-
+
- Requirements +
- Uploading the MXP Core +
- New installation +
- Advanced Installation +
- Upgrading the MXP Core +
- Confirmation +
- Copyright and Disclaimer +
+ +
diff --git a/admin/admin_gd_info.php b/admin/admin_gd_info.php
new file mode 100644
index 00000000..e19a245a
--- /dev/null
+++ b/admin/admin_gd_info.php
@@ -0,0 +1,112 @@
+set_filenames(array('body' => 'admin/admin_gd_info_body.' . TPL_EXT));
+
+if (function_exists('gd_info'))
+{
+ $gd_info_ary = gd_info();
+}
+
+$true = '' . $lang['GD_True'] . '';
+$false = '' . $lang['GD_False'] . '';
+
+if (count($gd_info_ary) == 0)
+{
+ print_r('v souboryu nic neni');
+}
+else
+{
+ $counter = 0;
+ //print_r($gd_info_ary);
+ foreach($gd_info_ary as $gd_key => $gd_value)
+ {
+ if (is_array($gd_value))
+ {
+ /*Convert the array to a string */
+ $gd_value = print_r($gd_value, true);
+ }
+
+ if (ctype_digit(strval($gd_value)) || empty($gd_value))
+ {
+ $gd_value = !empty($gd_value) ? $true : $false;
+ }
+
+ $gd_info_ary[$gd_key] = $gd_value;
+ }
+ $template->assign_vars(array( //#
+ 'VERSION' => $gd_info_ary['GD Version'],
+ 'FREETYPE_SUPPORT' => $gd_info_ary['FreeType Support'],
+ 'FREETYPE_LINKAGE' => $gd_info_ary['FreeType Linkage'],
+ 'T1LIB_SUPPORT' => $gd_info_ary['T1Lib Support'],
+ 'GIF_READ_SUPPORT' => $gd_info_ary['GIF Read Support'],
+ 'GIF_CREATE_SUPPORT' => $gd_info_ary['GIF Create Support'],
+ 'JPG_SUPPORT' => $gd_info_ary['JPEG Support'],
+ 'PNG_SUPPORT' => $gd_info_ary['PNG Support'],
+ 'WBMP_SUPPORT' => $gd_info_ary['WBMP Support'],
+ 'XBM_SUPPORT' => $gd_info_ary['XBM Support'],
+ 'WEBP_SUPPORT' => $gd_info_ary['WebP Support'],
+ 'JIS_MAPPED_SUPPORT' => $gd_info_ary['JIS-mapped Japanese Font Support'],
+ )
+ );
+ $counter++;
+}
+
+$template->assign_vars(array(
+ 'L_TITLE' => $lang['GD_Title'],
+ 'L_DESCRIPTION' => $lang['GD_Description'],
+ 'L_VERSION' => $lang['GD_VERSION'],
+ 'L_FREETYPE_SUPPORT' => $lang['GD_Freetype_Support'],
+ 'L_FREETYPE_LINKAGE' => $lang['GD_Freetype_Linkage'],
+ 'L_T1LIB_SUPPORT' => $lang['GD_T1lib_Support'],
+ 'L_GIF_READ_SUPPORT' => $lang['GD_Gif_Read_Support'],
+ 'L_GIF_CREATE_SUPPORT' => $lang['GD_Gif_Create_Support'],
+ 'L_JPG_SUPPORT' => $lang['GD_Jpg_Support'],
+ 'L_PNG_SUPPORT' => $lang['GD_Png_Support'],
+ 'L_WBMP_SUPPORT' => $lang['GD_Wbmp_Support'],
+ 'L_XBM_SUPPORT' => $lang['GD_XBM_Support'],
+ 'L_WEBP_SUPPORT' => $lang['GD_WebP_Support'],
+ 'L_JIS_MAPPED_SUPPORT' => $lang['GD_Jis_Mapped_Support'],
+
+ )
+);
+$template->pparse('body');
+
+//
+// Send page footer.
+//
+include_once('./page_footer_admin.' . PHP_EXT);
+?>
\ No newline at end of file
diff --git a/admin/admin_mx_page_cp.php b/admin/admin_mx_page_cp.php
index 22b31064..6f5c0bed 100644
--- a/admin/admin_mx_page_cp.php
+++ b/admin/admin_mx_page_cp.php
@@ -574,7 +574,8 @@
$page_header = !$new_page ? $page_rows[$page_count]['page_header'] : 'overall_header_navigation.html';
$page_footer = !$new_page ? $page_rows[$page_count]['page_footer'] : 'overall_footer.html';
$page_main_layout = !$new_page ? $page_rows[$page_count]['page_main_layout'] : 'mx_main_layout.html';
- $navigation_block_list = get_list_formatted('block_list', $page_main_layout, 'navigation_block', 'mx_menu_nav.' . $phpEx);
+ //$navigation_block_list = get_list_formatted('block_list', $page_main_layout, 'navigation_block', 'mx_menu_nav.' . $phpEx);
+ $navigation_block_list = get_list_formatted('block_list', $portal_config['navigation_block'], 'navigation_block', 'mx_menu_nav.' . $phpEx, false, 'mx_site_nav.' . $phpEx);
$default_style = !$new_page ? $page_rows[$page_count]['default_style'] : '_core';
$style_select = mx_style_select($default_style, 'mx_default_style', 'templates', true);
diff --git a/admin/admin_mx_portal.php b/admin/admin_mx_portal.php
index 5bf59136..5c1425ad 100644
--- a/admin/admin_mx_portal.php
+++ b/admin/admin_mx_portal.php
@@ -93,15 +93,30 @@
$new['smtp_username'] = $mx_request_vars->post('smtp_username', MX_TYPE_NO_TAGS, '0');
$new['smtp_password'] = $mx_request_vars->post('smtp_password', MX_TYPE_NO_TAGS, '0');
-
- $sql = "UPDATE " . PORTAL_TABLE . " SET " . $db->sql_build_array('UPDATE', $new);
+ $sql = "UPDATE " . PORTAL_TABLE . " SET " . $db->sql_build_array('UPDATE', utf8_normalize_nfc($new));
+
if( !($db->sql_query($sql)) )
{
mx_message_die(GENERAL_ERROR, "Failed to update portal configuration ", "", __LINE__, __FILE__, $sql);
}
-
+ //print_r("Portal configuration update " . "
" . $sql);
$message = update_portal_backend($new['portal_backend']) ? "The CMS configuration file was upgraded ...
" : update_portal_backend($new['portal_backend']);
+ //
+ // Update MX-Publisher page/block cache
+ //
+ $mx_cache->trash(); // Empty cache folder
+ $mx_cache->update(); // Regenerate all page_ and block_ files
+
+ //
+ // Update config/custom cache
+ //
+ $mx_cache->tidy(); // Not really needed
+ $mx_cache->destroy('phpbb_config'); // Not really needed
+ $mx_cache->destroy('mxbb_config'); // Not really needed
+ $mx_cache->unload(); // Regenerate data_global.php
+
+ $message .= $lang['Cache_generate'] . "
";
$mx_cache->put('mxbb_config', $new);
$message .= $lang['Portal_Config_updated'] . "
" . sprintf($lang['Click_return_portal_config'], "", "") . "
" . sprintf($lang['Click_return_admin_index'], "", "");
@@ -111,19 +126,69 @@
$template->set_filenames(array( 'admin_portal' => 'admin/admin_mx_portal.'.$tplEx) );
+$top_phpbb_links_yes = ( $portal_config['top_phpbb_links'] == 1 ) ? 'checked="checked"' : '';
+$top_phpbb_links_no = ( $portal_config['top_phpbb_links'] == 0 ) ? 'checked="checked"' : '';
+
+$mx_use_cache_yes = ( $portal_config['mx_use_cache'] == 1 ) ? 'checked="checked"' : '';
+$mx_use_cache_no = ( $portal_config['mx_use_cache'] == 0 ) ? 'checked="checked"' : '';
+
+$mx_mod_rewrite_yes = ( $portal_config['mod_rewrite'] == 1 ) ? 'checked="checked"' : '';
+$mx_mod_rewrite_no = ( $portal_config['mod_rewrite'] == 0 ) ? 'checked="checked"' : '';
+
+$mx_portal_status_yes = ( $portal_config['portal_status'] == 1 ) ? 'checked="checked"' : '';
+$mx_portal_status_no = ( $portal_config['portal_status'] == 0 ) ? 'checked="checked"' : '';
+
+$disabled_message = $portal_config['disabled_message'];
+
+$phpbb_rel_path = substr( "$phpbb_root_path", 3 );
+
$navigation_block_list = get_list_formatted('block_list', $portal_config['navigation_block'], 'navigation_block', 'mx_menu_nav.' . $phpEx, false, 'mx_site_nav.' . $phpEx);
-$portal_config['default_lang'] = $portal_config['default_lang'] == -1 ? $board_config['default_lang'] : $portal_config['default_lang'];
+$portal_version = $portal_config['portal_version'];
+$phpbb_version = isset($board_config['version']) ? '2' . $board_config['version'] : '0.0.0';
+
+$script_path = isset($portal_config['script_path']) ? $portal_config['script_path'] : $board_config['script_path'];
+$server_name = isset($portal_config['server_name']) ? $portal_config['server_name'] : $board_config['server_name'];
+
+$phpbb_script_path = $board_config['script_path'];
+$phpbb_server_name = $board_config['server_name'];
+
+
+$portal_config['default_lang'] = ($portal_config['default_lang'] == -1) ? $board_config['default_lang'] : $portal_config['default_lang'];
+
+// Default to phpBB default
$portal_config['default_admin_style'] = $portal_config['default_admin_style'] == -1 ? $board_config['default_style'] : $portal_config['default_admin_style'];
$portal_config['default_style'] = $portal_config['default_style'] == -1 ? $board_config['default_style'] : $portal_config['default_style'];
$portal_config['override_user_style'] = $portal_config['override_user_style'] == -1 ? $board_config['override_user_style'] : $portal_config['override_user_style'];
-$portal_backend_select = get_list_static('portal_backend', array('internal' => 'Internal', 'phpbb2' => 'phpBB2', 'phpbb3' => 'phpBB3', 'olympus' => 'Olympus', 'ascraeus' => 'Ascraeus', 'smf2' => 'SMF2', 'mybb' => 'myBB'), $portal_config['portal_backend']);
+$portal_backend_select = get_list_static('portal_backend',
+ array('internal' => 'Internal',
+ 'smf2' => 'SMF2',
+ 'mybb' => 'myBB',
+ 'phpbb2' => 'phpBB2',
+ 'phpbb3' => 'phpBB3',
+ 'olympus' => 'Olympus',
+ 'ascraeus' => 'Ascraeus',
+ 'rhea' => 'Rhea',
+ 'proteus' => 'Proteus',
+ 'phpbb4' => 'phpBB4'
+ ),
+ $portal_config['portal_backend']);
$style_select = mx_style_select($portal_config['default_style'], 'mx_default_style');
$style_admin_select = mx_style_select($portal_config['default_admin_style'], 'mx_default_admin_style');
+if ( isset($mx_user->data['user_timezone']) )
+{
+ $portal_config['board_timezone'] = $board_config['board_timezone'] = $mx_user->data['user_timezone'];
+}
+else
+{
+ $portal_config['board_timezone'] = $board_config['board_timezone'];
+}
+
$lang_select = mx_language_select($portal_config['default_lang'], 'default_lang', "language");
+
$timezone_select = mx_tz_select($portal_config['board_timezone'], 'board_timezone');
$current_phpbb_version = $mx_backend->get_phpbb_version(); // Empty if mxp is used standalone
@@ -164,37 +229,67 @@
"L_PORTAL_DESC" => $lang['Portal_Desc'], // Will override phpBB 'site_desc'
"PORTAL_DESC" => str_replace('"', '"', $portal_config['portal_desc']),
- "L_PORTAL_STATUS" => $lang['Portal_status'], // Will override phpBB 'board_disable'
- "L_PORTAL_STATUS_EXPLAIN" => $lang['Portal_status_explain'],
- "S_PORTAL_STATUS_YES" => ( $portal_config['portal_status'] == 1 ) ? 'checked="checked"' : '',
- "S_PORTAL_STATUS_NO" => ( $portal_config['portal_status'] == 0 ) ? 'checked="checked"' : '',
+ //"L_PORTAL_STATUS" => $lang['Portal_status'], // Will override phpBB 'board_disable'
+ //"L_PORTAL_STATUS_EXPLAIN" => $lang['Portal_status_explain'],
+ //"S_PORTAL_STATUS_YES" => ( $portal_config['portal_status'] == 1 ) ? 'checked="checked"' : '',
+ //"S_PORTAL_STATUS_NO" => ( $portal_config['portal_status'] == 0 ) ? 'checked="checked"' : '',
- "L_DISABLED_MESSAGE" => $lang['Disabled_message'], // Will override phpBB3 'board_disable_msg'
- "DISABLED_MESSAGE" => $portal_config['disabled_message'],
+ //"L_DISABLED_MESSAGE" => $lang['Disabled_message'], // Will override phpBB3 'board_disable_msg'
+ //"DISABLED_MESSAGE" => $portal_config['disabled_message'],
"L_SERVER_NAME" => $lang['Server_name'],
"L_SERVER_NAME_EXPLAIN" => $lang['Server_name_explain'],
- "SERVER_NAME" => $portal_config['server_name'],
+ "SERVER_NAME" => $server_name,
"L_SERVER_PORT" => $lang['Server_port'],
"L_SERVER_PORT_EXPLAIN" => $lang['Server_port_explain'],
- "SCRIPT_PATH" => $portal_config['script_path'],
+ "SCRIPT_PATH" => $script_path,
"L_SCRIPT_PATH" => $lang['Script_path'],
"L_SCRIPT_PATH_EXPLAIN" => $lang['Script_path_explain'],
"SERVER_PORT" => $portal_config['server_port'],
- "L_DATE_FORMAT" => $lang['Date_format'],
+ "L_DATE_FORMAT" => 'MXP' . $lang['Date_format'],
"L_DATE_FORMAT_EXPLAIN" => $lang['Date_format_explain'],
"DEFAULT_DATEFORMAT" => $portal_config['default_dateformat'],
- "L_SYSTEM_TIMEZONE" => $lang['System_timezone'],
+ "L_SYSTEM_TIMEZONE" => 'MXP ' . $lang['System_timezone'],
"TIMEZONE_SELECT" => $timezone_select, // board_timezone
- "L_ENABLE_GZIP" => $lang['Enable_gzip'],
+ "L_ENABLE_GZIP" => 'MXP ' . $lang['Enable_gzip'],
"GZIP_YES" => ( $portal_config['gzip_compress'] ) ? "checked=\"checked\"" : "",
"GZIP_NO" => ( !$portal_config['gzip_compress'] ) ? "checked=\"checked\"" : "",
+ "PORTAL_PHPBB_URL" => $portal_config['portal_phpbb_url'],
+ "OVERALL_HEADER" => $portal_config['overall_header'],
+
+ "OVERALL_FOOTER" => $portal_config['overall_footer'],
+ "MAIN_LAYOUT" => $portal_config['main_layout'],
+ "NAVIGATION_BLOCK" => $navigation_block_list,
+
+ //"L_PHPBB_RELATIVE_PATH" => $lang['Phpbb_path'],
+ //"L_PHPBB_RELATIVE_PATH_EXPLAIN" => $lang['Phpbb_path_explain'],
+ //"PHPBB_RELATIVE_PATH" => $phpbb_rel_path,
+
+ //"L_PORTAL_VERSION" => $lang['Portal_version'],
+ //"PORTAL_VERSION" => $portal_version,
+
+ "L_PHPBB_INFO" => $lang['PHPBB_info'],
+
+ //"L_PHPBB_SERVER_NAME" => $lang['PHPBB_server_name'],
+ //"PHPBB_SERVER_NAME" => $phpbb_server_name,
+
+ //"L_PHPBB_SCRIPT_PATH" => $lang['PHPBB_script_path'],
+ //"PHPBB_SCRIPT_PATH" => $phpbb_script_path,
+
+ //"L_PHPBB_VERSION" => $lang['PHPBB_version'],
+ //"PHPBB_VERSION" => $phpbb_version,
+
+ "L_TOP_PHPBB_LINKS" => $lang['Top_phpbb_links'] . "
" . $lang['Top_phpbb_links_explain'],
+ "S_TOP_PHPBB_LINKS_YES" => $top_phpbb_links_yes,
+ "S_TOP_PHPBB_LINKS_NO" => $top_phpbb_links_no,
+ "TOP_PHPBB_LINKS" => $portal_config['top_phpbb_links'],
+
"L_MX_USE_CACHE" => $lang['Mx_use_cache'],
"L_MX_USE_CACHE_EXPLAIN" => $lang['Mx_use_cache_explain'],
"S_MX_USE_CACHE_YES" => ( $portal_config['mx_use_cache'] == 1 ) ? 'checked="checked"' : '',
@@ -260,20 +355,31 @@
//
// User & Styling
//
+ "L_DEFAULT_LANG" => $lang['Default_language'] . ' (' . $mx_user->lang_name . '/' . $portal_config['default_lang'] . ') ',
"L_DEFAULT_LANGUAGE" => $lang['Default_language'],
"LANG_SELECT" => $lang_select,
- "L_DEFAULT_STYLE" => $lang['Default_style'],
- "STYLE_SELECT" => $style_select,
-
- "L_DEFAULT_ADMIN_STYLE" => $lang['Default_admin_style'],
- "ADMIN_STYLE_SELECT" => $style_admin_select,
+ "L_DEFAULT_STYLE" => $lang['Default_style'] . ' (' . $portal_config['default_style'] . ') ',
+ "L_DEFAULT_ADMIN_STYLE" => $lang['Default_admin_style'] . ' (' . $portal_config['default_admin_style'] . ') ',
+
"L_OVERRIDE_STYLE" => $lang['Override_style'],
"L_OVERRIDE_STYLE_EXPLAIN" => $lang['Override_style_explain'],
+
+ "STYLE_SELECT" => $style_select,
+ "ADMIN_STYLE_SELECT" => $style_admin_select,
+
"OVERRIDE_STYLE_YES" => ( $portal_config['override_user_style'] ) ? "checked=\"checked\"" : "",
"OVERRIDE_STYLE_NO" => ( !$portal_config['override_user_style'] ) ? "checked=\"checked\"" : "",
+ "L_MX_MOD_REWRITE" => $lang['Mx_mod_rewrite'],
+ "L_MX_MOD_REWRITE_EXPLAIN" => $lang['Mx_mod_rewrite_explain'],
+ "S_MX_MOD_REWRITE_YES" => $mx_mod_rewrite_yes,
+ "S_MX_MOD_REWRITE_NO" => $mx_mod_rewrite_no,
+ "MX_MOD_REWRITE" => $portal_config['mod_rewrite'],
+
+
+
"L_OVERALL_HEADER" => $lang['Portal_Overall_header'] . "
" . $lang['Portal_Overall_header_explain'],
"OVERALL_HEADER" => $portal_config['overall_header'],
@@ -347,6 +453,14 @@
"L_PHPBB_RELATIVE_PATH_EXPLAIN" => $lang['Phpbb_path_explain'],
"PHPBB_RELATIVE_PATH" => substr( "$phpbb_root_path", 3 ),
+ "L_PORTAL_STATUS" => $lang['Portal_status'],
+ "L_PORTAL_STATUS_EXPLAIN" => $lang['Portal_status_explain'],
+ "S_PORTAL_STATUS_YES" => $mx_portal_status_yes,
+ "S_PORTAL_STATUS_NO" => $mx_portal_status_no,
+
+ "L_DISABLED_MESSAGE" => $lang['Disabled_message'],
+ "DISABLED_MESSAGE" => $disabled_message,
+
"L_PHPBB_SERVER_NAME" => $lang['PHPBB_server_name'],
"PHPBB_SERVER_NAME" => $board_config['server_name'],
diff --git a/admin/admin_mx_styles.php b/admin/admin_mx_styles.php
index c8092bf6..255414aa 100644
--- a/admin/admin_mx_styles.php
+++ b/admin/admin_mx_styles.php
@@ -96,9 +96,9 @@
{
while( $sub_dir = @readdir($dir) )
{
- if( !is_file(phpBB2::phpbb_realpath($mx_root_path . 'templates/' .$sub_dir)) && !is_link(phpBB2::phpbb_realpath($mx_root_path . 'templates/' .$sub_dir)) && $sub_dir != "." && $sub_dir != ".." && $sub_dir != "CVS" )
+ if( !is_file($phpBB2->phpbb_realpath($mx_root_path . 'templates/' .$sub_dir)) && !is_link($phpBB2->phpbb_realpath($mx_root_path . 'templates/' .$sub_dir)) && $sub_dir != "." && $sub_dir != ".." && $sub_dir != "CVS" )
{
- if( @file_exists(@phpBB2::phpbb_realpath($mx_root_path. "templates/" . $sub_dir . "/$sub_dir.cfg")) )
+ if( @file_exists($phpBB2->phpbb_realpath($mx_root_path. "templates/" . $sub_dir . "/$sub_dir.cfg")) )
{
@include($mx_root_path. "templates/" . $sub_dir . "/$sub_dir.cfg");
@@ -132,7 +132,7 @@
"L_STYLES_TITLE" => $lang['Styles_admin'],
"L_STYLES_ADD_TEXT" => $lang['Styles_addnew_explain'],
"L_STYLE" => $lang['Style'],
- //"L_TEMPLATE" => $lang['Template'],
+ "L_TEMPLATE" => $lang['Template'],
"L_INSTALL" => $lang['Install'],
"L_ACTION" => $lang['Action'])
);
@@ -146,7 +146,7 @@
"ROW_CLASS" => $row_class,
"ROW_COLOR" => "#" . $row_color,
"STYLE_NAME" => $installable_themes[$i]['style_name'],
- //"TEMPLATE_NAME" => $installable_themes[$i]['template_name'],
+ "TEMPLATE_NAME" => $installable_themes[$i]['template_name'],
"U_STYLES_INSTALL" => mx_append_sid("admin_mx_styles.$phpEx?mode=addnew&style=" . urlencode($installable_themes[$i]['style_name']) . "&install_to=" . urlencode($installable_themes[$i]['template_name'])))
);
@@ -204,13 +204,15 @@
{
mx_message_die(GENERAL_ERROR, "Could not remove style data!", "", __LINE__, __FILE__, $sql);
}
-
- $sql = "UPDATE " . USERS_TABLE . "
- SET user_style = " . $board_config['default_style'] . "
- WHERE user_style = $style_id";
- if(!$result = $db->sql_query($sql, END_TRANSACTION))
+ if (PORTAL_BACKEND !== 'internal')
{
- mx_message_die(GENERAL_ERROR, "Could not update user style information", "", __LINE__, __FILE__, $sql);
+ $sql = "UPDATE " . USERS_TABLE . "
+ SET user_style = " . $board_config['default_style'] . "
+ WHERE user_style = $style_id";
+ if (!$result = $db->sql_query($sql, END_TRANSACTION))
+ {
+ mx_message_die(GENERAL_ERROR, "Could not update user style information", "", __LINE__, __FILE__, $sql);
+ }
}
$message = $lang['Style_removed'] . "
" . sprintf($lang['Click_return_styleadmin'], "", "") . "
" . sprintf($lang['Click_return_admin_index'], "", "");
diff --git a/admin/index.php b/admin/index.php
index 39143797..7b58d38b 100644
--- a/admin/index.php
+++ b/admin/index.php
@@ -373,19 +373,19 @@ function read_admin($dir_module)
case PAGE_INDEX:
$location = $lang['Forum_index'];
$location_url = "index.$phpEx?pane=right";
- break;
+ break;
case PAGE_POSTING:
$location = $lang['Posting_message'];
$location_url = "index.$phpEx?pane=right";
- break;
+ break;
case PAGE_LOGIN:
$location = $lang['Logging_on'];
$location_url = "index.$phpEx?pane=right";
- break;
+ break;
case PAGE_SEARCH:
$location = $lang['Searching_forums'];
$location_url = "index.$phpEx?pane=right";
- break;
+ break;
default:
$mx_viewonline_info = mx_get_viewonline_info($onlinerow_reg[$i]['user_session_page']);
if( $mx_viewonline_info !== false )
@@ -414,8 +414,8 @@ function read_admin($dir_module)
"ROW_COLOR" => "#" . $row_color,
"ROW_CLASS" => $row_class,
"USERNAME" => $username,
- "STARTED" => phpBB2::create_date($board_config['default_dateformat'], $onlinerow_reg[$i]['session_start'], $board_config['board_timezone']),
- "LASTUPDATE" => phpBB2::create_date($board_config['default_dateformat'], $onlinerow_reg[$i]['user_session_time'], $board_config['board_timezone']),
+ "STARTED" => $phpBB2->create_date($board_config['default_dateformat'], $onlinerow_reg[$i]['session_start'], $board_config['board_timezone']),
+ "LASTUPDATE" => $phpBB2->create_date($board_config['default_dateformat'], $onlinerow_reg[$i]['user_session_time'], $board_config['board_timezone']),
"FORUM_LOCATION" => $location,
"IP_ADDRESS" => $reg_ip,
@@ -452,19 +452,19 @@ function read_admin($dir_module)
case PAGE_INDEX:
$location = $lang['Forum_index'];
$location_url = "index.$phpEx?pane=right";
- break;
+ break;
case PAGE_POSTING:
$location = $lang['Posting_message'];
$location_url = "index.$phpEx?pane=right";
- break;
+ break;
case PAGE_LOGIN:
$location = $lang['Logging_on'];
$location_url = "index.$phpEx?pane=right";
- break;
+ break;
case PAGE_SEARCH:
$location = $lang['Searching_forums'];
$location_url = "index.$phpEx?pane=right";
- break;
+ break;
default:
$mx_viewonline_info = mx_get_viewonline_info($onlinerow_guest[$i]['session_page']);
if( $mx_viewonline_info !== false )
@@ -485,8 +485,8 @@ function read_admin($dir_module)
"ROW_COLOR" => "#" . $row_color,
"ROW_CLASS" => $row_class,
"USERNAME" => $lang['Guest'],
- "STARTED" => phpBB2::create_date($board_config['default_dateformat'], $onlinerow_guest[$i]['session_start'], $board_config['board_timezone']),
- "LASTUPDATE" => phpBB2::create_date($board_config['default_dateformat'], $onlinerow_guest[$i]['session_time'], $board_config['board_timezone']),
+ "STARTED" => $phpBB2->create_date($board_config['default_dateformat'], $onlinerow_guest[$i]['session_start'], $board_config['board_timezone']),
+ "LASTUPDATE" => $phpBB2->create_date($board_config['default_dateformat'], $onlinerow_guest[$i]['session_time'], $board_config['board_timezone']),
"FORUM_LOCATION" => $location,
"IP_ADDRESS" => $guest_ip,
@@ -506,8 +506,8 @@ function read_admin($dir_module)
$phpbb_version_info = $mx_backend->phpbb_version_check();
/* Begin MX-Publisher version check code block */
- $current_MXP_version = explode('.', $portal_config['portal_version']);
- $minor_mx_revision = (int) $current_MXP_version[2];
+ $current_mxp_version = explode('.', $portal_config['portal_version']);
+ $minor_mx_revision = (int) $current_mxp_version[2];
$errno = 0;
$errstr = $mx_version_info = '';
@@ -599,7 +599,7 @@ function read_admin($dir_module)
);
$template->assign_vars(array(
- 'ADMIN_TITLE' => $lang['Mx-Publisher_adminCP'],
+ 'L_ADMIN_TITLE' => isset($lang['mxBB_adminCP']) ? $lang['mxBB_adminCP'] : $lang['Mx-Publisher_adminCP'],
"S_FRAME_NAV" => mx_append_sid("index.$phpEx?pane=left"),
"S_FRAME_MAIN" => mx_append_sid("index.$phpEx?pane=right"))
);
diff --git a/admin/index_iframes.php b/admin/index_iframes.php
new file mode 100644
index 00000000..c565225c
--- /dev/null
+++ b/admin/index_iframes.php
@@ -0,0 +1,607 @@
+get('pane', MX_TYPE_NO_TAGS) == 'left')
+{
+ //require($mx_root_path.'admin/page_header_admin.'.$phpEx);
+
+ $template->set_filenames(array(
+ 'body' => 'admin/index_navigate.'.$tplEx)
+ );
+
+ $admincp_nav_icon_url = PORTAL_URL . $images['mx_graphics']['admin_icons'];
+
+ $template->assign_vars(array(
+ 'U_PHPBB_ROOT_PATH' => PHPBB_URL,
+ 'TEMPLATE_ROOT_PATH' => TEMPLATE_ROOT_PATH,
+ "U_PORTAL_INDEX" => mx_append_sid(PORTAL_URL . "index.$phpEx"),
+ "L_PORTAL_INDEX" => $lang['Portal_index'],
+ "L_PREVIEW_PORTAL" => $lang['Preview_portal'],
+
+ "LOGO" => $images['mx_logo'],
+
+ "U_FORUM_INDEX" => mx_append_sid(PHPBB_URL . "index.$phpEx"),
+ "U_ADMIN_INDEX" => mx_append_sid("index.$phpEx?pane=right"),
+ //+MOD: DHTML Menu for ACP
+ 'COOKIE_NAME' => $board_config['cookie_name'],
+ 'COOKIE_PATH' => $board_config['cookie_path'],
+ 'COOKIE_DOMAIN' => $board_config['cookie_domain'],
+ 'COOKIE_SECURE' => $board_config['cookie_secure'],
+ 'IMG_URL_CONTRACT' => $admincp_nav_icon_url . '/contract.gif',
+ 'IMG_URL_EXPAND' => $admincp_nav_icon_url . '/expand.gif',
+ //-MOD: DHTML Menu for ACP
+ "L_FORUM_INDEX" => $lang['Main_index'],
+ "L_ADMIN_INDEX" => $lang['Admin_Index'],
+ ));
+
+ //
+ // Read Portal configuration
+ //
+ // MX Addon ------------------------------------
+ $module_portal = read_admin('.');
+ $template->assign_block_vars('module_portal', array(
+ 'L_MX_PORTAL' => $lang['MX_Portal']
+ ));
+ // END ------------------------------------------
+
+ ksort($module_portal);
+
+ //+MOD: DHTML Menu for ACP
+ $menu_cat_id = 0;
+ //-MOD: DHTML Menu for ACP
+
+ while( list($cat, $action_array) = each($module_portal) )
+ {
+ $cat = ( !empty($lang[$cat]) ) ? $lang[$cat] : preg_replace("/_/", " ", $cat);
+
+ $template->assign_block_vars('module_portal.catrow', array(
+ //+MOD: DHTML Menu for ACP
+ 'MENU_CAT_ID' => $menu_cat_id,
+ 'MENU_CAT_ROWS' => count($action_array),
+ //-MOD: DHTML Menu for ACP
+ 'ADMIN_CATEGORY' => $cat)
+ );
+
+ ksort($action_array);
+
+ $row_count = 0;
+ while( list($action, $file) = each($action_array) )
+ {
+ $row_color = ( !($row_count%2) ) ? $theme['td_color1'] : $theme['td_color2'];
+ $row_class = ( !($row_count%2) ) ? $theme['td_class1'] : $theme['td_class2'];
+
+ $action = ( !empty($lang[$action]) ) ? $lang[$action] : preg_replace("/_/", " ", $action);
+
+ $template->assign_block_vars('module_portal.catrow.modulerow', array(
+ "ROW_COLOR" => "#" . $row_color,
+ "ROW_CLASS" => $row_class,
+ //+MOD: DHTML Menu for ACP
+ 'ROW_COUNT' => $row_count,
+ //-MOD: DHTML Menu for ACP
+ "ADMIN_MODULE" => $action,
+ "U_ADMIN_MODULE" => mx_append_sid(PORTAL_URL . $file . ( ( strpos($file, '?') !== false ) ? '&sid=' : '?sid=' ) . $userdata['session_id'])
+ ));
+ $row_count++;
+ }
+ //+MOD: DHTML Menu for ACP
+ $menu_cat_id++;
+ //-MOD: DHTML Menu for ACP
+ }
+
+ //
+ // Include PHPBB Administration
+ // -------------------------------------------------------------------------------
+ $mx_backend->load_phpbb_acp_menu();
+
+ //
+ // Read Portal Module Configuration
+ //
+ $sql = "SELECT *
+ FROM " . MODULE_TABLE . "
+ WHERE module_include_admin = 1
+ ORDER BY module_name";
+
+ if( !($q_modules = $db->sql_query($sql)) )
+ {
+ mx_message_die(GENERAL_ERROR, "Could not query modules information", '', __LINE__, __FILE__, $sql);
+ }
+
+ if( $total_modules = $db->sql_numrows($q_modules) )
+ {
+ $module_rows = $db->sql_fetchrowset($q_modules);
+ }
+ $db->sql_freeresult($result);
+
+ $module_mx = array();
+ for( $module_cnt = 0; $module_cnt < $total_modules; $module_cnt++ )
+ {
+ $module_path_admin = $mx_root_path . $module_rows[$module_cnt]['module_path'] . "admin/";
+ $module_path_root = $mx_root_path . $module_rows[$module_cnt]['module_path'];
+
+ // **********************************************************************
+ // Read language definition
+ // **********************************************************************
+ if ( file_exists( $module_path_root . 'language/lang_' . $board_config['default_lang'] . '/lang_admin.' . $phpEx ) )
+ {
+ include( $module_path_root . 'language/lang_' . $board_config['default_lang'] . '/lang_admin.' . $phpEx );
+ }
+ else if ( file_exists( $module_path_root . 'language/lang_english/lang_admin.' . $phpEx ) )
+ {
+ include( $module_path_root . 'language/lang_english/lang_admin.' . $phpEx );
+ }
+
+ $module_mx = array_merge_recursive($module_mx, read_admin($module_path_admin));
+ }
+ $template->assign_block_vars('module_mx', array(
+ 'L_MX_MODULES' => $lang['MX_Modules'])
+ );
+
+ ksort($module_mx);
+
+ //+MOD: DHTML Menu for ACP
+ $menu_cat_id = 0;
+ //-MOD: DHTML Menu for ACP
+
+ while( list($cat, $action_array) = each($module_mx) )
+ {
+ $cat = ( !empty($lang[$cat]) ) ? $lang[$cat] : preg_replace("/_/", " ", $cat);
+
+ $template->assign_block_vars('module_mx.catrow', array(
+ //+MOD: DHTML Menu for ACP
+ 'MENU_CAT_ID' => $menu_cat_id,
+ 'MENU_CAT_ROWS' => count($action_array),
+ //-MOD: DHTML Menu for ACP
+ 'ADMIN_CATEGORY' => $cat)
+ );
+
+ ksort($action_array);
+
+ $row_count = 0;
+ while( list($action, $file) = each($action_array) )
+ {
+ $row_color = ( !($row_count%2) ) ? $theme['td_color1'] : $theme['td_color2'];
+ $row_class = ( !($row_count%2) ) ? $theme['td_class1'] : $theme['td_class2'];
+
+ $action = ( !empty($lang[$action]) ) ? $lang[$action] : preg_replace("/_/", " ", $action);
+
+ $template->assign_block_vars('module_mx.catrow.modulerow', array(
+ "ROW_COLOR" => "#" . $row_color,
+ "ROW_CLASS" => $row_class,
+ //+MOD: DHTML Menu for ACP
+ 'ROW_COUNT' => $row_count,
+ //-MOD: DHTML Menu for ACP
+
+ "ADMIN_MODULE" => $action,
+ "U_ADMIN_MODULE" => mx_append_sid(PORTAL_URL . $file))
+ );
+ $row_count++;
+ }
+ //+MOD: DHTML Menu for ACP
+ $menu_cat_id++;
+ //-MOD: DHTML Menu for ACP
+ }
+ // -----------------------------------------------------------------------------------
+ // END MX ADDON
+ // -----------------------------------------------------------------------------------
+ $template->pparse('body');
+
+ include('./page_footer_admin.'.$phpEx);
+}
+elseif ($mx_request_vars->get('pane', MX_TYPE_NO_TAGS) == 'right')
+{
+ //require('./page_header_admin.'.$phpEx);
+
+ $template->set_filenames(array(
+ "body" => "admin/index_body.".$tplEx)
+ );
+
+ $template->assign_vars(array(
+ // MX Addon
+ 'U_PHPBB_ROOT_PATH' => PHPBB_URL,
+ 'TEMPLATE_ROOT_PATH' => TEMPLATE_ROOT_PATH,
+ // END
+ "L_WELCOME" => $lang['Welcome_mxBB'],
+ "L_ADMIN_INTRO" => $lang['Admin_intro_mxBB'],
+ "L_FORUM_STATS" => $lang['Forum_stats'],
+ "L_WHO_IS_ONLINE" => $lang['Who_is_Online'],
+ "L_USERNAME" => $lang['Username'],
+ "L_LOCATION" => $lang['Location'],
+ "L_LAST_UPDATE" => $lang['Last_updated'],
+ "L_IP_ADDRESS" => $lang['IP_Address'],
+ "L_STATISTIC" => $lang['Statistic'],
+ "L_VALUE" => $lang['Value'],
+ "L_NUMBER_POSTS" => $lang['Number_posts'],
+ "L_POSTS_PER_DAY" => $lang['Posts_per_day'],
+ "L_NUMBER_TOPICS" => $lang['Number_topics'],
+ "L_TOPICS_PER_DAY" => $lang['Topics_per_day'],
+ "L_NUMBER_USERS" => $lang['Number_users'],
+ "L_USERS_PER_DAY" => $lang['Users_per_day'],
+ "L_BOARD_STARTED" => $lang['Board_started'],
+ "L_AVATAR_DIR_SIZE" => $lang['Avatar_dir_size'],
+ "L_DB_SIZE" => $lang['Database_size'],
+ "L_FORUM_LOCATION" => $lang['Forum_Location'],
+ "L_STARTED" => $lang['Login'],
+ "L_GZIP_COMPRESSION" => $lang['Gzip_compression'])
+ );
+
+
+ $whois_url = "http://network-tools.com/default.asp?host=";
+ //$whois_url = mx_append_sid(PHPBB_URL . "adm/index.php?i=users&icat=13&mode=overview&action=whois&user_ip=");
+
+ $mx_backend->load_forum_stats();
+
+ //
+ // Get users online information.
+ //
+ $sql = $mx_backend->generate_session_online_sql();
+
+ if(!$result = $db->sql_query($sql))
+ {
+ mx_message_die(GENERAL_ERROR, "Couldn't obtain regd user/online information.", "", __LINE__, __FILE__, $sql);
+ }
+
+ $onlinerow_reg = $db->sql_fetchrowset($result);
+ $db->sql_freeresult($result);
+
+ $sql = $mx_backend->generate_session_online_sql(true);
+
+ if(!$result = $db->sql_query($sql))
+ {
+ mx_message_die(GENERAL_ERROR, "Couldn't obtain guest user/online information.", "", __LINE__, __FILE__, $sql);
+ }
+ $onlinerow_guest = $db->sql_fetchrowset($result);
+ $db->sql_freeresult($result);
+
+ $reg_userid_ary = array();
+
+ if( count($onlinerow_reg) )
+ {
+ $registered_users = 0;
+
+ for($i = 0; $i < count($onlinerow_reg); $i++)
+ {
+ if( !inarray($onlinerow_reg[$i]['user_id'], $reg_userid_ary) )
+ {
+ $reg_userid_ary[] = $onlinerow_reg[$i]['user_id'];
+
+ $username = $onlinerow_reg[$i]['username'];
+
+ if( $onlinerow_reg[$i]['user_allow_viewonline'] || $userdata['user_level'] == ADMIN )
+ {
+ $registered_users++;
+ $hidden = FALSE;
+ }
+ else
+ {
+ $hidden_users++;
+ $hidden = TRUE;
+ }
+
+ if( $onlinerow_reg[$i]['user_session_page'] < 1 )
+ {
+ switch($onlinerow_reg[$i]['user_session_page'])
+ {
+ case PAGE_INDEX:
+ $location = $lang['Forum_index'];
+ $location_url = "index.$phpEx?pane=right";
+ break;
+ case PAGE_POSTING:
+ $location = $lang['Posting_message'];
+ $location_url = "index.$phpEx?pane=right";
+ break;
+ case PAGE_LOGIN:
+ $location = $lang['Logging_on'];
+ $location_url = "index.$phpEx?pane=right";
+ break;
+ case PAGE_SEARCH:
+ $location = $lang['Searching_forums'];
+ $location_url = "index.$phpEx?pane=right";
+ break;
+ default:
+ $mx_viewonline_info = mx_get_viewonline_info($onlinerow_reg[$i]['user_session_page']);
+ if( $mx_viewonline_info !== false )
+ {
+ list($location, $location_url) = $mx_viewonline_info;
+ break;
+ }
+ }
+ }
+ else
+ {
+ $mx_viewonline_info = mx_get_viewonline_info($onlinerow_reg[$i]['user_session_page']);
+ if( $mx_viewonline_info !== false )
+ {
+ list($location, $location_url) = $mx_viewonline_info;
+ break;
+ }
+ }
+
+ $row_color = ( $registered_users % 2 ) ? $theme['td_color1'] : $theme['td_color2'];
+ $row_class = ( $registered_users % 2 ) ? $theme['td_class1'] : $theme['td_class2'];
+
+ $reg_ip = $mx_backend->decode_ip($onlinerow_reg[$i]['session_ip']);
+
+ $template->assign_block_vars("reg_user_row", array(
+ "ROW_COLOR" => "#" . $row_color,
+ "ROW_CLASS" => $row_class,
+ "USERNAME" => $username,
+ "STARTED" => phpBB2::create_date($board_config['default_dateformat'], $onlinerow_reg[$i]['session_start'], $board_config['board_timezone']),
+ "LASTUPDATE" => phpBB2::create_date($board_config['default_dateformat'], $onlinerow_reg[$i]['user_session_time'], $board_config['board_timezone']),
+ "FORUM_LOCATION" => $location,
+ "IP_ADDRESS" => $reg_ip,
+
+ "U_WHOIS_IP" => $whois_url . $reg_ip,
+ "U_USER_PROFILE" => mx_append_sid(PHPBB_URL . "admin_users.$phpEx?mode=edit&" . POST_USERS_URL . "=" . $onlinerow_reg[$i]['user_id']),
+ "U_FORUM_LOCATION" => mx_append_sid($location_url))
+ );
+ }
+ }
+ }
+ else
+ {
+ $template->assign_vars(array(
+ "L_NO_REGISTERED_USERS_BROWSING" => $lang['No_users_browsing'])
+ );
+ }
+
+ //
+ // Guest users
+ //
+ if( count($onlinerow_guest) )
+ {
+ $guest_users = 0;
+
+ for($i = 0; $i < count($onlinerow_guest); $i++)
+ {
+ $guest_userip_ary[] = $onlinerow_guest[$i]['session_ip'];
+ $guest_users++;
+
+ if( $onlinerow_guest[$i]['session_page'] < 1 )
+ {
+ switch( $onlinerow_guest[$i]['session_page'] )
+ {
+ case PAGE_INDEX:
+ $location = $lang['Forum_index'];
+ $location_url = "index.$phpEx?pane=right";
+ break;
+ case PAGE_POSTING:
+ $location = $lang['Posting_message'];
+ $location_url = "index.$phpEx?pane=right";
+ break;
+ case PAGE_LOGIN:
+ $location = $lang['Logging_on'];
+ $location_url = "index.$phpEx?pane=right";
+ break;
+ case PAGE_SEARCH:
+ $location = $lang['Searching_forums'];
+ $location_url = "index.$phpEx?pane=right";
+ break;
+ default:
+ $mx_viewonline_info = mx_get_viewonline_info($onlinerow_guest[$i]['session_page']);
+ if( $mx_viewonline_info !== false )
+ {
+ list($location, $location_url) = $mx_viewonline_info;
+ break;
+ }
+ }
+ }
+
+
+ $row_color = ( $guest_users % 2 ) ? $theme['td_color1'] : $theme['td_color2'];
+ $row_class = ( $guest_users % 2 ) ? $theme['td_class1'] : $theme['td_class2'];
+
+ $guest_ip = $mx_backend->decode_ip($onlinerow_guest[$i]['session_ip']);
+
+ $template->assign_block_vars("guest_user_row", array(
+ "ROW_COLOR" => "#" . $row_color,
+ "ROW_CLASS" => $row_class,
+ "USERNAME" => $lang['Guest'],
+ "STARTED" => phpBB2::create_date($board_config['default_dateformat'], $onlinerow_guest[$i]['session_start'], $board_config['board_timezone']),
+ "LASTUPDATE" => phpBB2::create_date($board_config['default_dateformat'], $onlinerow_guest[$i]['session_time'], $board_config['board_timezone']),
+ "FORUM_LOCATION" => $location,
+ "IP_ADDRESS" => $guest_ip,
+
+ "U_WHOIS_IP" => $whois_url . $guest_ip,
+ "U_FORUM_LOCATION" => mx_append_sid($location_url))
+ );
+ }
+ }
+ else
+ {
+ $template->assign_vars(array(
+ "L_NO_GUESTS_BROWSING" => $lang['No_users_browsing'])
+ );
+ }
+
+ /* Begin phpBB version check code block */
+ $phpbb_version_info = $mx_backend->phpbb_version_check();
+
+ /* Begin MX-Publisher version check code block */
+ $current_mxbb_version = explode('.', $portal_config['portal_version']);
+ $minor_mxbb_revision = (int) $current_mxbb_version[2];
+
+ $errno = 0;
+ $errstr = $mxbb_version_info = '';
+
+ if ($fsock = @fsockopen('www.mx-publisher.com', 80, $errno, $errstr))
+ {
+ @fputs($fsock, "GET /updatecheck/30x.txt HTTP/1.1\r\n");
+ @fputs($fsock, "HOST: www.mx-publisher.com\r\n");
+ @fputs($fsock, "Connection: close\r\n\r\n");
+
+ $get_info = false;
+ while (!@feof($fsock))
+ {
+ if ($get_info)
+ {
+ $mxbb_version_info .= @fread($fsock, 1024);
+ }
+ else
+ {
+ if (@fgets($fsock, 1024) == "\r\n")
+ {
+ $get_info = true;
+ }
+ }
+ }
+ @fclose($fsock);
+
+ $mxbb_version_info = explode("\n", $mxbb_version_info);
+ $latest_mxbb_head_revision = (int) $mxbb_version_info[0];
+ $latest_mxbb_minor_revision = (int) $mxbb_version_info[2];
+ $latest_mxbb_patch_revision = (int) $mxbb_version_info[3]; // For betas/RC
+
+ $latest_mxbb_version = (int) $mxbb_version_info[0] . '.' . (int) $mxbb_version_info[1] . '.' . (int) $mxbb_version_info[2];
+
+ if ($latest_mxbb_head_revision == 3 && $minor_mxbb_revision == $latest_mxbb_minor_revision)
+ {
+ $mxbb_version_info = '
' . $lang['mxBB_Version_up_to_date'] . '
'; + } + else + { + $mxbb_version_info = '' . $lang['mxBB_Version_outdated'];
+ $mxbb_version_info .= '
' . sprintf($lang['mxBB_Latest_version_info'], $latest_mxbb_version) . sprintf($lang['mxBB_Current_version_info'], $portal_config['portal_version']) . '
' . sprintf($lang['Connect_socket_error'], $errstr) . '
'; + } + else + { + $mxbb_version_info = '' . $lang['Socket_functions_disabled'] . '
'; + } + } + + $mxbb_version_info .= '' . $lang['mxBB_Mailing_list_subscribe_reminder'] . '
'; + + $template->assign_vars(array( + 'MXBB_VERSION_INFO' => $mxbb_version_info, + 'PHPBB_VERSION_INFO' => $phpbb_version_info, + 'L_VERSION_INFORMATION' => $lang['Version_information']) + ); + + $template->pparse("body"); + + include('./page_footer_admin.'.$phpEx); +} +else +{ + // + // Generate frameset + // + $template->set_filenames(array( + "body" => "admin/index_iframes.".$tplEx) + ); + $template->assign_vars(array( + "SITENAME" => $board_config['sitename'], + "SITE_DESCRIPTION" => $board_config['site_desc'], + "ADMIN_TITLE" => $lang['mxBB_adminCP'], + "U_PHPBB_ROOT_PATH" => PHPBB_URL, + "TEMPLATE_ROOT_PATH" => TEMPLATE_ROOT_PATH, + "S_FRAME_NAV" => mx_append_sid("index.$phpEx?pane=left"), + "S_FRAME_MAIN" => mx_append_sid("index.$phpEx?pane=right")) + ); + @header ("Expires: " . gmdate("D, d M Y H:i:s", time()) . " GMT"); + @header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); + + $template->pparse("body"); + + $db->sql_close(); + exit; +} +?> \ No newline at end of file diff --git a/admin/index_jon.php b/admin/index_jon.php index 76fe430e..29937ee8 100644 --- a/admin/index_jon.php +++ b/admin/index_jon.php @@ -128,7 +128,7 @@ class mx_acp */ function mx_acp() { - global $template, $db, $lang, $phpEx, $mx_root_path, $phpbb_root_path, $phpbb_auth, $mx_user; + global $mx_cache, $template, $db, $lang, $phpEx, $mx_root_path, $phpbb_root_path, $phpbb_auth, $mx_user; $this->_template_set_filenames(); $this->category = MAIN_CATEGORY; @@ -139,21 +139,21 @@ function mx_acp() // if ( PORTAL_BACKEND == 'phpbb2' ) { - mx_cache::load_file( 'functions', true ); - mx_cache::load_file( 'functions_selects', true ); - mx_cache::load_file( 'functions_validate', true ); + $mx_cache->load_file( 'functions', true ); + $mx_cache->load_file( 'functions_selects', true ); + $mx_cache->load_file( 'functions_validate', true ); } if ( PORTAL_BACKEND == 'phpbb3' ) { include_once( $mx_root_path . 'includes/sessions/phpbb3/auth.' . $phpEx ); - mx_cache::load_file( 'functions_admin', 'phpbb3' ); - mx_cache::load_file( 'acp/auth', 'phpbb3' ); - mx_cache::load_file( 'auth', 'phpbb3'); - mx_cache::load_file( 'functions', 'phpbb3' ); - mx_cache::load_file( 'functions', 'phpbb2' ); - mx_cache::load_file( 'functions_module', 'phpbb3' ); - mx_cache::load_file( 'message_parser' , 'phpbb3' ); + $mx_cache->load_file( 'functions_admin', 'phpbb3' ); + $mx_cache->load_file( 'acp/auth', 'phpbb3' ); + $mx_cache->load_file( 'auth', 'phpbb3'); + $mx_cache->load_file( 'functions', 'phpbb3' ); + $mx_cache->load_file( 'functions', 'phpbb2' ); + $mx_cache->load_file( 'functions_module', 'phpbb3' ); + $mx_cache->load_file( 'message_parser' , 'phpbb3' ); $phpbb_admin_path = ( defined( 'PHPBB_ADMIN_PATH' ) ) ? PHPBB_ADMIN_PATH : 'adm/'; @@ -287,7 +287,7 @@ function _read_menu_actions( $menu_array, $category = MAIN_CATEGORY ) function assign_menu() { - global $lang, $db, $template, $mx_user, $mx_root_path, $phpbb_root_path, $phpEx; + global $board_config, $lang, $db, $template, $mx_user, $mx_root_path, $phpbb_root_path, $phpEx; $allow_menu_sort = true; // # @@ -312,7 +312,7 @@ function assign_menu() { $module_rows = $db->sql_fetchrowset( $q_modules ); } - $db->sql_freeresult( $result ); + $db->sql_freeresult( $q_modules ); $menu_array = array(); for( $module_cnt = 0; $module_cnt < $total_modules; $module_cnt++ ) { @@ -343,7 +343,10 @@ function assign_menu() case 'phpbb2': $mnu_ary = read_admin( $phpbb_root_path . 'admin/' ); $menu_array = array(); - + + $lang['Group_rank_order'] = isset($lang['Group_rank_order']) ? $lang['Group_rank_order'] : $mx_user->lang('Group_rank_order'); + $lang['Resync_Post_counts'] = isset($lang['Resync_Post_counts']) ? $lang['Resync_Post_counts'] : $mx_user->lang('Resync_Post_counts'); + foreach( $mnu_ary as $key => $menu ) { $i = 0; @@ -439,12 +442,12 @@ function assign_menu() switch ( $this->category ) { case OLYMPUS_CATEGORY: - $menu_link_params = preg_replace( '#panel=[^&]*#', '&cat=' . $this->category . '&panel=' . $panel, $file_part[1] ); + $menu_link_params = preg_replace( '#panel=[^&]*#', '&cat=' . $this->category . '&panel=' . $panel, (isset($file_part[1]) ? $file_part[1] : '') ); break; case PHPBB2X_CATEGORY: case MODULE_CATEGORY: case MAIN_CATEGORY: - $menu_link_params = str_replace( '?', '', '&cat=' . $this->category . '&panel=' . $panel . '&' . $file_part[1] ); + $menu_link_params = str_replace( '?', '', '&cat=' . $this->category . '&panel=' . $panel . '&' . (isset($file_part[1]) ? $file_part[1] : '') ); break; } @@ -460,7 +463,10 @@ function assign_menu() { $menu_link = mx_append_sid( $menu_link ); } - + + $row_color = (!($row_count%2)) ? $mx_user->theme['td_color1'] : $mx_user->theme['td_color2']; + $row_class = (!($row_count%2)) ? $mx_user->theme['td_class1'] : $mx_user->theme['td_class2']; + $template->assign_block_vars('category.panel', array( "ROW_COLOR" => "#" . $row_color, "ROW_CLASS" => $row_class, // +MOD: DHTML Menu for ACP @@ -476,7 +482,7 @@ function assign_menu() $menu_cat_id++; // -MOD: DHTML Menufor ACP } - $this->menu_actions = array_merge(array( $this->action_script => $this->menu_actions[$this->action_script] ), $this->menu_actions); + $this->menu_actions = array_merge(array( $this->action_script => isset($this->menu_actions[$this->action_script]) ? $this->menu_actions[$this->action_script] : array()), $this->menu_actions); } function prepare_action_script() @@ -529,7 +535,7 @@ function prepare_action_script() ) ); // PHPBB2 FUNCTIONS REPLACE $functions_ary = array( // # - 'get_userdata', 'phpbb_clean_username', phpbb_realpath + 'get_userdata', 'phpbb_clean_username', 'phpbb_realpath' ); $preg_array = array_merge( $preg_array, array( // # '#(' . implode( '|', $functions_ary ) . ')\(#si' => '$phpBB2->\1(', @@ -705,7 +711,7 @@ function assign_content_acp( $acp_html ) function _template_assign_vars() { global $board_config, $userdata, $lang, $mx_user, $admincp_nav_icon_url; - global $theme, $images, $mx_starttime, $db, $phpEx, $template; + global $theme, $images, $mx_starttime, $db, $phpBB2, $phpEx, $template; $l_timezone = explode( '.', $board_config['board_timezone'] ); $l_timezone = ( count( $l_timezone ) > 1 && $l_timezone[count( $l_timezone )-1] != 0 ) ? $lang[sprintf( '%.1f', $board_config['board_timezone'] )] : $lang[number_format( $board_config['board_timezone'] )]; @@ -757,7 +763,7 @@ function _template_assign_vars() 'USERNAME' => $mx_user->data['username'], 'CATEGORY' => $this->category, - 'L_LOGGED_IN_AS' => $lang['Logged_in_as'], + 'L_LOGGED_IN_AS' => $mx_user->lang('Logged_in_as'), "L_PORTAL_INDEX" => $lang['Portal_index'], "L_PREVIEW_PORTAL" => $lang['Preview_portal'], @@ -780,7 +786,7 @@ function _template_assign_vars() 'S_TIMEZONE' => sprintf( $lang['All_times'], $l_timezone ), 'S_LOGIN_ACTION' => mx_append_sid( '../login.' . $phpEx ), 'S_JUMPBOX_ACTION' => mx_append_sid( '../viewforum.' . $phpEx ), - 'S_CURRENT_TIME' => sprintf($lang['Current_time'], phpBB2::create_date($board_config['default_dateformat'], time(), $board_config['board_timezone'])), + 'S_CURRENT_TIME' => sprintf($lang['Current_time'], $phpBB2->create_date($board_config['default_dateformat'], time(), $board_config['board_timezone'])), 'S_CONTENT_DIRECTION' => $lang['DIRECTION'], 'S_CONTENT_ENCODING' => $lang['ENCODING'], 'S_CONTENT_DIR_LEFT' => $lang['LEFT'], diff --git a/admin/index_ory.php b/admin/index_ory.php index 29c62fec..0b360a3a 100644 --- a/admin/index_ory.php +++ b/admin/index_ory.php @@ -128,7 +128,7 @@ class mx_acp */ function mx_acp() { - global $template, $db, $lang, $phpEx, $mx_root_path, $phpbb_root_path, $phpbb_auth, $mx_user; + global $mx_cache, $template, $db, $lang, $phpEx, $mx_root_path, $phpbb_root_path, $phpbb_auth, $mx_user; $this->_template_set_filenames(); $this->category = MAIN_CATEGORY; @@ -139,21 +139,21 @@ function mx_acp() // if ( PORTAL_BACKEND == 'phpbb2' ) { - mx_cache::load_file( 'functions', true ); - mx_cache::load_file( 'functions_selects', true ); - mx_cache::load_file( 'functions_validate', true ); + $mx_cache->load_file( 'functions', true ); + $mx_cache->load_file( 'functions_selects', true ); + $mx_cache->load_file( 'functions_validate', true ); } if ( PORTAL_BACKEND == 'phpbb3' ) { include_once( $mx_root_path . 'includes/sessions/phpbb3/auth.' . $phpEx ); - mx_cache::load_file( 'functions_admin', 'phpbb3' ); - mx_cache::load_file( 'acp/auth', 'phpbb3' ); - mx_cache::load_file( 'auth', 'phpbb3'); - mx_cache::load_file( 'functions', 'phpbb3' ); - mx_cache::load_file( 'functions', 'phpbb2' ); - mx_cache::load_file( 'functions_module', 'phpbb3' ); - mx_cache::load_file( 'message_parser' , 'phpbb3' ); + $mx_cache->load_file( 'functions_admin', 'phpbb3' ); + $mx_cache->load_file( 'acp/auth', 'phpbb3' ); + $mx_cache->load_file( 'auth', 'phpbb3'); + $mx_cache->load_file( 'functions', 'phpbb3' ); + $mx_cache->load_file( 'functions', 'phpbb2' ); + $mx_cache->load_file( 'functions_module', 'phpbb3' ); + $mx_cache->load_file( 'message_parser' , 'phpbb3' ); $phpbb_admin_path = ( defined( 'PHPBB_ADMIN_PATH' ) ) ? PHPBB_ADMIN_PATH : 'adm/'; @@ -287,7 +287,7 @@ function _read_menu_actions( $menu_array, $category = MAIN_CATEGORY ) function assign_menu() { - global $lang, $db, $template, $mx_user, $mx_root_path, $phpbb_root_path, $phpEx, $userdata; + global $lang, $db, $board_config, $template, $mx_user, $mx_root_path, $phpbb_root_path, $phpEx, $userdata; $allow_menu_sort = true; // # @@ -312,7 +312,7 @@ function assign_menu() { $module_rows = $db->sql_fetchrowset( $q_modules ); } - $db->sql_freeresult( $result ); + $db->sql_freeresult( $q_modules ); $menu_array = array(); for( $module_cnt = 0; $module_cnt < $total_modules; $module_cnt++ ) { @@ -343,7 +343,10 @@ function assign_menu() case 'phpbb2': $mnu_ary = read_admin( $phpbb_root_path . 'admin/' ); $menu_array = array(); - + + $lang['Group_rank_order'] = isset($lang['Group_rank_order']) ? $lang['Group_rank_order'] : $mx_user->lang('Group_rank_order'); + $lang['Resync_Post_counts'] = isset($lang['Resync_Post_counts']) ? $lang['Resync_Post_counts'] : $mx_user->lang('Resync_Post_counts'); + foreach( $mnu_ary as $key => $menu ) { $i = 0; @@ -439,12 +442,12 @@ function assign_menu() switch ( $this->category ) { case OLYMPUS_CATEGORY: - $menu_link_params = preg_replace( '#panel=[^&]*#', '&cat=' . $this->category . '&panel=' . $panel, $file_part[1] ); + $menu_link_params = preg_replace( '#panel=[^&]*#', '&cat=' . $this->category . '&panel=' . $panel, (isset($file_part[1]) ? $file_part[1] : '') ); break; case PHPBB2X_CATEGORY: case MODULE_CATEGORY: case MAIN_CATEGORY: - $menu_link_params = str_replace( '?', '', '&cat=' . $this->category . '&panel=' . $panel . '&' . $file_part[1] ); + $menu_link_params = str_replace( '?', '', '&cat=' . $this->category . '&panel=' . $panel . '&' . (isset($file_part[1]) ? $file_part[1] : '') ); break; } @@ -469,6 +472,9 @@ function assign_menu() //print_r($module_link); //print_r("t |
]*>/,"").replace(/<\/pre>\s*$/,""))}catch(i){return null}return c},abort:function(){var t=this;l&&l.contentWindow&&(l.contentWindow.stop?l.contentWindow.stop():l.contentWindow.document.execCommand?l.contentWindow.document.execCommand("Stop"):l.src="about:blank"),e.call(this,function(){t.dispatchEvent("abort")})},destroy:function(){this.getRuntime().getShim().removeInstance(this.uid)}})}return e.XMLHttpRequest=u}),n("moxie/runtime/html4/image/Image",["moxie/runtime/html4/Runtime","moxie/runtime/html5/image/Image"],function(e,t){return e.Image=t}),a(["moxie/core/utils/Basic","moxie/core/utils/Encode","moxie/core/utils/Env","moxie/core/Exceptions","moxie/core/utils/Dom","moxie/core/EventTarget","moxie/runtime/Runtime","moxie/runtime/RuntimeClient","moxie/file/Blob","moxie/core/I18n","moxie/core/utils/Mime","moxie/file/FileInput","moxie/file/File","moxie/file/FileDrop","moxie/file/FileReader","moxie/core/utils/Url","moxie/runtime/RuntimeTarget","moxie/xhr/FormData","moxie/xhr/XMLHttpRequest","moxie/image/Image","moxie/core/utils/Events","moxie/runtime/html5/image/ResizerCanvas"])}(this)}); +/** + * Plupload - multi-runtime File Uploader + * v2.3.3 + * + * Copyright 2013, Moxiecode Systems AB + * Released under GPL License. + * + * License: http://www.plupload.com/license + * Contributing: http://www.plupload.com/contributing + * + * Date: 2017-08-28 + */ +!function(e,t){var i=function(){var e={};return t.apply(e,arguments),e.plupload};"function"==typeof define&&define.amd?define("plupload",["./moxie"],i):"object"==typeof module&&module.exports?module.exports=i(require("./moxie")):e.plupload=i(e.moxie)}(this||window,function(e){!function(e,t,i){function n(e){function t(e,t,i){var r={chunks:"slice_blob",jpgresize:"send_binary_string",pngresize:"send_binary_string",progress:"report_upload_progress",multi_selection:"select_multiple",dragdrop:"drag_and_drop",drop_element:"drag_and_drop",headers:"send_custom_headers",urlstream_upload:"send_binary_string",canSendBinary:"send_binary",triggerDialog:"summon_file_dialog"};r[e]?n[r[e]]=t:i||(n[e]=t)}var i=e.required_features,n={};return"string"==typeof i?l.each(i.split(/\s*,\s*/),function(e){t(e,!0)}):"object"==typeof i?l.each(i,function(e,i){t(i,e)}):i===!0&&(e.chunk_size&&e.chunk_size>0&&(n.slice_blob=!0),l.isEmptyObj(e.resize)&&e.multipart!==!1||(n.send_binary_string=!0),e.http_method&&(n.use_http_method=e.http_method),l.each(e,function(e,i){t(i,!!e,!0)})),n}var r=window.setTimeout,s={},a=t.core.utils,o=t.runtime.Runtime,l={VERSION:"2.3.3",STOPPED:1,STARTED:2,QUEUED:1,UPLOADING:2,FAILED:4,DONE:5,GENERIC_ERROR:-100,HTTP_ERROR:-200,IO_ERROR:-300,SECURITY_ERROR:-400,INIT_ERROR:-500,FILE_SIZE_ERROR:-600,FILE_EXTENSION_ERROR:-601,FILE_DUPLICATE_ERROR:-602,IMAGE_FORMAT_ERROR:-700,MEMORY_ERROR:-701,IMAGE_DIMENSIONS_ERROR:-702,moxie:t,mimeTypes:a.Mime.mimes,ua:a.Env,typeOf:a.Basic.typeOf,extend:a.Basic.extend,guid:a.Basic.guid,getAll:function(e){var t,i=[];"array"!==l.typeOf(e)&&(e=[e]);for(var n=e.length;n--;)t=l.get(e[n]),t&&i.push(t);return i.length?i:null},get:a.Dom.get,each:a.Basic.each,getPos:a.Dom.getPos,getSize:a.Dom.getSize,xmlEncode:function(e){var t={"<":"lt",">":"gt","&":"amp",'"':"quot","'":"#39"},i=/[<>&\"\']/g;return e?(""+e).replace(i,function(e){return t[e]?"&"+t[e]+";":e}):e},toArray:a.Basic.toArray,inArray:a.Basic.inArray,inSeries:a.Basic.inSeries,addI18n:t.core.I18n.addI18n,translate:t.core.I18n.translate,sprintf:a.Basic.sprintf,isEmptyObj:a.Basic.isEmptyObj,hasClass:a.Dom.hasClass,addClass:a.Dom.addClass,removeClass:a.Dom.removeClass,getStyle:a.Dom.getStyle,addEvent:a.Events.addEvent,removeEvent:a.Events.removeEvent,removeAllEvents:a.Events.removeAllEvents,cleanName:function(e){var t,i;for(i=[/[\300-\306]/g,"A",/[\340-\346]/g,"a",/\307/g,"C",/\347/g,"c",/[\310-\313]/g,"E",/[\350-\353]/g,"e",/[\314-\317]/g,"I",/[\354-\357]/g,"i",/\321/g,"N",/\361/g,"n",/[\322-\330]/g,"O",/[\362-\370]/g,"o",/[\331-\334]/g,"U",/[\371-\374]/g,"u"],t=0;t0?"&":"?")+i),e},formatSize:function(e){function t(e,t){return Math.round(e*Math.pow(10,t))/Math.pow(10,t)}if(e===i||/\D/.test(e))return l.translate("N/A");var n=Math.pow(1024,4);return e>n?t(e/n,1)+" "+l.translate("tb"):e>(n/=1024)?t(e/n,1)+" "+l.translate("gb"):e>(n/=1024)?t(e/n,1)+" "+l.translate("mb"):e>1024?Math.round(e/1024)+" "+l.translate("kb"):e+" "+l.translate("b")},parseSize:a.Basic.parseSizeStr,predictRuntime:function(e,t){var i,n;return i=new l.Uploader(e),n=o.thatCan(i.getOption().required_features,t||e.runtimes),i.destroy(),n},addFileFilter:function(e,t){s[e]=t}};l.addFileFilter("mime_types",function(e,t,i){e.length&&!e.regexp.test(t.name)?(this.trigger("Error",{code:l.FILE_EXTENSION_ERROR,message:l.translate("File extension error."),file:t}),i(!1)):i(!0)}),l.addFileFilter("max_file_size",function(e,t,i){var n;e=l.parseSize(e),t.size!==n&&e&&t.size>e?(this.trigger("Error",{code:l.FILE_SIZE_ERROR,message:l.translate("File size error."),file:t}),i(!1)):i(!0)}),l.addFileFilter("prevent_duplicates",function(e,t,i){if(e)for(var n=this.files.length;n--;)if(t.name===this.files[n].name&&t.size===this.files[n].size)return this.trigger("Error",{code:l.FILE_DUPLICATE_ERROR,message:l.translate("Duplicate file error."),file:t}),i(!1),void 0;i(!0)}),l.addFileFilter("prevent_empty",function(e,t,n){e&&!t.size&&t.size!==i?(this.trigger("Error",{code:l.FILE_SIZE_ERROR,message:l.translate("File size error."),file:t}),n(!1)):n(!0)}),l.Uploader=function(e){function a(){var e,t,i=0;if(this.state==l.STARTED){for(t=0;t 0?Math.ceil(100*(e.loaded/e.size)):100,d()}function d(){var e,t,n,r=0;for(I.reset(),e=0;e S)&&(r+=n),I.loaded+=n):I.size=i,t.status==l.DONE?I.uploaded++:t.status==l.FAILED?I.failed++:I.queued++;I.size===i?I.percent=D.length>0?Math.ceil(100*(I.uploaded/D.length)):0:(I.bytesPerSec=Math.ceil(r/((+new Date-S||1)/1e3)),I.percent=I.size>0?Math.ceil(100*(I.loaded/I.size)):0)}function c(){var e=F[0]||P[0];return e?e.getRuntime().uid:!1}function f(){this.bind("FilesAdded FilesRemoved",function(e){e.trigger("QueueChanged"),e.refresh()}),this.bind("CancelUpload",b),this.bind("BeforeUpload",m),this.bind("UploadFile",_),this.bind("UploadProgress",E),this.bind("StateChanged",v),this.bind("QueueChanged",d),this.bind("Error",R),this.bind("FileUploaded",y),this.bind("Destroy",z)}function p(e,i){var n=this,r=0,s=[],a={runtime_order:e.runtimes,required_caps:e.required_features,preferred_caps:x,swf_url:e.flash_swf_url,xap_url:e.silverlight_xap_url};l.each(e.runtimes.split(/\s*,\s*/),function(t){e[t]&&(a[t]=e[t])}),e.browse_button&&l.each(e.browse_button,function(i){s.push(function(s){var u=new t.file.FileInput(l.extend({},a,{accept:e.filters.mime_types,name:e.file_data_name,multiple:e.multi_selection,container:e.container,browse_button:i}));u.onready=function(){var e=o.getInfo(this.ruid);l.extend(n.features,{chunks:e.can("slice_blob"),multipart:e.can("send_multipart"),multi_selection:e.can("select_multiple")}),r++,F.push(this),s()},u.onchange=function(){n.addFile(this.files)},u.bind("mouseenter mouseleave mousedown mouseup",function(t){U||(e.browse_button_hover&&("mouseenter"===t.type?l.addClass(i,e.browse_button_hover):"mouseleave"===t.type&&l.removeClass(i,e.browse_button_hover)),e.browse_button_active&&("mousedown"===t.type?l.addClass(i,e.browse_button_active):"mouseup"===t.type&&l.removeClass(i,e.browse_button_active)))}),u.bind("mousedown",function(){n.trigger("Browse")}),u.bind("error runtimeerror",function(){u=null,s()}),u.init()})}),e.drop_element&&l.each(e.drop_element,function(e){s.push(function(i){var s=new t.file.FileDrop(l.extend({},a,{drop_zone:e}));s.onready=function(){var e=o.getInfo(this.ruid);l.extend(n.features,{chunks:e.can("slice_blob"),multipart:e.can("send_multipart"),dragdrop:e.can("drag_and_drop")}),r++,P.push(this),i()},s.ondrop=function(){n.addFile(this.files)},s.bind("error runtimeerror",function(){s=null,i()}),s.init()})}),l.inSeries(s,function(){"function"==typeof i&&i(r)})}function g(e,n,r,s){var a=new t.image.Image;try{a.onload=function(){n.width>this.width&&n.height>this.height&&n.quality===i&&n.preserve_headers&&!n.crop?(this.destroy(),s(e)):a.downsize(n.width,n.height,n.crop,n.preserve_headers)},a.onresize=function(){var t=this.getAsBlob(e.type,n.quality);this.destroy(),s(t)},a.bind("error runtimeerror",function(){this.destroy(),s(e)}),a.load(e,r)}catch(o){s(e)}}function h(e,i,r){function s(e,i,n){var r=O[e];switch(e){case"max_file_size":"max_file_size"===e&&(O.max_file_size=O.filters.max_file_size=i);break;case"chunk_size":(i=l.parseSize(i))&&(O[e]=i,O.send_file_name=!0);break;case"multipart":O[e]=i,i||(O.send_file_name=!0);break;case"http_method":O[e]="PUT"===i.toUpperCase()?"PUT":"POST";break;case"unique_names":O[e]=i,i&&(O.send_file_name=!0);break;case"filters":"array"===l.typeOf(i)&&(i={mime_types:i}),n?l.extend(O.filters,i):O.filters=i,i.mime_types&&("string"===l.typeOf(i.mime_types)&&(i.mime_types=t.core.utils.Mime.mimes2extList(i.mime_types)),i.mime_types.regexp=function(e){var t=[];return l.each(e,function(e){l.each(e.extensions.split(/,/),function(e){/^\s*\*\s*$/.test(e)?t.push("\\.*"):t.push("\\."+e.replace(new RegExp("["+"/^$.*+?|()[]{}\\".replace(/./g,"\\$&")+"]","g"),"\\$&"))})}),new RegExp("("+t.join("|")+")$","i")}(i.mime_types),O.filters.mime_types=i.mime_types);break;case"resize":O.resize=i?l.extend({preserve_headers:!0,crop:!1},i):!1;break;case"prevent_duplicates":O.prevent_duplicates=O.filters.prevent_duplicates=!!i;break;case"container":case"browse_button":case"drop_element":i="container"===e?l.get(i):l.getAll(i);case"runtimes":case"multi_selection":case"flash_swf_url":case"silverlight_xap_url":O[e]=i,n||(u=!0);break;default:O[e]=i}n||a.trigger("OptionChanged",e,i,r)}var a=this,u=!1;"object"==typeof e?l.each(e,function(e,t){s(t,e,r)}):s(e,i,r),r?(O.required_features=n(l.extend({},O)),x=n(l.extend({},O,{required_features:!0}))):u&&(a.trigger("Destroy"),p.call(a,O,function(e){e?(a.runtime=o.getInfo(c()).type,a.trigger("Init",{runtime:a.runtime}),a.trigger("PostInit")):a.trigger("Error",{code:l.INIT_ERROR,message:l.translate("Init error.")})}))}function m(e,t){if(e.settings.unique_names){var i=t.name.match(/\.([^.]+)$/),n="part";i&&(n=i[1]),t.target_name=t.id+"."+n}}function _(e,i){function n(){c-->0?r(s,1e3):(i.loaded=p,e.trigger("Error",{code:l.HTTP_ERROR,message:l.translate("HTTP Error."),file:i,response:T.responseText,status:T.status,responseHeaders:T.getAllResponseHeaders()}))}function s(){var t,n,r={};i.status===l.UPLOADING&&e.state!==l.STOPPED&&(e.settings.send_file_name&&(r.name=i.target_name||i.name),d&&f.chunks&&o.size>d?(n=Math.min(d,o.size-p),t=o.slice(p,p+n)):(n=o.size,t=o),d&&f.chunks&&(e.settings.send_chunk_number?(r.chunk=Math.ceil(p/d),r.chunks=Math.ceil(o.size/d)):(r.offset=p,r.total=o.size)),e.trigger("BeforeChunkUpload",i,r,t,p)&&a(r,t,n))}function a(a,d,g){var m;T=new t.xhr.XMLHttpRequest,T.upload&&(T.upload.onprogress=function(t){i.loaded=Math.min(i.size,p+t.loaded),e.trigger("UploadProgress",i)}),T.onload=function(){return T.status<200&&T.status>=400?(n(),void 0):(c=e.settings.max_retries,g =o.size?(i.size!=i.origSize&&(o.destroy(),o=null),e.trigger("UploadProgress",i),i.status=l.DONE,i.completeTimestamp=+new Date,e.trigger("FileUploaded",i,{response:T.responseText,status:T.status,responseHeaders:T.getAllResponseHeaders()})):r(s,1),void 0)},T.onerror=function(){n()},T.onloadend=function(){this.destroy()},e.settings.multipart&&f.multipart?(T.open(e.settings.http_method,u,!0),l.each(e.settings.headers,function(e,t){T.setRequestHeader(t,e)}),m=new t.xhr.FormData,l.each(l.extend(a,e.settings.multipart_params),function(e,t){m.append(t,e)}),m.append(e.settings.file_data_name,d),T.send(m,h)):(u=l.buildUrl(e.settings.url,l.extend(a,e.settings.multipart_params)),T.open(e.settings.http_method,u,!0),l.each(e.settings.headers,function(e,t){T.setRequestHeader(t,e)}),T.hasRequestHeader("Content-Type")||T.setRequestHeader("Content-Type","application/octet-stream"),T.send(d,h))}var o,u=e.settings.url,d=e.settings.chunk_size,c=e.settings.max_retries,f=e.features,p=0,h={runtime_order:e.settings.runtimes,required_caps:e.settings.required_features,preferred_caps:x,swf_url:e.settings.flash_swf_url,xap_url:e.settings.silverlight_xap_url};i.loaded&&(p=i.loaded=d?d*Math.floor(i.loaded/d):0),o=i.getSource(),l.isEmptyObj(e.settings.resize)||-1===l.inArray(o.type,["image/jpeg","image/png"])?s():g(o,e.settings.resize,h,function(e){o=e,i.size=e.size,s()})}function E(e,t){u(t)}function v(e){if(e.state==l.STARTED)S=+new Date;else if(e.state==l.STOPPED)for(var t=e.files.length-1;t>=0;t--)e.files[t].status==l.UPLOADING&&(e.files[t].status=l.QUEUED,d())}function b(){T&&T.abort()}function y(e){d(),r(function(){a.call(e)},1)}function R(e,t){t.code===l.INIT_ERROR?e.destroy():t.code===l.HTTP_ERROR&&(t.file.status=l.FAILED,t.file.completeTimestamp=+new Date,u(t.file),e.state==l.STARTED&&(e.trigger("CancelUpload"),r(function(){a.call(e)},1)))}function z(e){e.stop(),l.each(D,function(e){e.destroy()}),D=[],F.length&&(l.each(F,function(e){e.destroy()}),F=[]),P.length&&(l.each(P,function(e){e.destroy()}),P=[]),x={},U=!1,S=T=null,I.reset()}var O,S,I,T,w=l.guid(),D=[],x={},F=[],P=[],U=!1;O={chunk_size:0,file_data_name:"file",filters:{mime_types:[],max_file_size:0,prevent_duplicates:!1,prevent_empty:!0},flash_swf_url:"js/Moxie.swf",http_method:"POST",max_retries:0,multipart:!0,multi_selection:!0,resize:!1,runtimes:o.order,send_file_name:!0,send_chunk_number:!0,silverlight_xap_url:"js/Moxie.xap"},h.call(this,e,null,!0),I=new l.QueueProgress,l.extend(this,{id:w,uid:w,state:l.STOPPED,features:{},runtime:null,files:D,settings:O,total:I,init:function(){var e,t,i=this;return e=i.getOption("preinit"),"function"==typeof e?e(i):l.each(e,function(e,t){i.bind(t,e)}),f.call(i),l.each(["container","browse_button","drop_element"],function(e){return null===i.getOption(e)?(t={code:l.INIT_ERROR,message:l.sprintf(l.translate("%s specified, but cannot be found."),e)},!1):void 0}),t?i.trigger("Error",t):O.browse_button||O.drop_element?(p.call(i,O,function(e){var t=i.getOption("init");"function"==typeof t?t(i):l.each(t,function(e,t){i.bind(t,e)}),e?(i.runtime=o.getInfo(c()).type,i.trigger("Init",{runtime:i.runtime}),i.trigger("PostInit")):i.trigger("Error",{code:l.INIT_ERROR,message:l.translate("Init error.")})}),void 0):i.trigger("Error",{code:l.INIT_ERROR,message:l.translate("You must specify either browse_button or drop_element.")})},setOption:function(e,t){h.call(this,e,t,!this.runtime)},getOption:function(e){return e?O[e]:O},refresh:function(){F.length&&l.each(F,function(e){e.trigger("Refresh")}),this.trigger("Refresh")},start:function(){this.state!=l.STARTED&&(this.state=l.STARTED,this.trigger("StateChanged"),a.call(this))},stop:function(){this.state!=l.STOPPED&&(this.state=l.STOPPED,this.trigger("StateChanged"),this.trigger("CancelUpload"))},disableBrowse:function(){U=arguments[0]!==i?arguments[0]:!0,F.length&&l.each(F,function(e){e.disable(U)}),this.trigger("DisableBrowse",U)},getFile:function(e){var t;for(t=D.length-1;t>=0;t--)if(D[t].id===e)return D[t]},addFile:function(e,i){function n(e,t){var i=[];l.each(u.settings.filters,function(t,n){s[n]&&i.push(function(i){s[n].call(u,t,e,function(e){i(!e)})})}),l.inSeries(i,t)}function a(e){var s=l.typeOf(e);if(e instanceof t.file.File){if(!e.ruid&&!e.isDetached()){if(!o)return!1;e.ruid=o,e.connectRuntime(o)}a(new l.File(e))}else e instanceof t.file.Blob?(a(e.getSource()),e.destroy()):e instanceof l.File?(i&&(e.name=i),d.push(function(t){n(e,function(i){i||(D.push(e),f.push(e),u.trigger("FileFiltered",e)),r(t,1)})})):-1!==l.inArray(s,["file","blob"])?a(new t.file.File(null,e)):"node"===s&&"filelist"===l.typeOf(e.files)?l.each(e.files,a):"array"===s&&(i=null,l.each(e,a))}var o,u=this,d=[],f=[];o=c(),a(e),d.length&&l.inSeries(d,function(){f.length&&u.trigger("FilesAdded",f)})},removeFile:function(e){for(var t="string"==typeof e?e:e.id,i=D.length-1;i>=0;i--)if(D[i].id===t)return this.splice(i,1)[0]},splice:function(e,t){var n=D.splice(e===i?0:e,t===i?D.length:t),r=!1;return this.state==l.STARTED&&(l.each(n,function(e){return e.status===l.UPLOADING?(r=!0,!1):void 0}),r&&this.stop()),this.trigger("FilesRemoved",n),l.each(n,function(e){e.destroy()}),r&&this.start(),n},dispatchEvent:function(e){var t,i;if(e=e.toLowerCase(),t=this.hasEventListener(e)){t.sort(function(e,t){return t.priority-e.priority}),i=[].slice.call(arguments),i.shift(),i.unshift(this);for(var n=0;n = 4.1.0, PHP 5, PHP 7) +*/ +@define('PHP_VERSION_MX', PHP_VERSION); // If we are on PHP >= 6.0.0 we do not need some code if (version_compare(PHP_VERSION, '5.3.0', '>=')) @@ -167,11 +173,123 @@ function deregister_globals() die("Hacking attempt"); } -/* -* Define some basic configuration arrays this also prevents -* malicious rewriting of language and otherarray values via -* URI params -*/ +if (@ini_get('register_globals') == '1' || strtolower(@ini_get('register_globals')) == 'on') +{ + // PHP4+ path + $not_unset = array('_GET', '_POST', '_COOKIE', '_SERVER', '_SESSION', '_ENV', '_POST', 'phpEx', 'phpbb_root_path', 'mx_root_path'); + + // Not only will array_merge give a warning if a parameter + // is not an array, it will actually fail. So we check if + // _SESSION has been initialised. + if (!isset($_SESSION) || !is_array($_SESSION)) + { + $_SESSION = array(); + } + + // Merge all into one extremely huge array; unset + // this later + // + // Note! Since array_merge() destroys numerical keys - if the array is numerically indexed, the keys get reindexed in a continuous way - we use the + operator instead + // + //$input = array_merge($_GET, $_POST, $_COOKIE, $_SERVER, $_SESSION, $_ENV, $_POST); + $input = $_GET + $_POST + $_COOKIE + $_SERVER + $_SESSION + $_ENV + $_POST; + + unset($input['input']); + unset($input['not_unset']); + + while (list($var,) = @each($input)) + { + if (in_array($var, $not_unset)) + { + die('Hacking attempt!'); + } + unset($$var); + } + unset($input); +} + +// +// addslashes to vars if magic_quotes_gpc is off +// this is a security precaution to prevent someone +// trying to break out of a SQL statement. +// +// If we are on PHP >= 6.0.0 we do not need some code +if ( (@phpversion() < '5.3.0') or ( @function_exists('get_magic_quotes_gpc') && !@get_magic_quotes_gpc() ) ) +{ + if( is_array($_GET) ) + { + while( list($k, $v) = each($_GET) ) + { + if( is_array($_GET[$k]) ) + { + while( list($k2, $v2) = each($_GET[$k]) ) + { + $_GET[$k][$k2] = addslashes($v2); + } + @reset($_GET[$k]); + } + else + { + $_GET[$k] = addslashes($v); + } + } + @reset($_GET); + } + + if( is_array($_POST) ) + { + while( list($k, $v) = each($_POST) ) + { + if( is_array($_POST[$k]) ) + { + while( list($k2, $v2) = each($_POST[$k]) ) + { + $_POST[$k][$k2] = addslashes($v2); + } + @reset($_POST[$k]); + } + else + { + $_POST[$k] = addslashes($v); + } + } + @reset($_POST); + } + + if( is_array($_COOKIE) ) + { + while( list($k, $v) = each($_COOKIE) ) + { + if( is_array($_COOKIE[$k]) ) + { + while( list($k2, $v2) = each($_COOKIE[$k]) ) + { + $_COOKIE[$k][$k2] = addslashes($v2); + } + @reset($_COOKIE[$k]); + } + else + { + $_COOKIE[$k] = addslashes($v); + } + } + @reset($_COOKIE); + } +} + +// +// Temp fix for timezone +// +if (@function_exists('date_default_timezone_set') && @function_exists('date_default_timezone_get')) +{ + @date_default_timezone_set(@date_default_timezone_get()); +} + +// +// Define some basic configuration arrays this also prevents +// malicious rewriting of language and otherarray values via +// URI params +// $board_config = array(); $portal_config = array(); $userdata = array(); @@ -205,6 +323,8 @@ function deregister_globals() require($mx_root_path . INCLUDES . 'utf/utf_tools.' . $phpEx); //Load UTF-8 Tools require($mx_root_path . INCLUDES . 'mx_functions_core.' . $phpEx); // CORE class +require($mx_root_path . 'vendor/paragonie/random_compat/lib/random.' . $phpEx); + // Setup class loader first if (@phpversion() >= '5.1.2') { @@ -225,7 +345,6 @@ function deregister_globals() */ $mx_cache = new mx_cache(); - /* * Define Users/Group/Sessions backend, and validate * Set $portal_config, $phpbb_root_path, $tplEx, $table_prefix & PORTAL_BACKEND @@ -239,6 +358,26 @@ function deregister_globals() @date_default_timezone_set(@date_default_timezone_get()); } +// +// instatiate the mx_backend class +// +$mx_backend = new mx_backend(); + +// +// Define some general backend definitions +// PORTAL_URL, PHPBB_URL, PORTAL_VERSION & $board_config +// +$mx_backend->setup_backend(); + +// +// Instantiate Dummy phpBB Classes +// +if( class_exists('phpBB2')) +{ + $phpBB2 = new phpBB2(); +} +$phpBB3 = new phpBB3(); + // // MX-Publisher Includes - doing the rest // @@ -258,6 +397,12 @@ function deregister_globals() // $mx_user = new mx_user(); +/** +* Instantiate the mx_language class +* $language->_load_lang($mx_root_path, 'lang_main'); +*/ +$language = new mx_language(); + // // Instantiate the mx_page (CORE) class // @@ -271,14 +416,8 @@ function deregister_globals() // // Obtain and encode users IP // -$client_ip = ( !empty($_SERVER['REMOTE_ADDR']) ) ? $_SERVER['REMOTE_ADDR'] : ( ( !empty($_ENV['REMOTE_ADDR']) ) ? $_ENV['REMOTE_ADDR'] : getenv('REMOTE_ADDR') ); -$user_ip = phpBB2::encode_ip($client_ip); - -// -// Define some general backend definitions -// PORTAL_URL, PHPBB_URL, PORTAL_VERSION & $board_config -// -$mx_backend->setup_backend(); +$client_ip = (!empty($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : ((!empty($_ENV['REMOTE_ADDR'])) ? $_ENV['REMOTE_ADDR'] : getenv('REMOTE_ADDR')); +$user_ip = $phpBB2->encode_ip($client_ip); // // Instantiate the mx_bbcode class @@ -320,4 +459,5 @@ function deregister_globals() $do_gzip_compress = FALSE; mx_session_start(); // Note: this needs $board_config populated + ?> \ No newline at end of file diff --git a/contrib/phpbb3_backend_language/lang_romanian/lang_admin.php b/contrib/phpbb3_backend_language/lang_romanian/lang_admin.php index ba08326d..1903f698 100644 --- a/contrib/phpbb3_backend_language/lang_romanian/lang_admin.php +++ b/contrib/phpbb3_backend_language/lang_romanian/lang_admin.php @@ -1,9 +1,9 @@ Pagina de start a administratorului din panel-ul stâng. Pentru a reveni la pagina de start a forumului dumneavoastră, apăsaţi pe logo-ul phpBB-ului aflat, de asemenea, în panel-ul stâng. Celelalte legături din partea stângă vă permit să controlaţi orice aspect al forumului, fiecare ecran va avea instrucţiuni care dau explicaţii despre cum se folosesc uneltele.'; +$lang['Welcome_mxBB'] = 'Bine aţi venit la panoul de control al portalului mxBB'; +$lang['Admin_intro_mxBB'] = 'Vă mulţumim pentru aţi ales mxBB-Portal ca soluţie pentru portalul/cms-ul dumneavoastră şi phpBB ca soluţie pentru forumul dumneavoastră. Acest ecran vă oferă o privire de ansamblu a diverselor statistici ale site-ului dumneavoastră. Puteţi reveni la această pagină folosind legătura Pagina de start a administratorului din panel-ul stâng. Pentru a reveni la pagina de start a forumului dumneavoastră, apăsaţi pe logo-ul phpBB-ului aflat, de asemenea, în panel-ul stâng. Celelalte legături din partea stângă vă permit să controlaţi orice aspect al forumului, fiecare ecran va avea instrucţiuni care dau explicaţii despre cum se folosesc uneltele.'; // // General @@ -116,19 +116,19 @@ $lang['Portal_Name'] = 'Nume Portal:'; $lang['Portal_Description'] = 'Descriptie Portal:'; $lang['Portal_PHPBB_Url'] = 'URL pt. instarea ta de forum phpBB:'; -$lang['Portal_Url'] = 'URL pentru Mx-Publisher:'; +$lang['Portal_Url'] = 'URL pentru mxBB-Portal:'; $lang['Portal_Config_updated'] = 'Configuraţia Portalului Actualizată cu Succes'; $lang['Click_return_portal_config'] = 'Click %sAici%s pentru a te intoarce la Configurarea Portalului'; $lang['PHPBB_info'] = 'Informatii phpBB'; $lang['PHPBB_version'] = 'Versiunea phpBB:'; $lang['PHPBB_script_path'] = 'phpBB Cale Script:'; $lang['PHPBB_server_name'] = 'phpBB Domeniu (nume_server):'; -$lang['MX_Portal'] = 'Mx-Publisher'; -$lang['MX_Modules'] = 'MXP-Module'; +$lang['MX_Portal'] = 'mxBB-Portal'; +$lang['MX_Modules'] = 'mxBB-Module'; $lang['Phpbb'] = 'phpBB'; $lang['Top_phpbb_links'] = 'phpBB Stats în Header (valoare impicită)
- linkuri la postari noi/necitite etc'; -$lang['Portal_version'] = 'Versiune Mx-Publisher:'; -$lang['Mx_use_cache'] = 'Foloseşte MXP Bloc Cache'; +$lang['Portal_version'] = 'Versiune mxBB-Portal:'; +$lang['Mx_use_cache'] = 'Foloseşte mxBB Bloc Cache'; $lang['Mx_use_cache_explain'] = 'Datele din Bloc este în fişiere individuale cache/bloc_*.xml. Fişierele Bloc cache sunt create când Blocurile sunt editate.'; $lang['Mx_mod_rewrite'] = 'Foloseste mod_rewrite'; $lang['Mx_mod_rewrite_explain'] = 'Daca eşti pe server Apache, şi ai mod_rewrite activat, poţi rescrie url-urile ca \'page=x\' cu alternative mai intuitive. Citeşte pentru mai multe documentaţia pentru modulul mx_mod_rewrite.'; @@ -307,104 +307,6 @@ $lang['Click_return_portalpage_admin'] = 'Click %sAici%s pt. întoarcere la Pagina Portalului'; $lang['BlockCP_Config_updated'] = 'Blocul a fost Actualizat...'; - -// -// Pages Administration -// -$lang['Page_admin'] = 'Page Administration'; -$lang['Page_admin_explain'] = 'Use this form to add, delete and change the settings for Portal Pages and Page Templates.
To use this panel, you need to have JavaScript and cookies enabled in your browser!'; -$lang['Page_admin_edit'] = 'Page Edit'; -$lang['Page_admin_private'] = 'Advanced Page (PRIVATE) Permissions'; -$lang['Page_admin_settings'] = 'Page Settings'; -$lang['Page_admin_new_page'] = 'New Page Administration'; -$lang['Page'] = 'Page'; -$lang['Page_Id'] = 'Page ID'; -$lang['Page_icon'] = 'Page Icon
- to be used in the adminCP only, eg. icon_home.gif (default)'; -$lang['Page_alt_icon'] = 'Alternative Page Icon
- Full url (http://...) to custom page icon.'; -$lang['Default_page_style'] = 'Portal Style (default)
To use the default setting, leave this unset.'; -$lang['Override_page_style'] = 'Override user style'; -$lang['Override_page_style_explain'] = ' '; -$lang['Page_header'] = 'Page header file
- i.e. overall_header.tpl (default), overall_noheader.tpl (no header) or user custom header file.
To use the default setting, leave this blank.'; -$lang['Page_footer'] = 'Page footer file
- i.e. overall_footer.tpl (default) or user custom footer file.
To use the default setting, leave this blank.'; -$lang['Page_main_layout'] = 'Page main layout file
- i.e. mx_main_layout.tpl (default) or user custom header file.
To use the default setting, leave this blank.'; -$lang['Page_Navigation_block'] = 'Page header navigation block'; -$lang['Page_Navigation_block_explain'] = '- This is the page header navigation block, provided you\'ve chosen a overall header file which supports page navigation.
To use the default setting, leave this unset.'; -$lang['Auth_Page'] = 'Permissions'; -$lang['Select_sort_method'] = 'Select Sort Method'; -$lang['Order'] = 'Order'; -$lang['Sort'] = 'Sort'; -$lang['Width'] = 'Width'; -$lang['Height'] = 'Height'; -$lang['Page_sort_title'] = 'Page title'; -$lang['Page_sort_desc'] = 'Page description'; -$lang['Page_sort_created'] = 'Page created'; -$lang['Sort_Ascending'] = 'ASC'; -$lang['Sort_Descending'] = 'DESC'; -$lang['Return_to_page'] = 'Return to Portal Page'; -$lang['Auth_Page_group'] = '-> PRIVATE Group'; -$lang['Page_desc'] = 'Description'; -$lang['Page_parent'] = 'Parent Page'; -$lang['Add_Page'] = 'Add New Page'; -$lang['Page_Config_updated'] = 'Page Configuration Updated Successfully'; -$lang['Click_return_page_admin'] = 'Click %sHere%s to return to Page Administration'; -$lang['Remove_block'] = 'Remove Portal Block'; -$lang['Remove_block_explain'] = 'This will remove the block from this page. Beware: this operation cannot be undone!'; -$lang['Click_block_remove_yes'] = 'Click %sHere%s to remove the Block'; -$lang['Delete_page'] = 'Delete Page'; -$lang['Delete_page_explain'] = 'This will delete the Page. Beware: this operation cannot be undone!'; -$lang['Click_page_delete_yes'] = 'Click %sHere%s to delete the Page'; - -$lang['Mx_IP_filter'] = 'IP Filter'; -$lang['Mx_IP_filter_explain'] = 'To restrict access to this page by IP, enter the valid IP adresses, with one IP address per line.
Example: 127.0.0.1 or 127.1.*.*'; -$lang['Mx_phpBB_stats'] = 'phpBB Statistics in Header'; -$lang['Mx_phpBB_stats_explain'] = '- Links to new, unread posts, etc.'; -$lang['Column_admin'] = 'Page Column Administration'; -$lang['Column_admin_explain'] = 'Administrate Page Columns'; -$lang['Column'] = 'Page Column'; -$lang['Columns'] = 'Page Columns'; -$lang['Column_block'] = 'Page Column Block'; -$lang['Column_blocks'] = 'Page Column Blocks'; -$lang['Edit_Column'] = 'Edit a Column'; -$lang['Edit_Column_explain'] = 'Use this form to modify a column'; -$lang['Column_Size'] = 'Size of the column'; -$lang['Column_name'] = 'Column Name'; -$lang['Column_delete'] = 'Delete a Column'; -$lang['Page_updated'] = 'Page and Column information updated successfully'; -$lang['Create_column'] = 'Add New Column'; -$lang['Delete_page_column'] = 'Delete Page Column'; -$lang['Delete_page_column_explain'] = 'This will delete the Page Column. Beware: this operation cannot be undone!'; -$lang['Click_page_column_delete_yes'] = 'Click %sHere%s to delete the Page Column'; - -$lang['Add_Split_Block'] = 'Add Split Column Block'; -$lang['Add_Split_Block_explain'] = 'This block splits the column'; -$lang['Add_Dynamic_Block'] = 'Add Dynamic (Sub) Block'; -$lang['Add_Dynamic_Block_explain'] = 'This dynamic block defines subpages, set from the navigation menu'; -$lang['Add_Virtual_Block'] = 'Add Virtual (Page Blog) Block'; -$lang['Add_Virtual_Block_explain'] = 'This block turns the page into a virtual (blog) page'; - -// -// Page templates -// -$lang['Page_templates_admin'] = 'Page Templates Administration'; -$lang['Page_templates_admin_explain'] = 'Use this page to create, edit or delete Page Templates'; -$lang['Page_template'] = 'Page Template'; -$lang['Page_templates'] = 'Page Templates'; -$lang['Page_template_column'] = 'Page Template Column'; -$lang['Page_template_columns'] = 'Page Template Columns'; -$lang['Choose_page_template'] = 'Choose Page Template'; -$lang['Template_Config_updated'] = 'Template Configuration Updated'; -$lang['Add_Template'] = 'Add New Template'; -$lang['Template'] = 'Template'; -$lang['Template_name'] = 'Template Name'; -$lang['Page_template_delete'] = 'Delete Template'; -$lang['Delete_page_template'] = 'Delete Page Template'; -$lang['Delete_page_template_explain'] = 'This will delete the Page Template. Beware: this operation cannot be undone!'; -$lang['Click_page_template_delete_yes'] = 'Click %sHere%s to delete the Page Template'; -$lang['Delete_page_template_column'] = 'Delete Page Template'; -$lang['Delete_page_template_column_explain'] = 'This will delete the Page Template. Beware: this operation cannot be undone!'; -$lang['Click_page_template_column_delete_yes'] = 'Click %sHere%s to delete the Page Template'; - - // // Pages Administration // @@ -465,14 +367,6 @@ $lang['Delete_page_column_explain'] = 'Acesta va şterge Coloana Paginii. Atenţie, acestă operaţie nu este reversibilă!'; $lang['Click_page_column_delete_yes'] = 'Click %sAici%s pt. a şterge Colana Paginii'; - -$lang['Add_Split_Block'] = 'Add Split Column Block'; -$lang['Add_Split_Block_explain'] = 'This block splits the column'; -$lang['Add_Dynamic_Block'] = 'Add Dynamic (Sub) Block'; -$lang['Add_Dynamic_Block_explain'] = 'This dynamic block defines subpages, set from the navigation menu'; -$lang['Add_Virtual_Block'] = 'Add Virtual (Page Blog) Block'; -$lang['Add_Virtual_Block_explain'] = 'This block turns the page into a virtual (blog) page'; - // // Page templates // @@ -501,7 +395,7 @@ $lang['Cache_dir_write_protect'] = 'Directorul tau cache este protejat la scriere. Nu s-a putut genera fişierul cache'; $lang['Cache_generate'] = 'Fişierele cache au fost generate.'; $lang['Cache_submit'] = 'Să generez fişierul cache?'; -$lang['Cache_explain'] = 'Cu acestă opţiune poţi să generezi toate fişierele XML (fişiere cache) odată pentru toate blocurile portalului. Aceste fişiere permit reducerea numărului de cereri ale bazei de date necesare şi îmbunătăţesc performanţa portalului.
Notează: MXP cache trebuie activat (în Portal General Admin CP) petru ca aceste fişiere să fie folosite de sistem.
Mai Notează: fişierele cache sunt create on the fly când sunt şi blocurile de editare la fel.'; +$lang['Cache_explain'] = 'Cu acestă opţiune poţi să generezi toate fişierele XML (fişiere cache) odată pentru toate blocurile portalului. Aceste fişiere permit reducerea numărului de cereri ale bazei de date necesare şi îmbunătăţesc performanţa portalului.
Notează: mxBB cache trebuie activat (în Portal General Admin CP) petru ca aceste fişiere să fie folosite de sistem.
Mai Notează: fiÅŸierele cache sunt create on the fly când sunt ÅŸi blocurile de editare la fel.'; $lang['Generate_mx_cache'] = 'Generează Bloc Cache'; // @@ -639,11 +533,11 @@ // // Version Checker // -$lang['MXP_Version_up_to_date'] = 'Instalarea MXP este la zi. Nu există actualizări pentru versiunea ta de MXP.'; -$lang['MXP_Version_outdated'] = 'Se pare ca instalarea ta MXP nu este la zi. Actualizări există pentru versiunea ta de MXP. Te rog viziteză downloadare pachetul MXP Core pt. a obÅ£ine ultima versiune.'; -$lang['MXP_Latest_version_info'] = 'Ultima veriune disponibilă este MXP %s. '; -$lang['MXP_Current_version_info'] = 'Tu ai MXP %s.'; -$lang['MXP_Mailing_list_subscribe_reminder'] = 'Pentru ultimile informaÅ£ii de ÅŸtiri ÅŸi actualizări pentru MXP, de ce nu înscriete la lista de mailuri.'; +$lang['mxBB_Version_up_to_date'] = 'Instalarea mxBB este la zi. Nu există actualizări pentru versiunea ta de mxBB.'; +$lang['mxBB_Version_outdated'] = 'Se pare ca instalarea ta mxBB nu este la zi. Actualizări există pentru versiunea ta de mxBB. Te rog viziteză downloadare pachetul mxBB Core pt. a obÅ£ine ultima versiune.'; +$lang['mxBB_Latest_version_info'] = 'Ultima veriune disponibilă este mxBB %s. '; +$lang['mxBB_Current_version_info'] = 'Tu ai mxBB %s.'; +$lang['mxBB_Mailing_list_subscribe_reminder'] = 'Pentru ultimile informaÅ£ii de ÅŸtiri ÅŸi actualizări pentru mxBB, de ce nu înscriete la lista de mailuri.'; $lang['Trans_title'] = 'Translate to your Language'; $lang['Trans_description'] = 'Use Translate Control Panel to translate portal to your language'; diff --git a/docs/INSTALL.html b/docs/INSTALL.html new file mode 100644 index 00000000..6cf34e19 --- /dev/null +++ b/docs/INSTALL.html @@ -0,0 +1,275 @@ + + + + + + + + + + + + + +MXP • Installalation + + + + + + + ++ ++ + + + + diff --git a/docs/bg_header.gif b/docs/bg_header.gif new file mode 100644 index 00000000..351de9f4 Binary files /dev/null and b/docs/bg_header.gif differ diff --git a/docs/corners_left.gif b/docs/corners_left.gif new file mode 100644 index 00000000..206e5036 Binary files /dev/null and b/docs/corners_left.gif differ diff --git a/docs/corners_left.png b/docs/corners_left.png new file mode 100644 index 00000000..256bde3d Binary files /dev/null and b/docs/corners_left.png differ diff --git a/docs/corners_right.gif b/docs/corners_right.gif new file mode 100644 index 00000000..0ba66d50 Binary files /dev/null and b/docs/corners_right.gif differ diff --git a/docs/corners_right.png b/docs/corners_right.png new file mode 100644 index 00000000..df41823b Binary files /dev/null and b/docs/corners_right.png differ diff --git a/docs/mxp.css b/docs/mxp.css index abeef6f2..7e6d6764 100644 --- a/docs/mxp.css +++ b/docs/mxp.css @@ -1,832 +1,363 @@ -/***********************************************/ -/* Main */ -/***********************************************/ - -/* Fix for centering the container in IE */ -body{ - /* text-align: center; */ - margin: 0px; - padding: 0px; - font-family: Verdana, Arial, Helvetica, sans-serif; - color: #000; - line-height: 85%; - background: #ffffff url(images/theme/bg.gif) top left repeat-x; - /*background: #f0f0f0;*/ - - scrollbar-face-color: #DEE3E7; - scrollbar-highlight-color: #FFFFFF; - scrollbar-shadow-color: #DEE3E7; - scrollbar-3dlight-color: #D1D7DC; - scrollbar-arrow-color: #326030; - scrollbar-track-color: #EFEFEF; - scrollbar-darkshadow-color: #98AAB1; -} - -/* TinyMCE specific rules */ -body.mceContentBody { - text-align: left; - font-family: Verdana, Arial, Helvetica, sans-serif; - color: #000; - background: #FFF; -} - -/* Main Containers */ -#container{ - width: 750px; - min-width: 500px; - text-align: left; /* Fix for centering the container in IE */ - margin: 0px auto 0px auto; - /*background-color: #ffffff;*/ - border: 0px solid black; -} - -/* Main Containers */ -#container_100{ - width: 100%; - text-align: left; /* Fix for centering the container in IE */ - margin: 0px auto 0px auto; - /*background-color: #ffffff;*/ - border: 0px solid black; -} - -/* Outer and Inner Container */ -#outer { - width: auto; - border-left-style: solid; - border-left-width: 190px; /* left column width */ - border-left-color: #ffffff; /* left column colour */ - /*border-right-style: solid;*/ - /*border-right-width: 160px;*/ /* right column width */ - /*border-right-color: #EEEEDD;*/ /* right column colour */ - background-color: #fff; /* center column colour */ -} - -/* One-column */ -#outer_1_col { - width: auto; - /*border-left-style: solid;*/ - /*border-left-width: 220px;*/ /* left column width */ - /*border-left-color: #ffffff;*/ /* left column colour */ - /*border-right-style: solid;*/ - /*border-right-width: 160px;*/ /* right column width */ - /*border-right-color: #EEEEDD;*/ /* right column colour */ - background-color: #fff; /* center column colour */ -} - -#inner { - margin: 0px; - width: 100%; - - /* background: url(/templates/mxp/images/theme/leftcol.gif) -195px repeat-y; */ -} - -/* Columns */ -#leftcol{ - width: 190px; /* left column width */ - float: left; - position: relative; - padding: 0px; - margin: 0px; - margin-left: -190px; /* _negative_ left column width */ - - border-top: 1px solid #a1a1a1; - border-bottom: 1px solid #a1a1a1; - - background: url(images/theme/leftcol.gif) repeat-y; - - overflow:hidden; - z-index: 10; -} - -#rightcol{ - width: 190px; /* right column width */ - float: right; - position: relative; - padding: 0px; - margin: 0px; - margin-right: -190px; /* _negative_ right column width */ - - overflow:hidden; - z-index: 11; -} - -#middlecol{ - float: left; - width: 100%; - position: relative; - /*padding: 0px;*/ - z-index: 12; -} - -/* Block Container */ -div.blockcontainer{ - height: 1%; /* IE6 Fix */ - padding: 0px; -} - -#leftcol div.blockcontainer{ - margin: 10px; -} - -#middlecol div.blockcontainer{ - margin: 10px 10px 10px 20px; -} - -#rightcol div.blockcontainer{ - margin: 10px; -} - -/***********************************************/ -/* Layout */ -/***********************************************/ - -#header{ - /* background-color: #326030; - border-top: 1px solid gray; - border-bottom: 1px solid gray; - */ - margin: 0px; - padding: 0px; - - height:35px; - - /*background-image: url(more_col_base.jpg);*/ - /*background-repeat: repeat-y;*/ - /*background-position: right;*/ -} - -#header h1, #header h2, #header h3{ - padding: 0px; - margin: 0px; -} - -/* Top Navigation */ -#header .globalNav{ - color: #00355C; - white-space: nowrap; - padding: 11px 0px; -} -/* 'nowrap' prevents links from line-wrapping if there are too many to fit in one line - this will force a horizontal scrollbar if there isn't enough room for all links - remove rule or change value to 'normal' if you want the links to line-wrap */ - -#header .globalNav img{ - /* display: block; */ -} - -/* Top header */ -#header .globalNav .cat-button, #header .globalNav .cat-button-current{ - white-space: nowrap; - padding: 3px 3px; -} - -#header .globalNav .cat-button{ - /*background-color: #00355C;*/ - /*border-bottom: 1px solid #f0f0f0;*/ -} - -#header .globalNav .cat-button a{ - color:#f0f0f0; -} - -#header .globalNav .cat-button-current{ - /*background-color: #f0f0f0;*/ - /*border-bottom: 1px solid #f0f0f0;*/ -} - -#header .globalNav .cat-button-current a{ - color:#b0b0b0; -} - -#header .globalNav .cat-button a, #header .globalNav .cat-button-current a { - font-size:11px; font-style:normal; font-weight:bold; text-decoration:none; text-transform:uppercase; -} +/* + The original "prosilver" theme for phpBB3 + Created by subBlue design :: http://www.subBlue.com +*/ -#header .globalNav .cat-button a:hover, #header .globalNav .cat-button-current a:hover { +* { margin: 0; padding: 0; } -} +html { font-size: 100%; height: 100%; margin-bottom: 1px; } -/* Lower header */ -#header .globalNav .nav-button, #header .globalNav .nav-button-current{ - padding: 3px 3px; +body { + font-family: Verdana, Helvetica, Arial, sans-serif; + color: #828282; + background-color: #FFFFFF; + font-size: 12px; + margin: 0; + padding: 12px 0; } -#header .globalNav .nav-button{ - /*background-color: #00355C;*/ -} +img { border-width: 0; } -#header .globalNav .nav-button a{ - color:#f0f0f0; +p { + line-height: 1.3em; + font-size: 1.1em; + margin-bottom: 1.5em; } -#header .globalNav .nav-button-current{ - /*background-color: #00355C;*/ +hr { + border: 0 none #FFFFFF; + border-top: 1px solid #CCCCCC; + height: 1px; + margin: 5px 0; + display: block; + clear: both; } -#header .globalNav .nav-button-current a{ - color:#cccccc; +html, body { + color: #536482; + background-color: #FFFFFF; } -#header .globalNav .nav-button a, #header .globalNav .nav-button-current a { - font-size:10px; font-style:normal; font-weight:bold; text-decoration:none; text-transform:uppercase; +#doc-description h1 { + font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; + margin-right: 200px; + color: #FFFFFF; + margin-top: 15px; + font-weight: bold; + font-size: 2em; + color: #fff; } -#header .globalNav .nav-button a:hover, #header .globalNav .nav-button-current a:hover { - +h1 { + font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; + font-weight: normal; + color: #000; + font-size: 2em; + margin: 0.8em 0 0.2em 0; } -#subheader{ - /*background: transparent url('/templates/mxp/images/theme/leftcol.gif') repeat-y;*/ - margin: 0px; - padding: 0px 10px 9px 10px; - font-size:10px; font-style:normal; font-weight:bold; text-decoration:none; color:#215A19; +h2 { + font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; + font-weight: normal; + color: #28313F; + font-size: 1.5em; + margin: 0.8em 0 0.2em 0; } -#subheader a { - font-size:10px; font-style:normal; font-weight:bold; text-decoration:none; color:#215A19; +h3 { + font-family: Arial, Helvetica, sans-serif; + font-weight: bold; + border-bottom: 1px solid #CCCCCC; + margin-bottom: 3px; + padding-bottom: 2px; + font-size: 1.05em; + color: #115098; + margin-top: 20px; } -#subheader a:hover { - text-decoration:underline; - font-size:10px; font-style:normal; font-weight:bold; text-decoration:none; color:#999999; +h4 { + font-family: Arial, Helvetica, sans-serif; + font-weight: bold; + margin-bottom: 3px; + padding-bottom: 2px; + font-size: 1.05em; + color: #115098; + margin-top: 20px; } -#subheader .left .menu-button-current a{ - color:#999999; +h5 { + font-family: Arial, Helvetica, sans-serif; + font-weight: bold; + margin-bottom: 3px; + padding-bottom: 2px; + font-size: 1.05em; + color: #ec0409; + margin-top: 20px; } -#subheader .left{ - text-align: left; - float:right; - - padding: 5px 5px 2px 20px; - border-right: 1px solid #CFD5CF; - border-bottom: 1px solid #CFD5CF; -} +.good { color: green; } +.bad { color: red; } -#subheader .right{ +.version { + margin-top: 20px; text-align: left; - - padding: 5px 5px 3px 5px; + font-size: 70%; + color: #006600; + border-top: 1px solid #ccc; } -/* Block title */ -div.blockheader{ - margin: 0px; - padding: 2px 5px; - - /* background: url(/templates/mxp/images/cornerr.gif) top right no-repeat; */ +code { + color: #006600; + font-weight: normal; + font-family: 'Courier New', monospace; + border-color: #D1D7DC; + border-width: 1px; + border-style: solid; + background-color: #FAFAFA; } -#leftcol div.blockheader{ - /* - border-top: 1px solid #215A19; - border-right: 1px solid #215A19; - border-bottom: 0px solid #215A19; - border-left: 1px solid #215A19; - */ - - color: #333; - /* background-color: #215A19; */ - background: transparent url('images/theme/blockheader.gif') no-repeat; - - padding: 6px 5px; +#wrap { + padding: 0 20px; + min-width: 650px; } -#middlecol div.blockheader{ - +#simple-wrap { + padding: 6px 10px; } -#rightcol div.blockheader{ - +#page-body { + margin: 4px 0; + clear: both; } -div.blockheader .blockhidden{ - float: right; - margin: 0px; - padding: 0px; +#page-footer { + clear: both; } -div.blockheader .editCP_switch{ - float: right; - margin: 0px; - padding: 0px; +#logo { + float: left; + width: auto; + padding: 10px 13px 0 10px; } -div.blockheader .editCP_switch .trimform { - margin: 0px; - padding: 0px; +a#logo:hover { + text-decoration: none; } -div.block{ - margin: 0px; - padding: 0px; +#doc-description { + float: left; + width: 70%; } -#leftcol div.block{ - border-top: 1px solid #215A19; - border-right: 1px solid #215A19; - border-bottom: 1px solid #215A19; - border-left: 1px solid #215A19; - - background-color: #ffffff; - - padding: 5px; +#doc-description h1 { + margin-right: 0; } -#middlecol div.block{ - /* - border-top: 1px solid #B0B0B0; - border-right: 1px solid #B0B0B0; - border-bottom: 1px solid #B0B0B0; - border-left: 1px solid #B0B0B0; - - background-color: #ffffff; - */ - - padding: 5px; +.headerbar { + background: #ebebeb none repeat-x 0 0; + color: #FFFFFF; + margin-bottom: 4px; + padding: 0 5px; } -#rightcol div.block{ - +span.corners-top, span.corners-bottom, span.corners-top span, span.corners-bottom span { + font-size: 1px; + line-height: 1px; + display: block; + height: 5px; + background-repeat: no-repeat; } -#footer{ - clear: both; - margin: 5px 0px; - padding: 2px 5px; - color: #333; - background-color: #326030; - border: 1px solid #000; - font-size: 9px; +span.corners-top { + background-image: none; + background-position: 0 0; + margin: 0 -5px; } -#footer .globalNav{ - text-align: center; - color: #cccccc; - white-space: nowrap; +span.corners-top span { + background-image: none; + background-position: 100% 0; } -/* 'nowrap' prevents links from line-wrapping if there are too many to fit in one line - this will force a horizontal scrollbar if there isn't enough room for all links - remove rule or change value to 'normal' if you want the links to line-wrap */ - -#footer .globalNav a { - padding: 0px 4px 0px 0px; +span.corners-bottom { + background-image: none; + background-position: 0 100%; + margin: 0 -5px; + clear: both; } -#footer a, #footer a:link, #footer a:visited { text-decoration: none; color: #CFD7D1; font-weight: bold;} -#footer a:hover{ text-decoration: underline; color: #CFD7D1; font-weight: bold;} - -#footer a.copyright, #footer a.copyright:link, #footer a.copyright:visited { text-decoration: none; color: #CFD7D1; font-weight: normal;} -#footer a.copyright:hover{ text-decoration: underline; color: #CFD7D1; font-weight: normal;} - -#footer p { margin: 0px 0px 1em 0px; } - -.pageStats { - padding: 0px 10px 5px 0px; +span.corners-bottom span { + background-image: none; + background-position: 100% 100%; } -* html x { /* This is the Tan hack */ - width: 130px; /* For IE5 */ - w\idth: 100px; } /* For IE6 */ - -#clear { clear: both; } - -/***********************************************/ -/* Theme */ -/***********************************************/ -/* General text */ -font,th,td,p { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; } -#leftcol font, #leftcol th, #leftcol td, #leftcol p { color: #000000; } -#middlecol font, #middlecol th, #middlecol td, #middlecol p { color: #000000; } -#rightcol font, #rightcol th, #rightcol td, #rightcol p { color: #000000; } - -.gen,.genmed,.gensmall { color : #000000; } -a,a.gen,a.genmed,a.gensmall { color: #326030; text-decoration: none; } -a:hover,a.gen:hover,a.genmed:hover,a.gensmall:hover { color: #DD6900; text-decoration: underline; } - -tr.oddrow a, tr.oddrow a.gen,tr.oddrow a.genmed, tr.oddrow a.gensmall { font-size:10px; color: #ffffff; text-decoration: none; } -tr.oddrow a:hover, tr.oddrow a.gen:hover,tr.oddrow a.genmed:hover,tr.oddrow a.gensmall:hover { color: #215A19; text-decoration: underline; } - -/* -#leftcol .gen, #leftcol .genmed, #leftcol .gensmall { color : #000000; } -#leftcol a.gen, #leftcol a.genmed, #leftcol a.gensmall { color: #326030; text-decoration: none; } -#leftcol a.gen:hover, #leftcol a.genmed:hover, #leftcol a.gensmall:hover { color: #DD6900; text-decoration: underline; } - -#middlecol .gen, #middlecol .genmed, #middlecol .gensmall { color : #000000; } -#middlecol a.gen, #middlecol a.genmed, #middlecol a.gensmall { color: #326030; text-decoration: none; } -#middlecol a.gen:hover, #middlecol a.genmed:hover, #middlecol a.gensmall:hover { color: #DD6900; text-decoration: underline; } - -#rightcol .gen, #rightcol .genmed, #rightcol .gensmall { color : #000000; } -#rightcol a.gen, #rightcol a.genmed, #rightcol a.gensmall { color: #326030; text-decoration: none; } -#rightcol a.gen:hover, #rightcol a.genmed:hover, #rightcol a.gensmall:hover { color: #DD6900; text-decoration: underline; } -*/ - -.gen { font-size : 11px; } -.genmed { font-size : 10px; } -.gensmall { font-size : 9px; } - -/* This is the outline round the main forum tables */ -.forumline { text-align: left; } - -/* Main table cell colours and backgrounds */ -td.row1 { } -td.row2 { background-color: #f0f0f0; } -td.row3 { background-color: #f0f0f0; } - -td.oddcell { background-color: #f0f0f0; } -tr.oddrow { background-color: #f0f0f0; } - -/* -#leftcol td.row1 { background-color: #EFEFEF; } -#leftcol td.row2 { background-color: #DEE3E7; } -#leftcol td.row3 { background-color: #D1D7DC; } - -#middlecol td.row1 { background-color: #EFEFEF; } -#middlecol td.row2 { background-color: #DEE3E7; } -#middlecol td.row3 { background-color: #D1D7DC; } - -#rightcol td.row1 { background-color: #EFEFEF; } -#rightcol td.row2 { background-color: #DEE3E7; } -#rightcol td.row3 { background-color: #D1D7DC; } -*/ - -#middlecol div.block img { margin: 4px 10px 4px 4px; } -#middlecol div.block .DynamicTree img { margin: 0px; } /* SimpleDoc Fix */ -#middlecol div.block .wrap2 img { margin: 0px; } /* tinyMCE Fix */ -.ImageFrame_image { margin: 0px; padding: 0px; } /* Gallery Fix */ -#middlecol div.block img.ImageFrame_image { margin: 0px; padding: 0px; } /* Gallery Fix */ - -div.block p { margin: 0.7em 0px 0.7em 0px; } - -div.block h1 { margin: .2em 0px .5em 0px; } -div.block h2 { margin: 1.5em 0px .5em 0px; } -div.block h3, div.block h4 { margin: 1.5em 0px .4em 0px; } - -h1 { font-family: Geneva, Arial, Helvetica, san-serif; font-size: 13px; font-weight: bold; color: #215A19; letter-spacing: 2px; } -h2 { font-family: Geneva, Arial, Helvetica, san-serif; font-size: 12px; font-weight: bold; color: #215A19; letter-spacing: 2px; } -h3 { font-family: Geneva, Arial, Helvetica, san-serif; font-size: 11px; font-weight: bold; font-variant: normal; color: #003300; text-transform: uppercase; } -h4 { font-size: 10px; font-variant: normal; color: #006600; text-transform: uppercase; line-height: 5px;} - -/* Block titles */ -.blocktitle { font-family: Verdana, Arial, Helvetica, sans-serif;font-weight: bold; font-size: 11px ; letter-spacing: 1px;} -a.blocktitle { text-decoration: none;} -a.blocktitle:hover{ text-decoration: underline;} - -/* Discreet text */ -.discreet { font-size : 9px; color : #879C6C } - -#leftcol .blocktitle, #leftcol a.blocktitle { color : #ffffff;} -#middlecol .blocktitle, #middlecol a.blocktitle { color : #326030;} -#rightcol .blocktitle, #rightcol a.blocktitle { color : #326030;} - -/* The register, login, search etc links at the top of the page */ -.mainmenu { font-size : 11px; color : #000000 } -a.mainmenu { text-decoration: none; color : #326030; } -a.mainmenu:hover{ text-decoration: underline; color : #DD6900; } - -/* Forum category titles */ -.cattitle { font-weight: bold; font-size: 12px ; letter-spacing: 1px; color : #326030} -a.cattitle { text-decoration: none; color : #215A19; } -a.cattitle:hover{ text-decoration: underline; } - -/* Forum title: Text and link to the forums used in: index.php */ -.forumlink { font-weight: bold; font-size: 12px; color : #215A19; } -a.forumlink { text-decoration: none; color : #215A19; } -a.forumlink:hover{ text-decoration: underline; color : #DD6900; } - -/* Used for the navigation text, (Page 1,2,3 etc) and the navigation bar when in a forum */ -.nav { font-weight: bold; font-size: 11px; color : #000000;} -a.nav { text-decoration: none; color : #215A19; } -a.nav:hover { text-decoration: underline; } - -/* titles for the topics: could specify viewed link colour too */ -.topictitle { font-weight: bold; font-size: 11px; color : #000000; } -a.topictitle:link { text-decoration: none; color : #215A19; } -a.topictitle:visited { text-decoration: none; color : #215A19; } -a.topictitle:hover { text-decoration: underline; color : #444444; } - -/* Name of poster in viewmsg.php and viewtopic.php and other places */ -.name { font-size : 11px; color : #000000;} - -/* Location, number of posts, post date etc */ -.postdetails { font-size : 10px; color : #000000; } - -/* The content of the posts (body of text) */ -.postbody { font-size : 10px;} -a.postlink:link { text-decoration: none; color : #326030 } -a.postlink:visited { text-decoration: none; color : #5493B4; } -a.postlink:hover { text-decoration: underline; color : #DD6900} - -/* Quote & Code blocks */ -.code { - font-family: Courier, 'Courier New', sans-serif; font-size: 10px; color: #006600; - background-color: #FAFAFA; border: #D1D7DC; border-style: solid; - border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px -} - -.code { - display: block; - padding: 5px; - margin: 5px 15px; +.paragraph { + padding: 0 10px; + margin-bottom: 4px; + background-repeat: no-repeat; + background-position: 100% 0; + background-color: #ECF3F7; } -.quote { - font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #444444; line-height: 125%; - background-color: #FAFAFA; border: #D1D7DC; border-style: solid; - border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px +.paragraph:target .content { + color: #000000; } -.quote { - display: block; - padding: 5px; - margin: 5px 15px; +.paragraph:target h3 a { + color: #000000; } -/* Copyright and bottom info */ -.copyright { font-size: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; color: #444444; letter-spacing: -1px;} -a.copyright { color: #444444; text-decoration: none;} -a.copyright:hover { color: #000000; text-decoration: underline;} - -/* Form elements */ -input,textarea, select { - color : #000000; - font: normal 10px Verdana, Arial, Helvetica, sans-serif; - border-color : #000000; +.content { + color: #333333; } -/* The text input fields background colour */ -input.post, textarea.post, select { - background-color : #FFFFFF; +.content h2, .panel h2 { + color: #115098; + border-bottom-color: #CCCCCC; } -input { text-indent : 2px; } +a:link { color: #898989; text-decoration: none; } +a:visited { color: #898989; text-decoration: none; } +a:hover { color: #d3d3d3; text-decoration: underline; } +a:active { color: #d2d2d2; text-decoration: none; } -/* The buttons used for bbCode styling in message post */ -input.button { - background-color : #EFEFEF; - color : #000000; - font-size: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; +hr { + border-color: #FFFFFF; + border-top-color: #CCCCCC; } -/* The main submit button option */ -input.mainoption { - background-color : #FAFAFA; - font-weight : bold; +.menu { + background-color: #cadceb; } -/* None-bold submit button */ -input.liteoption { - background-color : #FAFAFA; - font-weight : normal; -} - -/* This is the line in the posting page which shows the rollover - help line. This is actually a text box, but if set to be the same - colour as the background no one will know ;) -*/ -.helpline { background-color: #DEE3E7; border-style: none; } - -/* Import the fancy styles for IE only (NS4.x doesn't use the @import function) */ -/* @import url("formIE.css"); */ - -/* Fancy form styles for IE */ - -input, textarea, select { - border-top-width : 1px; - border-right-width : 1px; - border-bottom-width : 1px; - border-left-width : 1px; +.headerbar { + background-color: #12A3EB; + background-image: url("bg_header.gif"); + color: #FFFFFF; } -input { text-indent : 2px; } - -input.button { - border-top-width : 1px; - border-right-width : 1px; - border-bottom-width : 1px; - border-left-width : 1px; +.panel { + background-color: #ECF1F3; + color: #28313F; } -.postbody { line-height: 18px} -/* Form elements */ -form { - margin: 0px; +span.corners-top { + background-image: url("corners_left.png"); } -/* Form elements */ -form.mx_editform { - margin-bottom: 0px; - margin-top: 0px; +span.corners-top span { + background-image: url("corners_right.png"); } -/* This is the border around numbers in pagination */ -.mx_pagination, .mx_pagination_sele, .mx_pagination_over { - padding-left: 2px; - padding-right: 2px; - border-top: 1px solid #B0B0B0; - border-right: 1px solid #B0B0B0; - border-bottom: 1px solid #B0B0B0; - border-left: 1px solid #B0B0B0; - text-decoration: none; +span.corners-bottom { + background-image: url("corners_left.png"); } -.mx_pagination_sele { - background-color: #E0E0E0; -} -.mx_pagination_over { - background-color: #F0F0F0; +span.corners-bottom span { + background-image: url("corners_right.png"); } -.shadow { - color: #00AA00; - filter: DropShadow(Color=#660000, OffX=5, OffY=5, Positive=1); -} -img.shadow { - color: #00AA00; - filter:progid:DXImageTransform.Microsoft.dropshadow(OffX=5, OffY=5, Color='gray', Positive='true'); +.error { + color: #BC2A4D; } -/* This is the style used for the top page title. */ -.pagetitle { - font-weight: bold; - font-size: 30px; - font-family: "Comic Sans MS", Verdana, Arial, Helvetica, sans-serif; - text-decoration: none; - line-height : 120%; - color : #000066; - font-variant: small-caps; - text-transform: capitalize; - letter-spacing: 5px; - vertical-align: 20%; -} +a:link { color: #105289; } +a:visited { color: #105289; } +a:hover { color: #D31141; } +a:active { color: #368AD2; } -/* This is the style used for the top site title. */ -.sitetitle { - font-family: Arial; - font-variant: small-caps; - font-weight: bolder; - font-size: 12pt; - color: #000066; +.paragraph span.corners-top, .paragraph span.corners-bottom { + margin: 0 -10px; } -/* This is the style used for the top site description. */ -.sitetitle_desc { - color: #326030; - font-size: 9px; +.content { + padding: 0; + line-height: 1.48em; + color: #333333; } -/* Block Navigation */ -#leftcol ul { - border: 1px solid #fff; - border-width: 0px 1px; - font-size: 11px; - /* font-size: 85%; */ - list-style: none; - margin: 3px 0px 3px 0px; - padding: 0px; +.content h2, .panel h2 { + color: #115098; + border-bottom-color: #CCCCCC; } -#leftcol ul li { - border-bottom: 1px solid #fff; +.notice { + border-top-color: #CCCCCC; } -#leftcol ul a { - /* background: #ffffff url(/modules/mx_navmenu/templates/samSkolan3/images/arrow_right.gif) 5px 50% no-repeat; */ - background: #ffffff; - border: none; - color: #215A19; +.codebox { + padding: 3px; + background-color: #FFFFFF; + border: 1px solid #C9D2D8; + font-size: 1em; + margin-bottom: 10px; display: block; - line-height: 1.4em; - /* padding-left: 20px; */ - padding-left: 5px; - text-decoration: none; - font-size: 11px; + font: 0.9em Monaco, "Andale Mono","Courier New", Courier, mono; + line-height: 1.3em; } -#leftcol ul a:hover { - /* background: #efefef url(/modules/mx_navmenu/templates/samSkolan3/images/arrow_right.gif) 5px 50% no-repeat; */ - background: #efefef; - border: none; - color: #215A19; -} +* html hr { margin: 0; } +* html span.corners-top, * html span.corners-bottom { background-image: url("corners_left.gif"); } +* html span.corners-top span, * html span.corners-bottom span { background-image: url("corners_right.gif"); } -#leftcol li#cattitle a { - /* background: #ffffff url(/modules/mx_navmenu/templates/samSkolan3/images/arrow_right.gif) 5px 50% no-repeat; */ - background: #ffffff; - color: #215A19; - font-weight: bold; - font-variant: small-caps; -} - -#leftcol li#cat a { - /* background: #ffffff url(/modules/mx_navmenu/templates/samSkolan3/images/arrow_right.gif) 5px 50% no-repeat; */ - background: #326B2A; - color: #ffffff; - font-weight: bold; - font-variant: small-caps; -} - -/* -* -* Generic Button -* -*/ -a.genericbutton { - background: transparent url('images/buttons/createbutton_a.gif') no-repeat scroll top right; - color: #326030; - display: inline-block; - /*float: left;*/ - font: bold 10px arial, sans-serif; - height: 20px; - margin: 10px 6px 10px 0px; - padding-right: 14px; /* sliding doors padding */ - text-decoration: none; - vertical-align: middle; +.back2top { + clear: both; + height: 11px; + text-align: right; + color: #da343b; } -a.genericbutton span { - background: transparent url('images/buttons/createbutton_span.gif') no-repeat; - display: inline-block; - line-height: 12px; - padding: 4px 0 4px 14px; - cursor: pointer; +.content ol, .content ul { + margin-left: 25px; + margin-top: 0; } -/* ForeFox Fix */ -a.genericbutton, a.genericbutton span { - display:-moz-inline-stack; +.content ul + p, .content ul + div { + margin-top: 20px; } -/* Hover */ -a.genericbutton:hover { - background-position: bottom right; +.comment { + color: green; } -a.genericbutton:hover span { - background-position: bottom left; - color: #a51; +.indent { + margin-left: 20px; } -/* Click */ -a.genericbutton:active { - background-position: bottom right; - color: #000; - outline: none; /* hide dotted outline in Firefox */ +.paragraph table { + font-size: 8pt; + border-collapse: collapse; + border: 1px solid #cfcfcf; + margin-bottom: 20px; } -a.genericbutton:active span { - background-position: bottom left; +.paragraph table caption { + display: none; } -/* -* -* Image Button -* -*/ -a.imagebutton { - text-decoration: none; - vertical-align: middle; - display: inline-block; +.paragraph table thead { + background-color: #cadceb; + color: #000; } -a.imagebutton:hover { - text-decoration: none; - vertical-align: middle; - display: inline-block; - - filter:alpha(opacity=40); - opacity:0.4; +.paragraph table td, .paragraph table th { + border: 1px solid #006699; + padding: 0.5em; + background-color: #e1ebf2; } -/* ForeFox Fix */ -a.imagebutton{ - display:-moz-inline-stack; +.paragraph table th { + background-color: #cadceb; } -/* -* -* Text Button -* -*/ -a.textbutton { - text-decoration: none; - vertical-align: middle; - font-weight: bold; - - margin: 10px 6px 10px 0px; - border: 1px double #326030; - border-width: 3px 1px; +.paragraph table td dl { + margin: 0; + padding: 0; } -a.textbutton:hover { - border: 1px double #326030; - border-width: 2px 1px; +.paragraph table td dl dt { + float: left; + clear: both; + margin-right: 1em; } - -a.textbutton:active { - border: 1px double #326030; - border-width: 2px 1px; -} \ No newline at end of file diff --git a/docs/site_logo.gif b/docs/site_logo.gif new file mode 100644 index 00000000..35e7c9bd Binary files /dev/null and b/docs/site_logo.gif differ diff --git a/includes/db/dbal.php b/includes/db/dbal.php index 887f59c7..646cbb1d 100644 --- a/includes/db/dbal.php +++ b/includes/db/dbal.php @@ -8,12 +8,10 @@ * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @link http://mxpcms.sourceforge.net/ * +* */ -if ( !defined('IN_PORTAL') ) -{ - die("Hacking attempt"); -} +if (!defined('IN_PORTAL')) { die("Hacking attempt"); } /** * @package DBal @@ -61,7 +59,97 @@ function dbal() $this->any_char = chr(0) . '%'; $this->one_char = chr(0) . '_'; } + + /** + * Gets the name of the sql layer. + * + * @return string + */ + public function get_sql_layer() + { + return $this->sql_layer; + } + /** + * Gets the name of the database. + * + * @return string + */ + public function get_db_name() + { + return $this->dbname; + } + + /** + * Wildcards for matching any (%) character within LIKE expressions + * + * @return string + */ + public function get_any_char() + { + return $this->any_char; + } + + /** + * Wildcards for matching exactly one (_) character within LIKE expressions + * + * @return string + */ + public function get_one_char() + { + return $this->one_char; + } + + /** + * {@inheritdoc} + */ + public function get_db_connect_id() + { + return $this->db_connect_id; + } + + /** + * {@inheritdoc} + */ + public function get_sql_error_triggered() + { + return $this->sql_error_triggered; + } + + /** + * {@inheritdoc} + */ + public function get_sql_error_sql() + { + return $this->sql_error_sql; + } + + /** + * {@inheritdoc} + */ + public function get_transaction() + { + return $this->transaction; + } + + /** + * Gets the time spent into the queries + * + * @return int + */ + public function get_sql_time() + { + return $this->sql_time; + } + + /** + * {@inheritdoc} + */ + public function get_sql_error_returned() + { + return $this->sql_error_returned; + } + /** * return on error or display error message */ diff --git a/includes/hooks/hook_fb4phpbb_light.php b/includes/hooks/hook_fb4phpbb_light.php new file mode 100644 index 00000000..42365219 --- /dev/null +++ b/includes/hooks/hook_fb4phpbb_light.php @@ -0,0 +1,51 @@ +assign_vars(array( + 'HAS_JQUERY' => find_jquery(), + 'HAS_JQUERY_UI' => find_jquery_ui(), + 'FB4PHPBB_LIGHT_XMLNS' => 'xmlns:fb="http://ogp.me/ns/fb#"', + 'FB4PHPBB_LIGHT_INIT' => fb4phpbb_light_init($config['fb4phpbb_light_appid'], $config['fb4phpbb_light_lang']), + 'S_FB4PHPBB_MOD_ENABLED' => ($config['fb4phpbb_light_mod_enabled'] == 'yes') ? true : false, + 'FB4PHPBB_LIGHT_CONNECT' => generate_board_url() . '/fb4phpbb_light/fb4phpbb_light_connect.' . $phpEx, + )); + } +} + +if (!$config['board_disable']) +{ + $phpbb_hook->register(array('template','display'), 'facebook_for_phpbb_light_template_hook'); +} diff --git a/includes/mx_functions.php b/includes/mx_functions.php index 46b5cfbd..8314ef59 100644 --- a/includes/mx_functions.php +++ b/includes/mx_functions.php @@ -59,7 +59,6 @@ function mx_message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = // //This will check whaever we are installing // - if(defined('HAS_DIED')) { // @@ -74,7 +73,7 @@ function mx_message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = else { $custom_error_message = sprintf($custom_error_message, '', ''); - } + } echo "\n\n\nCritical Error!++ + + + ++ + + + + + + + +Please read through this document completely before you proceed to installation or upgrade.
+This document will walk you through the basics on installation & updgrading the MXP CMS software.
+ +Install
+ + + +1. Requirements
+++ ++++ ++MXP as a CMS tool does have some requirements which must be met before you are able to start your installation.
+ ++
+ +- A webserver or web hosting account running on any major Operating System with support for PHP.
+- mySQL3 or postgreSQL 7.1 Database (Latest mySQL4 or postgreSQL version recommended)
+- PHP 5.1.2 and later versions.
+- phpBB 2.0.x (Latest phpBB2 recommended) (Required in MX-Publisher 2.8.x. Optional in MX-Publisher 3.0.x)
+- phpBB 3.0.x (Latest phpBB3/Olympus recommended) (Optional in MX-Publisher 3.0.x)
+
+- The following are optional items you may require depending on your local machines setup and/or your server or web-hosts control panel support and features. +
++
+- FTP Program
+- HTML Editor
+
+ +2. Uploading the MXP Core
+++ ++++ ++As a rule without exception MXP and phpBB must be installed in different directories. Do not mix the files up!! If phpBB is not installed on your system, please visit www.phpBB.com for further instructions. When uploading the default directory structure which will cause you the least effort and quickest installation is as follows:
+ ++ +
/your/path/to/public/html/YOUR_PORTAL_NAME/
(this is the place were all MXP files should be located)
+/your/path/to/public/html/YOUR_FORUM_NAME/
(this is the place where your working phpBB installation should be located)You can alternatively install MX-Publisher in your root directory (which can be accessed via http://www.yourdomain.com/ while your forum can be installed in a folder along with the MXP folders (ie it'd be located in
+ +http://www.yourdomain.com/phpBB2/
Using the default setup above, the install path variables should be: phpBB Relative Path: ../YOUR_FORUM_NAME/
+ +Note #1
If you move the phpBB folder into another one before installing MXP, the phpBB configuration (the
+ +/phpbbroot/config.php
file) must also be modified to match the new phpB location.Note #2
The MXP and phpBB installations use completely differing config.php files. Do not confuse them and mix them together! They are two different files.
+ +Note #3
If you plan to switch to phpBB mode later (after a fresh standalone installation) you have to set the phpBB relative path manually in the MXP Admin Control Panel. + +
Unzip the distributed MXP files and upload
+ +SPECIAL NOTE
MX-Publisher needs write access/permissions to the cache folder and the mx_meta.inc file. + +## CHMOD (0777) THE FOLLOWING FILES/DIRECTORIES:
+ +## - mxroot/cache/
## - mxroot/mx_meta.inc
For those with Windows servers, CHMOD 0777 gives read, write, and access permissions to all 3 auth types (commonly Owner, Group, and Other/Anonymous). You'll have to give the files/folders above these permissions; this depends from host to host, though usually you can do it via your hosting control panel (cPanel, DirectAdmin, etc.) +
+ +3. New installation
+++ ++++ ++In your browser, call
+ +http://www.yourdomain.com/mxproot/install/mx_install.php
Replace "mxproot" with whatever name you had for your MXP folder, which contains all of the MXP files and folders. You will now be presented with an installation page showing you some options, the first of which is the choice of MXP installtion, of which there are a possible 3 seperate types of install which you can choose from, lets take a look at these below:MXP - standalone (INTERNAL)
+This option will allow you to get your MXP install up and running without any need of 3rd party software - usually phpBB forum - it'll get your demo default website up and running quickly without the forum part. At a later stage you can still choose from with the Admin Control Panel to select a type of phpBB forum software which you have installed - of which MXP supports two types; phpBB 2 and phpBB 3.
+MXP - With phpBB2 / phpBB3
+With the installer, all of the values should already be filled in, and you should be set up to go and click "Install." However, you should go over the information filled in. If you definitely need something changed, then go ahead and see this document for details on how to set the installer to allow you to enter your own settings. Note that you should only do this if you know what you are doing. + +
You then need to fill out the installation configuration form which consists of the following:
+ +MX-Publisher Prefix in DB (default: mx_)
+This is the prefix name for the database - so when you browse through phpmyadmin you'll see it more clearly plus it prevents table mixups between other things in your database (such as phpBB) which has a database prefix of phpbb_. Also you may want to change this if you want several instances of MXP present within the same database; for example mx2_ - this is not something highly recommended due to export and backup functions, extraction of data however.
+Database Type (default: mySQL)
+You wont have to change this option.
+Database Server Hostname/DSN
+The default: localhost is normally all that is required if you need to fill this in.
+Your Database Name
+This will be either the database which phpBB already uses or if you are planning on an enttirely internal (standalone) install you'll need to create a new one with your prefered db management tool. Sometimes the database name here requries a prefix of the domain name - which for example might be
+www.testsite.com
with a database nameddata1
; so the database name entry here would be testsite_data1.Database Username
+You need to enter the database username which was auto-created when your database was created OR create a db user, with appropriate db permissions. Again this may require the website name as a prefix to the username.
+Database Password
+The password unlike the two previous entries which required your website as a prefix before either the database name or the database username DOES NOT need a prefix before it - enter this as per the normal password of the database user. +
MXP Admin Username
+You may or may not want to consider keeping this the same as your phpBB forum install credentials for simplicity and to avoid confusion when switching around your website.
+MXP Admin Password
+Again - you may or may not want to consider keeping this the same as your phpBB forum install credentials for simplicity and to avoid confusion when switching around your website.
+Re-enter MXP Admin Password
+Repeat the password you have just entered.
+ +Now That you have the correct information present you can click the Install button to continue, at this stage you'll be told you can download the config.php for you to upload directly to your sever into the MXP directory so this is your next step - click the button to download the config.php file and place it on your server.
+You can now REFRESH the page and this will start the installation wizard placing entries into the database - the page will scroll showing you this, when finished you'll be presented with some instructions at the bottom fo the page.
+These will tell you that you need to now delete two directories on your server:
+ +/contrib/
and/install/
once done you can then login to your brand new MXP installation.
+ +4. Advanced Installation
+++ + +++++To choose your own configuration instead of the installer's default suggestions, open up the mx_install.php file in your favorite PHP or text editor and perform the following code changes to the file.
+Find
define('INSTALL_READONLY', true);
+Replace With:
// define('INSTALL_READONLY', true);
+ +The purpsoe of this is to 'comment out' the code line - meaning that it will stop working and in turn allow you to set up your own configuration. + +
Note
+The install script creates the MX-Publisher config.php file. If for some reason the install fails, you may need to remove the generated config.php manually before retrying the install. Also, if you feel like doing a fresh reinstallation, you will need to remove the previous MX-Publisher config.php file.
+Failure to do this action will result in a failure to install MXP and your install script will not update correctly.
+ +Also, some webservers deny the installer the rights to edit theconfig.php
file. In this case you'll need to CHMOD the config.php file to 0777. (CHMOD is overviewed above). If you have any other errors regarding config.php (you shouldn't), go here. + +2) Don't forget to remove the install/ and contrib/ folders after a successful installation! Otherwise, this could mean a potential security hole. +3) Installation Complete! Now enter the MX-Publisher AdminCP and configure the portal. The user interface is intuitive. For further information, visit some of our documents and Knowledge Base articles on ours DOCS page at www.mx-publisher.com. +
+5. Upgrading the MXP Core
+ +++ + ++ +++ ++Upgrading your installation is only a matter of a few steps to take and simple awareness of one or two facts.
+ ++
+ +- Download the full package from the Downloads Page at www.mx-publisher.com.
+- Unzip/unrar the contents - making sure the directory integrity remains intact.
+- Open your FTP client and connect to your MXP directory
+- Upload all files and folders except for config.php.
+- Now visit the
+mx_install.php
.
+- This will start the install wizard for your upgrade - follow all the steps then click Finish.
+- Remove the
/install/
and/contrib/
directories and you are free to login to your new portal. +Do not forget to also upgrade all the modules to make sure you have full MXP compatibility.
+6. Confirmation
+ +++ + ++ +++ ++After successful installation of the MXP db tables, you'll be forwarded to the confirmation page, from where you are directed to the MXP Administration Control Panel, to finalize the installation, eg
++
+- define board timezone and other localized settings
+- configure the server mail SMTP
+Further, in the MXP Administration Control Panel, additional modules can be installed.
+ +
+7. Copyright and Disclaimer
+ +++ + + + + + ++ ++++This CMS tool is opensource software released under the GPL. Please see source code and the docs directory for more details. MXP and its contents are Copyright (c) 2001 - 2008 MXP Homepage, All Rights Reserved.
+Install Version: 1.0
+ + +
+
\nmx_message_die() was called multiple times.
"; for( $i = 0; $i < count($msg_history); $i++ ) { @@ -94,6 +93,10 @@ function mx_message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = } echo "
\n"; } + if (version_compare(PHP_VERSION, '5.4') < 0) + { + echo('You are running an unsupported PHP version: ' . PHP_VERSION . '. Please upgrade to PHP 5.6.4 or higher before trying to install phpBB3 or install / upgrate MX-Publisher 3
'); + } echo $custom_error_message . '
'; die("\n"); } @@ -189,7 +192,7 @@ function mx_message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = if ( empty($default_lang) ) { // - populate $default_lang - $default_lang= 'english'; + $default_lang = 'english'; } $lang_path = $mx_root_path . 'includes/shared/phpbb2/language/'; @@ -230,11 +233,11 @@ function mx_message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = // if ( !defined('IN_ADMIN') ) { - include($mx_root_path . 'includes/page_header.'.$phpEx); + include_once($mx_root_path . 'includes/page_header.'.$phpEx); } else { - include($mx_root_path . 'admin/page_header_admin.'.$phpEx); + include_once($mx_root_path . 'admin/page_header_admin.'.$phpEx); } } @@ -245,14 +248,14 @@ function mx_message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = { $msg_title = $lang['Information']; } - break; + break; case CRITICAL_MESSAGE: if ( $msg_title == '' ) { $msg_title = $lang['Critical_Information']; } - break; + break; case GENERAL_ERROR: if ( $msg_text == '' ) @@ -264,7 +267,7 @@ function mx_message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = { $msg_title = $lang['General_Error']; } - break; + break; case CRITICAL_ERROR: // @@ -304,7 +307,7 @@ function mx_message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = { $msg_title = 'MX-Publisher : ' . $lang['Critical_Error'] . ''; } - break; + break; } @@ -348,6 +351,7 @@ function mx_message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = { $template->set_filenames(array('message_body' => 'admin/admin_message_body.tpl')); } + // // Fix for correcting possible "bad" links to phpBB // @@ -662,6 +666,116 @@ function mx_redirect($url, $redirect_msg = '', $redirect_link = '') exit; } +// +// Encode the IP from decimals into hexademicals +// +function mx_encode_ip($dotquad_ip) +{ + $ip_sep = explode('.', $dotquad_ip); + return sprintf('%02x%02x%02x%02x', $ip_sep[0], $ip_sep[1], $ip_sep[2], $ip_sep[3]); +} + +// +// Decode the IP from hexademicals to decimals +// +function mx_decode_ip($int_ip) +{ + $hexipbang = explode('.', chunk_split($int_ip, 2, '.')); + return hexdec($hexipbang[0]). '.' . hexdec($hexipbang[1]) . '.' . hexdec($hexipbang[2]) . '.' . hexdec($hexipbang[3]); +} + +// +// Create date/time from format and timezone +// +function mx_create_date($format, $gmepoch, $tz) +{ + global $mx_user, $board_config, $lang; + + static $translate; + static $midnight; + static $date_cache; + + $format = (!$format) ? $mx_user->date_format : $format; + $now = time(); + $delta = $now - $gmepoch; + + if (!isset($date_cache[$format])) + { + // Is the user requesting a friendly date format (i.e. 'Today 12:42')? + $date_cache[$format] = array( + 'is_short' => strpos($format, '|'), + 'format_short' => substr($format, 0, strpos($format, '|')) . '||' . substr(strrchr($format, '|'), 1), + 'format_long' => str_replace('|', '', $format), + // Filter out values that are not strings (e.g. arrays) for strtr(). + 'lang' => array_filter($mx_user->lang['datetime'], 'is_string'), + ); + + // Short representation of month in format? Some languages use different terms for the long and short format of May + if ((strpos($format, '\M') === false && strpos($format, 'M') !== false) || (strpos($format, '\r') === false && strpos($format, 'r') !== false)) + { + $date_cache[$format]['lang']['May'] = $mx_user->lang['datetime']['May_short']; + } + } + + // Zone offset + $zone_offset = $mx_user->timezone + $mx_user->dst; + + // Show date <= 1 hour ago as 'xx min ago' but not greater than 60 seconds in the future + // A small tolerence is given for times in the future but in the same minute are displayed as '< than a minute ago' + if ($delta <= 3600 && $delta > -60 && ($delta >= -5 || (($now / 60) % 60) == (($gmepoch / 60) % 60)) && $date_cache[$format]['is_short'] !== false && !$forcedate && isset($this->lang['datetime']['AGO'])) + { + return $this->lang(array('datetime', 'AGO'), max(0, (int) floor($delta / 60))); + } + + if (!$midnight) + { + list($d, $m, $y) = explode(' ', gmdate('j n Y', time() + $zone_offset)); + $midnight = gmmktime(0, 0, 0, $m, $d, $y) - $zone_offset; + } + + if ($date_cache[$format]['is_short'] !== false && !$forcedate && !($gmepoch < $midnight - 86400 || $gmepoch > $midnight + 172800)) + { + $day = false; + + if ($gmepoch > $midnight + 86400) + { + $day = 'TOMORROW'; + } + else if ($gmepoch > $midnight) + { + $day = 'TODAY'; + } + else if ($gmepoch > $midnight - 86400) + { + $day = 'YESTERDAY'; + } + + if ($day !== false) + { + return str_replace('||', $mx_user->lang['datetime'][$day], strtr(@gmdate($date_cache[$format]['format_short'], $gmepoch + $zone_offset), $date_cache[$format]['lang'])); + } + } + + if (empty($translate) && $board_config['default_lang'] != 'english') + { + @reset($lang['datetime']); + while (list($match, $replace) = @each($lang['datetime'])) + { + $translate[$match] = $replace; + } + } + + if (empty($translate)) + { + @reset($lang['datetime']); + while (list($match, $replace) = @each($lang['datetime'])) + { + $translate[$match] = $replace; + } + } + return (!is_array($translate)) ? strtr(@gmdate($format, $gmepoch + (3600 * $tz)), $translate) : strtr(@gmdate($format, $gmepoch + (3600 * $tz)), $date_cache[$format]['lang']); +} + /** * Global function for chmodding directories and files for internal use * @@ -685,7 +799,7 @@ function mx_redirect($url, $redirect_msg = '', $redirect_link = '') * @return bool true on success, otherwise false * @author faw, phpBB Group */ -function mx_chmod($filename, $perms = CHMOD_READ) +function mx3_chmod($filename, $perms = CHMOD_READ) { static $_chmod_info; @@ -892,7 +1006,7 @@ function mx_is_writable($file) } /** -* Generate portal url (example: http://www.example.com/phpBB) +* Generate portal url (example: http://www.example.com/) * @param bool $without_script_path if set to true the script path gets not appended (example: http://www.example.com) */ function generate_portal_url($without_script_path = false) @@ -928,7 +1042,7 @@ function generate_portal_url($without_script_path = false) if ($server_port && (($cookie_secure && $server_port <> 443) || (!$cookie_secure && $server_port <> 80))) { - // HTTP HOST can carry a port number (we fetch $user->host, but for old versions this may be true) + // HTTP HOST can carry a port number (we fetch $mx_user->host, but for old versions this may be true) if (strpos($server_name, ':') === false) { $url .= ':' . $server_port; @@ -948,6 +1062,101 @@ function generate_portal_url($without_script_path = false) return $url; } +//Form validation + + +/** +* Add a secret hash for use in links/GET requests +* @param string $link_name The name of the link; has to match the name used in check_link_hash, otherwise no restrictions apply +* @return string the hash +unique_id() +*/ +function mx_generate_link_hash($link_name) +{ + global $mx_user; + + if (!isset($mx_user->data["hash_$link_name"])) + { + $mx_user->data["hash_$link_name"] = substr(sha1($mx_user->data['user_form_salt'] . $link_name), 0, 8); + } + + return $mx_user->data["hash_$link_name"]; +} + + +/** +* checks a link hash - for GET requests +* @param string $token the submitted token +* @param string $link_name The name of the link +* @return boolean true if all is fine +*/ +function mx_check_link_hash($token, $link_name) +{ + return $token === mx_generate_link_hash($link_name); +} + +/** +* Add a secret token to the form (requires the S_FORM_TOKEN template variable) +* @param string $form_name The name of the form; has to match the name used in check_form_key, otherwise no restrictions apply +* @param string $template_variable_suffix A string that is appended to the name of the template variable to which the form elements are assigned +*/ +function mx_add_form_key($form_name, $template_variable_suffix = '') +{ + global $board_config, $template, $mx_user; + + $now = time(); + $token_sid = ($mx_user->data['user_id'] == ANONYMOUS) ? $mx_user->session_id : ''; + $token = sha1($now . $mx_user->data['user_form_salt'] . $form_name . $token_sid); + + $s_fields = build_hidden_fields(array( + 'creation_time' => $now, + 'form_token' => $token, + )); + + $template->assign_var('S_FORM_TOKEN' . $template_variable_suffix, $s_fields); +} + +/** + * Check the form key. Required for all altering actions not secured by confirm_box + * + * @param string $form_name The name of the form; has to match the name used + * in add_form_key, otherwise no restrictions apply + * @param int $timespan The maximum acceptable age for a submitted form + * in seconds. Defaults to the config setting. + * @return bool True, if the form key was valid, false otherwise + */ +function mx_check_form_key($form_name, $timespan = false) +{ + global $board_config, $mx_request_vars, $mx_user; + + if ($timespan === false) + { + // we enforce a minimum value of half a minute here. + $timespan = ($board_config['form_token_lifetime'] == -1) ? -1 : max(30, $board_config['form_token_lifetime']); + } + + if ($mx_request_vars->is_set_post('creation_time') && $mx_request_vars->is_set_post('form_token')) + { + $creation_time = abs($mx_request_vars->request('creation_time', 0)); + $token = $mx_request_vars->variable('form_token', ''); + + $diff = time() - $creation_time; + + // If creation_time and the time() now is zero we can assume it was not a human doing this (the check for if ($diff)... + if (defined('DEBUG_TEST') || $diff && ($diff <= $timespan || $timespan === -1)) + { + $token_sid = ($mx_user->data['user_id'] == ANONYMOUS && !empty($board_config['form_token_sid_guests'])) ? $mx_user->session_id : ''; + $key = sha1($creation_time . $mx_user->data['user_form_salt'] . $form_name . $token_sid); + + if ($key === $token) + { + return true; + } + } + } + + return false; +} /** * Generate Pagination. @@ -1067,31 +1276,31 @@ function mx_generate_pagination($base_url, $num_items, $per_page, $start_item, $ /** * Get userdata * - * Get Userdata, $user can be username or user_id. If force_str is true, the username will be forced. + * Get Userdata, $mx_user can be username or user_id. If force_str is true, the username will be forced. * Cached sql, since this function is used for every block. * - * @param unknown_type $user id or name + * @param unknown_type $mx_user id or name * @param boolean $force_str force clean_username * @return array */ -function mx_get_userdata($user, $force_str = false) +function mx_get_userdata($mxuser, $force_str = false) { - global $db; + global $db, $phpBB2; - if (!is_numeric($user) || $force_str) + if (!is_numeric($mxuser) || $force_str) { - $user = phpBB2::phpbb_clean_username($user); + $mxuser = $phpBB2->phpbb_clean_username($mxuser); } else { - $user = intval($user); + $mxuser = intval($mxuser); } $sql = "SELECT * FROM " . USERS_TABLE . " WHERE "; - $sql .= ((is_integer($user)) ? "user_id = $user" : "username = '" . str_replace("\'", "''", $user) . "'" ) . " AND user_id <> " . ANONYMOUS; - if (!($result = $db->sql_query($sql, 120))) + $sql .= ((is_integer($mxuser)) ? "user_id = $mxuser" : "username = '" . str_replace("\'", "''", $mxuser) . "'" ) . " AND user_id <> " . ANONYMOUS; + if (!($result = $db->sql_query($sql))) { mx_message_die(GENERAL_ERROR, 'Tried obtaining data for a non-existent user', '', __LINE__, __FILE__, $sql); } @@ -1101,6 +1310,205 @@ function mx_get_userdata($user, $force_str = false) return $return; } +/** +* Get user avatar +* +* @param array $user_row Row from the users table +* @param string $alt Optional language string for alt tag within image, can be a language key or text +* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP +* @param bool $lazy If true, will be lazy loaded (requires JS) +* +* @return string Avatar html +*/ +function mx_get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false, $lazy = false) +{ + return mx_get_avatar($user_row, $alt, $ignore_config, $lazy); +} + +/** +* Get group avatar +* +* @param array $group_row Row from the groups table +* @param string $alt Optional language string for alt tag within image, can be a language key or text +* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP +* @param bool $lazy If true, will be lazy loaded (requires JS) +* +* @return string Avatar html +*/ +function mx_get_group_avatar($user_row, $alt = 'GROUP_AVATAR', $ignore_config = false, $lazy = false) +{ + return mx_get_avatar($user_row, $alt, $ignore_config, $lazy); +} + +/** +* Build gravatar URL for output on page +* +* @param array $row User data or group data that has been cleaned with +* \phpbb\avatar\manager::clean_row +* @return string Gravatar URL +*/ +function mx_get_gravatar_url($row) +{ + $url = '//secure.gravatar.com/avatar/'; + + $url .= md5(strtolower(trim($row['avatar']))); + + if ($row['avatar_width'] || $row['avatar_height']) + { + $url .= '?s=' . max($row['avatar_width'], $row['avatar_height']); + } + + return $url; +} + +/** +* Get avatar +* +* @param array $row Row cleaned by \phpbb\avatar\manager::clean_row +* @param string $alt Optional language string for alt tag within image, can be a language key or text +* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP +* @param bool $lazy If true, will be lazy loaded (requires JS) +* +* @return string Avatar html +*/ +function mx_get_avatar($row, $alt, $ignore_config = false, $lazy = false) +{ + global $mx_user, $board_config, $mx_cache, $phpbb_root_path, $phpEx; + + if (!$mx_user->optionget('viewavatars') && !$ignore_config) + { + return ''; + } + + $row = array( + 'avatar' => isset($row['avatar']) ? $row['avatar'] : $row['user_avatar'], + 'avatar_type' => isset($row['avatar_type']) ? $row['avatar_type'] : $row['user_avatar_type'], + 'avatar_width' => isset($row['avatar_width']) ? $row['avatar_width'] : (isset($row['user_avatar_width']) ? $row['user_avatar_width'] : '120'), + 'avatar_height' => isset($row['avatar_height']) ? $row['avatar_height'] : (isset($row['user_avatar_height']) ? $row['user_avatar_height'] : '120'), + ); + + $avatar_data = array( + 'src' => $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], + ); + + + $driver = $row['avatar_type']; + $html = ''; + + if ($driver) + { + $html = ''; + + if (!empty($html)) + { + return $html; + } + + $root_path = generate_portal_url(); + + $avatar_data = array( + 'src' => $root_path . $board_config['avatar_gallery_path'] . '/' . $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], + ); + } + else + { + $avatar_data['src'] = ''; + } + + if (!empty($avatar_data['src'])) + { + if ($lazy) + { + // Determine board url - we may need it later + $board_url = generate_portal_url() . '/'; + // This path is sent with the base template paths in the assign_vars() + // call below. We need to correct it in case we are accessing from a + // controller because the web paths will be incorrect otherwise. + + $web_path = $board_url; + + if (is_dir($phpbb_root_path . $mx_user->template_path . $mx_user->template_name . '/theme/images/')) + { + $theme_images = "{$web_path}{$mx_user->template_path}" . rawurlencode($mx_user->template_name) . '/theme/images'; + } + elseif (is_dir($phpbb_root_path . $mx_user->template_path . $mx_user->template_name . '/images/')) + { + $theme_images = "{$web_path}{$mx_user->template_path}" . rawurlencode($mx_user->template_name . '/images'); + } + $src = 'src="' . $theme_images . '/no_avatar.gif" data-src="' . $avatar_data['src'] . '"'; + } + else + { + $src = 'src="' . $avatar_data['src'] . '"'; + } + + $html = '
lang[$alt])) ? $mx_user->lang[$alt] : $alt) . '" />'; + } + return $html; +} + +/** +* Get user rank title and image +* +* @param array $userdata the current stored users data +* @param int $user_posts the users number of posts +* +* @return array An associative array containing the rank title (title), the rank image as full img tag (img) and the rank image source (img_src) +* +* Note: since we do not want to break backwards-compatibility, this function will only properly assign ranks to guests if you call it for them with user_posts == false +*/ +function mx_get_user_rank($userdata, $user_posts, &$rank_title = null, &$rank_img = null, &$rank_img_src = null) +{ + global $ranks, $board_config, $phpbb_root_path; + + $user_rank_data = array( + 'title' => $rank_title ? $rank_title : null, + 'img' => $rank_img ? $rank_img : null, + 'img_src' => $rank_img_src ? $rank_img_src : null, + ); + + if (empty($ranks)) + { + global $mx_cache; + $ranks = $mx_cache->obtain_ranks(); + } + + if (!empty($userdata)) + { + $user_rank_data['title'] = (isset($ranks['special'][$userdata['user_rank']]['rank_title'])) ? $ranks['special'][$userdata['user_rank']]['rank_title'] : ''; + $user_rank_data['img'] = (!empty($ranks['special'][$userdata['user_rank']]['rank_image'])) ? '
' : ''; + $user_rank_data['img_src'] = (!empty($ranks['special'][$userdata['user_rank']]['rank_image'])) ? $phpbb_root_path . $board_config['ranks_path'] . '/' . $ranks['special'][$userdata['user_rank']]['rank_image'] : ''; + } + else if ($user_posts !== false) + { + if (!empty($ranks['normal'])) + { + foreach ($ranks['normal'] as $rank) + { + if ($user_posts >= $rank['rank_min']) + { + $user_rank_data['title'] = $rank['rank_title']; + $user_rank_data['img'] = (!empty($rank['rank_image'])) ? '
' : ''; + $user_rank_data['img_src'] = (!empty($rank['rank_image'])) ? $phpbb_root_path . $board_config['ranks_path'] . '/' . $rank['rank_image'] : ''; + break; + } + } + } + } + + return $user_rank_data; +} + /** * Select language. * @@ -1182,7 +1590,7 @@ function mx_style_select($default_style, $select_name = "style", $dirname = "tem { $style_select .= ''; } - + /* while (!($row = $db->sql_fetchrow($result))) { $sql = "SELECT themes_id, style_name @@ -1193,7 +1601,8 @@ function mx_style_select($default_style, $select_name = "style", $dirname = "tem { mx_message_die(GENERAL_ERROR, "Couldn't query themes table", "", __LINE__, __FILE__, $sql); } - } + } + */ while ($row = $db->sql_fetchrow($result)) { $id = $row['themes_id']; @@ -2070,7 +2479,7 @@ function mx_this_url($args = '', $force_standalone_mode = false, $file = '') */ function mx_session_start() { - global $board_config, $do_gzip_compress; + global $board_config, $do_gzip_compress, $mx_user, $mx_request_vars, $sid; // // Prevent from doing the job more than once. @@ -2096,9 +2505,9 @@ function mx_session_start() { $phpver = phpversion(); - $useragent = (isset($_SERVER['HTTP_USER_AGENT'])) ? $_SERVER['HTTP_USER_AGENT'] : getenv('HTTP_USER_AGENT'); + $mx_useragent = (isset($_SERVER['HTTP_USER_AGENT'])) ? $_SERVER['HTTP_USER_AGENT'] : getenv('HTTP_USER_AGENT'); - if ($phpver >= '4.0.4pl1' && (strstr($useragent,'compatible') || strstr($useragent,'Gecko'))) + if ($phpver >= '4.0.4pl1' && (strstr($mx_useragent,'compatible') || strstr($mx_useragent,'Gecko'))) { if (extension_loaded('zlib')) { @@ -2126,8 +2535,24 @@ function mx_session_start() // Initialize PHP session // //phpinfo(); - session_start(); - // + //Security check + if(is_object($mx_request_vars) || !empty($mx_user->session_id)) + { + // session id check + if (!$mx_request_vars->is_empty_request('sid')) + { + $sid = $mx_request_vars->request('sid', MX_TYPE_NO_TAGS, $mx_user->session_id); + } + session_id(strip_tags($sid)); + } + // ok to try and start the session + if (!empty($sid)) + { + if (!session_start()) + { + mx_message_die(GENERAL_ERROR, "Failed to start the session", '', __LINE__, __FILE__, $sid); + } + } } /** @@ -2151,12 +2576,12 @@ function get_page_id($search_item, $use_function_file = false, $get_page_data_ar // // Try to reuse results. // - $cache_key = '_pagemap_block' . $search_item; + $mx_cache_key = '_pagemap_block' . $search_item; $page_id_array = array(); - if ( $mx_cache->_exists( $cache_key ) ) + if ( $mx_cache->_exists( $mx_cache_key ) ) { - $page_id_array = unserialize( $mx_cache->get( $cache_key ) ); + $page_id_array = unserialize( $mx_cache->get( $mx_cache_key ) ); } else { @@ -2324,7 +2749,7 @@ function get_page_id($search_item, $use_function_file = false, $get_page_data_ar $page_id_array['block_id'] = isset($p_row['block_id']) ? $p_row['block_id'] : 0; } unset($p_row); - $mx_cache->put( $cache_key, serialize($page_id_array) ); + $mx_cache->put( $mx_cache_key, serialize($page_id_array) ); } if ( $get_page_data_array && !empty($page_id_array['page_id']) ) @@ -2463,6 +2888,30 @@ function mx_parent_data($block_id, $key = '') return false; } +/** + * Get MX-Publisher modules + * + * @return modules array + */ +function obtain_portal_modules() +{ + global $db; + + $modules = array(); + + $sql = "SELECT * FROM " . MODULE_TABLE . " ORDER BY module_name"; + if( !($result = $db->sql_query($sql)) ) + { + mx_message_die(GENERAL_ERROR, "Couldn't obtain modules from database", '', __LINE__, __FILE__, $sql); + } + while ($row = $db->sql_fetchrow($result)) + { + $modules[] = $row; + } + $db->sql_freeresult($result); + return $modules; +} + /** * Compose MX-Publisher copyrights and credits page. * @access public @@ -2484,7 +2933,7 @@ function compose_mx_copy() $mx_module_copy = '
' . $lang['mx_copy_title'] . '
'; $mx_module_copy .= '
' . '' . $lang['mx_copy_modules_title'] . ''; - for( $i = 0; $i < count($module); $i++ ) + for( $i = 0; $i < $count = count($module); $i++ ) { if( !empty($module[$i]['module_copy']) ) { @@ -2714,28 +3163,28 @@ function get_backtrace() * * Creates missing config entry if needed. * - * @param unknown_type $config_name - * @param unknown_type $config_value + * @param unknown_type $board_config_name + * @param unknown_type $board_config_value * @param unknown_type $is_dynamic */ - function mx_set_config($config_name, $config_value) + function mx_set_config($board_config_name, $board_config_value) { global $db, $mx_cache, $portal_config; $sql = 'UPDATE ' . PORTAL_TABLE . " - SET config_value = '" . $db->sql_escape($config_value) . "' - WHERE config_name = '" . $db->sql_escape($config_name) . "'"; + SET config_value = '" . $db->sql_escape($board_config_value) . "' + WHERE config_name = '" . $db->sql_escape($board_config_name) . "'"; $db->sql_query($sql); - if (!$db->sql_affectedrows() && !isset($portal_config[$config_name])) + if (!$db->sql_affectedrows() && !isset($portal_config[$board_config_name])) { $sql = 'INSERT INTO ' . PORTAL_TABLE . ' ' . $db->sql_build_array('INSERT', array( - 'config_name' => $config_name, - 'config_value' => $config_value)); + 'config_name' => $board_config_name, + 'config_value' => $board_config_value)); $db->sql_query($sql); } - $portal_config[$config_name] = $config_value; + $portal_config[$board_config_name] = $board_config_value; $mx_cache->put( 'mxbb_config', $portal_config ); } } @@ -3005,7 +3454,7 @@ function update_portal_backend($new_backend = PORTAL_BACKEND) $dbcharacter_set = "uft8"; /* - $config = array( + $board_config = array( 'dbms' => $dbms, 'dbhost' => $dbhost, 'dbname' => $dbname, @@ -3043,18 +3492,18 @@ function update_portal_backend($new_backend = PORTAL_BACKEND) $process_msgs[] = 'Writing config ...
'; - $config_data = "<"."?php\n\n"; - $config_data .= "// $mx_portal_name auto-generated config file\n// Do not change anything in this file!\n\n"; - $config_data .= "// This file must be put into the $mx_portal_name directory, not into the phpBB directory.\n\n"; - $config_data .= '$'."dbms = '$dbms';\n\n"; - $config_data .= '$'."dbhost = '$dbhost';\n"; - $config_data .= '$'."dbname = '$dbname';\n"; - $config_data .= '$'."dbuser = '$dbuser';\n"; - $config_data .= '$'."dbpasswd = '$dbpasswd';\n\n"; - $config_data .= '$'."mx_table_prefix = '$mx_table_prefix';\n\n"; - $config_data .= "define('DBCHARACTER_SET', '$dbcharacter_set');\n\n"; - $config_data .= "define('MX_INSTALLED', true);\n\n"; - $config_data .= '?' . '>'; // Done this to prevent highlighting editors getting confused! + $board_config_data = "<"."?php\n\n"; + $board_config_data .= "// $mx_portal_name auto-generated config file\n// Do not change anything in this file!\n\n"; + $board_config_data .= "// This file must be put into the $mx_portal_name directory, not into the phpBB directory.\n\n"; + $board_config_data .= '$'."dbms = '$dbms';\n\n"; + $board_config_data .= '$'."dbhost = '$dbhost';\n"; + $board_config_data .= '$'."dbname = '$dbname';\n"; + $board_config_data .= '$'."dbuser = '$dbuser';\n"; + $board_config_data .= '$'."dbpasswd = '$dbpasswd';\n\n"; + $board_config_data .= '$'."mx_table_prefix = '$mx_table_prefix';\n\n"; + $board_config_data .= "define('DBCHARACTER_SET', '$dbcharacter_set');\n\n"; + $board_config_data .= "define('MX_INSTALLED', true);\n\n"; + $board_config_data .= '?' . '>'; // Done this to prevent highlighting editors getting confused! @umask(0111); @chmod($mx_root_path . "config.$phpEx", 0644); @@ -3063,10 +3512,10 @@ function update_portal_backend($new_backend = PORTAL_BACKEND) { $process_msgs[] = "Unable to write config file " . $mx_root_path . "config.$phpEx" . "
\n"; } - $result = @fputs($fp, $config_data, strlen($config_data)); + $result = @fputs($fp, $board_config_data, strlen($board_config_data)); @fclose($fp); - $process_msgs[] = ''.str_replace("\n", "
\n", htmlspecialchars($config_data)).''; + $process_msgs[] = ''.str_replace("\n", "
\n", htmlspecialchars($board_config_data)).''; $message = '
'; for( $i=0; $i < count($process_msgs); $i++ ) @@ -3119,11 +3568,13 @@ function t($string, array $args = array(), array $options = array()) { global $lang, $mx_cache, $mx_user, $board_config; static $lang_string; + // Merge in default. if (empty($options['langcode'])) { $options['langcode'] = isset($lang['USER_LANG']) ? $lang['USER_LANG'] : $mx_user->encode_lang($board_config['default_lang']); } + if (!empty($lang[$string])) { $lang_string = $lang[$string]; @@ -3132,6 +3583,7 @@ function t($string, array $args = array(), array $options = array()) { $lang_string = $string; } + if (empty($args)) { return $lang_string; diff --git a/includes/mx_functions_admincp.php b/includes/mx_functions_admincp.php index 42b946e2..1b1155e1 100644 --- a/includes/mx_functions_admincp.php +++ b/includes/mx_functions_admincp.php @@ -2842,31 +2842,7 @@ function_admin= '$module_data[6]' $sql_delete = "DELETE FROM " . PARAMETER_TABLE . " WHERE function_id = " . $module_data[1] . " AND parameter_id = " . $module_data[2]; break; - // - // 0: option, 1: option_id, 2: parameter_id, 3: option_code, - // 4: option_desc - // - case 'option': - // Parameter Option - $sql = "SELECT * FROM " . PARAMETER_OPTION_TABLE . " WHERE parameter_id = ".intval($module_data[2])." ORDER BY option_id"; - if(($result = $db->sql_query($sql))) - { - $table = PARAMETER_OPTION_TABLE; - $fldkey = 'option_id'; - $key = $module_data[1]; - - $sql_add = "INSERT INTO " . PARAMETER_OPTION_TABLE . " (option_id, parameter_id, option_code, option_desc) - VALUES ('$module_data[1]', '$module_data[2]', '$module_data[3]', '$module_data[4]' )"; - - $sql_update = "UPDATE " . PARAMETER_OPTION_TABLE . " - SET parameter_id = '$module_data[2]', - option_code = '$module_data[3]', - option_desc = '$module_data[4]' - WHERE option_id = '$module_data[1]'"; - - $sql_delete = "DELETE FROM " . PARAMETER_OPTION_TABLE . " WHERE option_id = " . $module_data[1] . " AND parameter_id = " . $module_data[2]; - } - break; + // // 0: block, 1: block_id, 2: block_title, 3: block_desc, // 4: function_id, 5: auth_view, 6: auth_edit, 7: auth_delete @@ -3165,28 +3141,6 @@ function export_pack($module_id) $module_pak .= $resultset_param[$p]['parameter_order'] . "\n"; $paramater_id = $resultset_param[$p]['parameter_id']; - - // Parameter Option - $sql = "SELECT * FROM " . PARAMETER_OPTION_TABLE . " WHERE parameter_id = $paramater_id ORDER BY option_id"; - if(($result = $db->sql_query($sql))) - { - $resultset_opt = $db->sql_fetchrowset($result); - - // 0: option, 1: option_id, 2: parameter_id, 3: option_code, - // 4: option_desc - for( $o = 0; $o < count($resultset_opt); $o++ ) - { - $module_pak .= 'option' . $delimeter . $resultset_opt[$o]['option_id'] . $delimeter; - $module_pak .= $resultset_opt[$o]['parameter_id'] . $delimeter; - $module_pak .= $resultset_opt[$o]['option_code'] . $delimeter; - $module_pak .= $resultset_opt[$o]['option_desc'] . "\n"; - } - - $module_pak .= 'option' . $delimeter. '0' . $delimeter; - $module_pak .= '0' . $delimeter; - $module_pak .= '0' . $delimeter; - $module_pak .= 'endoflist' . $delimeter . "\n"; - } } $module_pak .= 'parameter' . $delimeter . '0' . $delimeter; diff --git a/includes/mx_functions_bbcode.php b/includes/mx_functions_bbcode.php index 9ba77fbe..161b1ba6 100644 --- a/includes/mx_functions_bbcode.php +++ b/includes/mx_functions_bbcode.php @@ -85,8 +85,8 @@ function prepare_bbcode_template($bbcode_tpl) { global $document_id, $access_key, $height, $width; global $lang; - $bbcode_tpl['olist_open'] = str_replace('{LIST_TYPE}', '\\1', $bbcode_tpl['olist_open']); + //$bbcode_tpl['mlist_open'] = str_replace('{LIST_TYPE}', '\\1', $bbcode_tpl['mlist_open']); $bbcode_tpl['color_open'] = str_replace('{COLOR}', '\\1', $bbcode_tpl['color_open']); $bbcode_tpl['size_open'] = str_replace('{SIZE}', '\\1', $bbcode_tpl['size_open']); $bbcode_tpl['quote_open'] = str_replace('{L_QUOTE}', $lang['Quote'], $bbcode_tpl['quote_open']); @@ -112,14 +112,35 @@ function prepare_bbcode_template($bbcode_tpl) $bbcode_tpl['email'] = str_replace('{EMAIL}', '\\1', $bbcode_tpl['email']); // bbcode_box Mod - $bbcode_tpl['align_open'] = str_replace('{ALIGN}', '\\1', $bbcode_tpl['align_open']); - // $bbcode_tpl['stream'] = str_replace('{URL}', '\\1', $bbcode_tpl['stream']); + // $bbcode_tpl['stream'] = str_replace('{URL}', '\\1', $bbcode_tpl['stream']); $bbcode_tpl['ram'] = str_replace('{URL}', '\\1', $bbcode_tpl['ram']); $bbcode_tpl['marq_open'] = str_replace('{MARQ}', '\\1', $bbcode_tpl['marq_open']); - $bbcode_tpl['table_open'] = str_replace('{TABLE}', '\\1', $bbcode_tpl['table_open']); - $bbcode_tpl['cell_open'] = str_replace('{CELL}', '\\1', $bbcode_tpl['cell_open']); - $bbcode_tpl['web'] = str_replace('{URL}', '\\1', $bbcode_tpl['web']); - //$bbcode_tpl['center_open'] = str_replace('{CENTER}', '\\1', $bbcode_tpl['center_open']); + + // table + $bbcode_tpl['table_open'] = str_replace('{TABLE}', '\\1', $bbcode_tpl['table_open']); + // tr + $bbcode_tpl['tr_open'] = str_replace('{TR}', '\\1', $bbcode_tpl['tr_open']); + // th + $bbcode_tpl['th_open'] = str_replace('{TH}', '\\1', $bbcode_tpl['th_open']); + // td + $bbcode_tpl['td_open'] = str_replace('{TD}', '\\1', $bbcode_tpl['td_open']); + // cell + $bbcode_tpl['cell_open'] = str_replace('{CELL}', '\\1', $bbcode_tpl['cell_open']); + // thead + $bbcode_tpl['thead_open'] = str_replace('{THEAD}', '\\1', $bbcode_tpl['thead_open']); + // tbody + $bbcode_tpl['tbody_open'] = str_replace('{TBODY}', '\\1', $bbcode_tpl['tbody_open']); + // center + $bbcode_tpl['center_open'] = str_replace('{CENTER}', '\\1', $bbcode_tpl['center_open']); + // align + $bbcode_tpl['align_open'] = str_replace('{ALIGN}', '\\1', $bbcode_tpl['align_open']); + // float + $bbcode_tpl['float_open'] = str_replace('{FLOAT}', '\\1', $bbcode_tpl['float_open']); + // fa + $bbcode_tpl['fa_open'] = str_replace('{TEXT}', '\\1', $bbcode_tpl['fa_open']); + + $bbcode_tpl['web'] = str_replace('{URL}', '\\1', $bbcode_tpl['web']); + //$bbcode_tpl['flash'] = str_replace('{WIDTH}', '\\1', $bbcode_tpl['flash']); //$bbcode_tpl['flash'] = str_replace('{HEIGHT}', '\\2', $bbcode_tpl['flash']); //$bbcode_tpl['flash'] = str_replace('{URL}', '\\3', $bbcode_tpl['flash']); @@ -176,6 +197,21 @@ function bbcode_nl2br($text) * a thread. Assumes the message is already first-pass encoded, and we are given the * correct UID as used in first-pass encoding. * This a temporary function + + Creating an BBcode List with a custom bullet character. + For example to list your favorite colors you could use: + + [list=square] + [*]Red + [*]Blue + [*]Yellow + [/list] + + The question is how to specify a custom list’s bullet such as [b]?[/b] for a Features BBcode List ? + + [b]√[/b][color=#FF0000]Red[/color] + [b]√[/b][color=#0040FF]Blue[/color] + [b]√[/b][color=#FFFF00]Yellow[/color] */ function bbencode_second_pass($text, $uid = '', $bitfield = false) { @@ -200,8 +236,8 @@ function bbencode_second_pass($text, $uid = '', $bitfield = false) $this->bbcode_second_pass($text, $uid, $bitfield); } - //$text = str_replace(array("\n", "\r"), array('
', "\n"), $text); - $text = str_replace(array("\n", "\r"), array('
', ""), $text); + $text = str_replace(array("\n", "\r"), array('
', "\n"), $text); + $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text); // pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0). @@ -243,14 +279,23 @@ function bbencode_second_pass($text, $uid = '', $bitfield = false) // [list] and [list=x] for (un)ordered lists. // unordered lists $text = str_replace("[list:$uid]", $bbcode_tpl['ulist_open'], $text); + // li tags $text = str_replace("[*:$uid]", $bbcode_tpl['listitem'], $text); + // ending tags $text = str_replace("[/list:u:$uid]", $bbcode_tpl['ulist_close'], $text); $text = str_replace("[/list:o:$uid]", $bbcode_tpl['olist_close'], $text); - // Ordered lists - $text = preg_replace("/\[list=([a1]):$uid\]/si", $bbcode_tpl['olist_open'], $text); - + //$text = str_replace("[/list:m:$uid]", $bbcode_tpl['mlist_close'], $text); + // Ordered lists + $text = preg_replace("/\[list=([a1]):$uid\]/si", $bbcode_tpl['olist_open'], $text); + //$text = preg_replace("/\[list=([disc]):$uid\]/si", $bbcode_tpl['olist_open'], $text); + //$text = preg_replace("/\[list=([circle]):$uid\]/si", $bbcode_tpl['olist_open'], $text); + //$text = preg_replace("/\[list=([square]):$uid\]/si", $bbcode_tpl['olist_open'], $text); + //$text = preg_replace("/\[list=([radical]):$uid\]/si", $bbcode_tpl['olist_open'], $text); + //$text = preg_replace("/\[list=([none]):$uid\]/si", $bbcode_tpl['olist_open'], $text); + //$text = preg_replace("/\[list=([^\[]+):$uid\][\n]/si", $bbcode_tpl['mlist_open'], $text); + // colours $text = preg_replace("/\[color=(\#[0-9A-F]{6}|[a-z]+):$uid\]/si", $bbcode_tpl['color_open'], $text); $text = str_replace("[/color:$uid]", $bbcode_tpl['color_close'], $text); @@ -262,7 +307,13 @@ function bbencode_second_pass($text, $uid = '', $bitfield = false) // [b] and [/b] for bolding text. $text = str_replace("[b:$uid]", $bbcode_tpl['b_open'], $text); $text = str_replace("[/b:$uid]", $bbcode_tpl['b_close'], $text); - + + // [fa] and [/fa] for bolding text. + $text = str_replace("[fa:$uid]", $bbcode_tpl['fa_open'], $text); + $text = str_replace("[fa_logo:$uid]", $bbcode_tpl['fa_logo_open'], $text); + $text = str_replace("[/fa:$uid]", $bbcode_tpl['fa_close'], $text); + $text = str_replace("[/fa_logo:$uid]", $bbcode_tpl['fa_logo_close'], $text); + // [u] and [/u] for underlining text. $text = str_replace("[u:$uid]", $bbcode_tpl['u_open'], $text); $text = str_replace("[/u:$uid]", $bbcode_tpl['u_close'], $text); @@ -280,8 +331,8 @@ function bbencode_second_pass($text, $uid = '', $bitfield = false) // [img]image_url_here[/img] code.. // This one gets first-passed.. $patterns[] = "#\[img:$uid\]([^?](?:[^\[]+|\[(?!url))*?)\[/img:$uid\]#i"; - $replacements[] = $bbcode_tpl['img']; - + $replacements[] = $bbcode_tpl['img']; + // matches a [url]xxxx://www.phpbb.com[/url] code.. $patterns[] = "#\[url\]([\w]+?://([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is"; $replacements[] = $bbcode_tpl['url1']; @@ -297,10 +348,13 @@ function bbencode_second_pass($text, $uid = '', $bitfield = false) // [url=www.phpbb.com]phpBB[/url] code.. (no xxxx:// prefix). $patterns[] = "#\[url=((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is"; $replacements[] = $bbcode_tpl['url4']; - + // [email]user@domain.tld[/email] code.. $patterns[] = "#\[email\]([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si"; - $replacements[] = $bbcode_tpl['email']; + $replacements[] = $bbcode_tpl['email']; + + $patterns[] = "#\[ram\]([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/ram\]#si"; + $replacements[] = $bbcode_tpl['ram']; //Strat more bbcode $text = preg_replace($patterns, $replacements, $text); @@ -310,16 +364,39 @@ function bbencode_second_pass($text, $uid = '', $bitfield = false) // marquee $text = preg_replace("/\[marq=(left|right|up|down):$uid\]/si", $bbcode_tpl['marq_open'], $text); $text = str_replace("[/marq:$uid]", $bbcode_tpl['marq_close'], $text); + // html + $text = $this->bbencode_second_pass_html($text, $uid, $bbcode_tpl); // table - $text = preg_replace("/\[table=(.*?):$uid\]/si", $bbcode_tpl['table_open'], $text); - $text = str_replace("[/table:$uid]", $bbcode_tpl['table_close'], $text); + $text = str_replace("[table:$uid]", $bbcode_tpl['table_open'], $text); + $text = str_replace("[/table:$uid]", $bbcode_tpl['table_close'], $text); + // tr + $text = str_replace("[tr:$uid]", $bbcode_tpl['tr_open'], $text); + $text = str_replace("[/tr:$uid]", $bbcode_tpl['tr_close'], $text); + // th + $text = preg_replace("[th:$uid]", $bbcode_tpl['th_open'], $text); + $text = str_replace("[/th:$uid]", $bbcode_tpl['th_close'], $text); + // td + $text = preg_replace("[td:$uid]", $bbcode_tpl['td_open'], $text); + $text = str_replace("[/td:$uid]", $bbcode_tpl['td_close'], $text); // cell $text = preg_replace("/\[cell=(.*?):$uid\]/si", $bbcode_tpl['cell_open'], $text); $text = str_replace("[/cell:$uid]", $bbcode_tpl['cell_close'], $text); + // thead + $text = preg_replace("[thead:$uid]", $bbcode_tpl['thead_open'], $text); + $text = str_replace("[/thead:$uid]", $bbcode_tpl['thead_close'], $text); + // tbody + $text = preg_replace("[tbody:$uid]", $bbcode_tpl['tbody_open'], $text); + $text = str_replace("[/tbody:$uid]", $bbcode_tpl['tbody_close'], $text); // center $text = preg_replace("/\[center:$uid\]/si", $bbcode_tpl['center_open'], $text); $text = str_replace("[/center:$uid]", $bbcode_tpl['center_close'], $text); - // font + // align + $text = preg_replace("/\[align:$uid\]/si", $bbcode_tpl['align_open'], $text); + $text = str_replace("[/align:$uid]", $bbcode_tpl['align_close'], $text); + // float + $text = preg_replace("/\[float:$uid\]/si", $bbcode_tpl['float_open'], $text); + $text = str_replace("[/float:$uid]", $bbcode_tpl['float_close'], $text); + // font $text = preg_replace("/\[font=(.*?):$uid\]/si", $bbcode_tpl['font_open'], $text); $text = str_replace("[/font:$uid]", $bbcode_tpl['font_close'], $text); // poet @@ -401,7 +478,6 @@ function bbencode_second_pass($text, $uid = '', $bitfield = false) function replace_listitems($text, $uid) { $text = str_replace("[*]", "[*:$uid]", $text); - return $text; } @@ -435,7 +511,7 @@ function bbencode_first_pass($text, $uid) // [ipaper] and [/ipaper] for posting scribd embed bbcode in your posts. $text = $this->bbencode_first_pass_pda($text, $uid, '[ipaper]', '[/ipaper]', '', true, ''); - + // [scribd] and [/scribd] for posting scribd embed bbcode in your posts. $text = $this->bbencode_first_pass_pda($text, $uid, '[scribd]', '[/scribd]', '', false, ''); $text = $this->bbencode_first_pass_pda($text, $uid, '/\[scribd\\\\id=([0-9A-Za-z-_]{8})\\\\key=([0-9A-Za-z-_]{24})\](.*?)\]/is', '[/scribd]', '', false, '', "[scribd:$uid=\\\id=\\1\\\key=\\2\\\]"); @@ -446,10 +522,15 @@ function bbencode_first_pass($text, $uid) // unordered.. $text = $this->bbencode_first_pass_pda($text, $uid, $open_tag, "[/list]", "[/list:u]", false, 'replace_listitems'); - + $open_tag[0] = "[list=1]"; $open_tag[1] = "[list=a]"; - + //$open_tag[0] = "[list=disc]"; + //$open_tag[0] = "[list=circle]"; + //$open_tag[0] = "[list=square]"; + //$open_tag[0] = "[list=radical]"; + //$open_tag[0] = "[list=none]"; + // ordered. $text = $this->bbencode_first_pass_pda($text, $uid, $open_tag, "[/list]", "[/list:o]", false, 'replace_listitems'); @@ -461,7 +542,11 @@ function bbencode_first_pass($text, $uid) // [b] and [/b] for bolding text. $text = preg_replace("#\[b\](.*?)\[/b\]#si", "[b:$uid]\\1[/b:$uid]", $text); - + + // [fa] and [/fa] for simple text. + $text = preg_replace("#\[fa\](.*?)\[/fa\]#si", "[fa:$uid]\\1[/fa:$uid]", $text); + $text = preg_replace("#\[fa_logo\](.*?)\[/fa_logo\]#si", "[fa_logo:$uid]\\1[/fa_logo:$uid]", $text); + // [u] and [/u] for underlining text. $text = preg_replace("#\[u\](.*?)\[/u\]#si", "[u:$uid]\\1[/u:$uid]", $text); @@ -469,14 +554,18 @@ function bbencode_first_pass($text, $uid) $text = preg_replace("#\[i\](.*?)\[/i\]#si", "[i:$uid]\\1[/i:$uid]", $text); // [img]image_url_here[/img] code.. - $text = preg_replace("#\[img\]((http|ftp|https|ftps)://)([^ \?&=\#\"\n\r\t<]*?(\.(jpg|jpeg|gif|png)))\[/img\]#sie", "'[img:$uid]\\1' . str_replace(' ', '%20', '\\3') . '[/img:$uid]'", $text); - + $text = preg_replace("#\[img\]((http|ftp|https|ftps)://)([^ \?&=\#\"\n\r\t<]*?(\.(jpg|jpeg|gif|png)))\[/img\]#si", "'[img:$uid]\\1' . str_replace(' ', '%20', '\\3') . '[/img:$uid]'", $text); + //Start more bbcode $text = str_replace('url:' . $uid, 'url', $text); // [stream]Sound URL[/stream] code.. $text = preg_replace("#\[stream\](.*?)\[/stream\]#si", "[stream:$uid]\\1[/stream:$uid]", $text); + // [html width=X height=X] [/html] code.. + $text = $this->bbencode_first_pass_pda($text, $uid, '[html]', '[/html]', '', true, ''); + + // [scribd width=X height=X]Scribd URL[/scribd] code.. $text = preg_replace("#\[scribd width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-9]?[0-9])\](([a-z]+?)://([^, \n\r]+))\[\/scribd\]#si","[scribd width=\\1 height=\\2:$uid\]\\3[/scribd:$uid]", $text); @@ -489,7 +578,7 @@ function bbencode_first_pass($text, $uid) //Stop more bbcode // Remove our padding from the string.. - return substr($text, 1);; + return substr($text, 1); } // bbencode_first_pass() @@ -684,24 +773,18 @@ function bbencode_first_pass_pda($text, $uid, $open_tag, $close_tag, $close_tag_ $after_end_tag = substr($text, $curr_pos + $close_tag_length); // Mark the lowest nesting level if needed. - if ($mark_lowest_level && ($curr_nesting_depth == 1)) - { - if ($open_tag[0] == '[code]') - { - $code_entities_match = array('#<#', '#>#', '#"#', '#:#', '#\[#', '#\]#', '#\(#', '#\)#', '#\{#', '#\}#'); - $code_entities_replace = array('<', '>', '"', ':', '[', ']', '(', ')', '{', '}'); - $between_tags = preg_replace($code_entities_match, $code_entities_replace, $between_tags); - } - $text = $before_start_tag . substr($start_tag, 0, $start_length - 1) . ":$curr_nesting_depth:$uid]"; - $text .= $between_tags . substr($close_tag_new, 0, $close_tag_new_length - 1) . ":$curr_nesting_depth:$uid]"; - } - else + if (!$mark_lowest_level && ($curr_nesting_depth !== 1)) { if ($open_tag[0] == '[code]') { $text = $before_start_tag . '[code]'; $text .= $between_tags . '[/code]'; } + elseif ($open_tag[0] == '[html]') + { + $text = $before_start_tag . '[ ]'; + $text .= $between_tags . '[ ]'; + } else { if ($open_is_regexp) @@ -715,7 +798,23 @@ function bbencode_first_pass_pda($text, $uid, $open_tag, $close_tag, $close_tag_ $text .= $between_tags . substr($close_tag_new, 0, $close_tag_new_length - 1) . ":$uid]"; } } - + elseif ($mark_lowest_level && ($curr_nesting_depth == 1)) + { + if ($open_tag[0] == '[code]') + { + $code_entities_match = array('#<#', '#>#', '#"#', '#:#', '#\[#', '#\]#', '#\(#', '#\)#', '#\{#', '#\}#'); + $code_entities_replace = array('<', '>', '"', ':', '[', ']', '(', ')', '{', '}'); + $between_tags = preg_replace($code_entities_match, $code_entities_replace, $between_tags); + } + if ($open_tag[0] == '[html]') + { + $code_entities_match = array('#<#', '#>#', '#"#', '#:#', '#\[#', '#\]#', '#\(#', '#\)#', '#\{#', '#\}#'); + $code_entities_replace = array('<', '>', '"', ':', '[', ']', '(', ')', '{', '}'); + $between_tags = preg_replace($code_entities_match, $code_entities_replace, $between_tags); + } + $text = $before_start_tag . substr($start_tag, 0, $start_length - 1) . ":$curr_nesting_depth:$uid]"; + $text .= $between_tags . substr($close_tag_new, 0, $close_tag_new_length - 1) . ":$curr_nesting_depth:$uid]"; + } $text .= $after_end_tag; // Now.. we've screwed up the indices by changing the length of the string. @@ -804,7 +903,56 @@ function bbencode_second_pass_code($text, $uid, $bbcode_tpl) return $text; } // bbencode_second_pass_code() + + /** + * Rewritten by Florin C Bodin - August 2, 2018. + */ + function bbencode_second_pass_html($text, $uid, $bbcode_tpl) + { + global $lang; + + $html_start_html = $bbcode_tpl['html_open']; + $html_end_html = $bbcode_tpl['html_close']; + + // First, do all the 1st-level matches. These need an htmlspecialchars() run, + // so they have to be handled differently. + $match_count = preg_match_all("#\[html:1:$uid\](.*?)\[/html:1:$uid\]#si", $text, $matches); + + for ($i = 0; $i < $match_count; $i++) + { + $before_replace = $matches[1][$i]; + $after_replace = $matches[1][$i]; + + // Replace 2 spaces with " " so non-tabbed table indents without making huge long lines. + $after_replace = str_replace(" ", " ", $after_replace); + // now Replace 2 spaces with " " to catch odd #s of spaces. + $after_replace = str_replace(" ", " ", $after_replace); + + // Replace tabs with " " so tabbed table indents sorta right without making huge long lines. + $after_replace = str_replace("\t", " ", $after_replace); + + // now Replace space occurring at the beginning of a line + $after_replace = preg_replace("/^ {1}/m", ' ', $after_replace); + + $str_to_match = "[html:1:$uid]" . $before_replace . "[/html:1:$uid]"; + + $replacement = $html_start_html; + + $replacement .= $after_replace; + + $replacement .= $html_end_html; + + $text = str_replace($str_to_match, $replacement, $text); + } + + // Now, do all the non-first-level matches. These are simple. + $text = str_replace("[html:$uid]", $html_start_html, $text); + $text = str_replace("[/html:$uid]", $html_end_html, $text); + return $text; + + } // bbencode_second_pass_html() + //phpBB Temporary code ends /** diff --git a/includes/mx_functions_blockcp.php b/includes/mx_functions_blockcp.php index 41df5bd6..b68474b4 100644 --- a/includes/mx_functions_blockcp.php +++ b/includes/mx_functions_blockcp.php @@ -421,7 +421,7 @@ function _controlpanel($id, $new_block = false) /* * PRIVATE auth */ - + $groupdata = array(); // Get the list of phpBB usergroups $sql = $mx_backend->generate_group_select_sql(); if( !($result = $db->sql_query($sql)) ) @@ -441,7 +441,7 @@ function _controlpanel($id, $new_block = false) $moderator_groups = @explode(',', $this->block_info['auth_moderator_group']); $row_private = ''; - for( $i = 0; $i < count($groupdata); $i++ ) + for( $i = 0; $i < $count = count($groupdata); $i++ ) { $row_color = ( !( $i % 2 ) ) ? 'row1' : 'row2'; $row_private .= ''; diff --git a/includes/mx_functions_core.php b/includes/mx_functions_core.php index 56a07053..87752a0b 100644 --- a/includes/mx_functions_core.php +++ b/includes/mx_functions_core.php @@ -74,19 +74,19 @@ class mx_cache extends cache */ public function __construct() { - global $mx_root_path, $phpbb_root_path, $phpEx; + global $mx_root_path, $phpbb_root_path; global $db, $portal_config; global $mx_table_prefix, $table_prefix, $phpEx, $tplEx; global $mx_backend, $phpbb_auth, $mx_bbcode; - $this->path = $mx_root_path; + $this->path = ($mx_root_path) ? $mx_root_path : './'; + $this->php_ext = $phpEx; + $this->cache_dir = $mx_root_path . 'cache/'; $this->backend = $mx_backend; $this->backend_path = $phpbb_root_path; $this->db = $db; $this->config = $portal_config; - $this->php_ex = $phpEx; - $this->tpl_ex = $tplEx; - $this->cache_dir = $mx_root_path . 'cache/'; + $this->tpl_ext = $tplEx; $this->prefix = $mx_table_prefix; } @@ -118,14 +118,16 @@ public function load_backend($portal_backend = false) // Overwrite Backend $this->portal_config = $portal_config; - + if (($portal_config['portal_backend']) && @file_exists($portal_config['portal_backend_path'] . "index.$phpEx")) + { + $this->backend_path = (!$portal_config['portal_backend_path']) ? $this->backend_path : $portal_config['portal_backend_path']; + } if ($this->backend) { $portal_config['portal_backend'] = $this->backend; } - - // No backend defined ? Portal not updated to v. 3 ? - if ((!$portal_config['portal_backend']) && @file_exists($this->phpbb_path . "profile.$phpEx")) + // No backend defined ? MXP-CMS not updated to v. 3 ? + if ((!$portal_config['portal_backend']) && @file_exists($this->backend_path . "profile.$phpEx")) { $portal_config['portal_backend'] = 'phpbb2'; $portal_config['portal_backend_path'] = $this->backend_path; @@ -139,10 +141,8 @@ public function load_backend($portal_backend = false) } // Load backend $mx_root_path = $this->path; - $phpbb_root_path = $this->backend_path; - $phpEx = $this->php_ex; - $tplEx = $this->tpl_ex; - require($this->path . 'includes/sessions/'.$portal_config['portal_backend'].'/core.'. $this->php_ex); + $phpbb_root_path = $this->backend_path; + require($this->path . 'includes/sessions/'.$portal_config['portal_backend'].'/core.'. $this->php_ext); //Redirect to upgrade or redefine portal backend path if (!$portal_config['portal_backend_path']) @@ -186,6 +186,46 @@ public function load_backend($portal_backend = false) require($mx_root_path . 'includes/sessions/'.PORTAL_BACKEND.'/constants.' . $phpEx); } + /** + * Enter description here... + * + * @access public + * @param boolean $use_cache + * @return unknown + */ + function obtain_phpbb_config($use_cache = true) + { + global $db; + + if (($config = $this->get('phpbb_config')) && $use_cache) + { + return $config; + } + else + { + $sql = "SELECT * + FROM " . CONFIG_TABLE; + + if ( !( $result = $db->sql_query( $sql ) ) ) + { + mx_message_die( GENERAL_ERROR, 'Couldnt query config information', '', __LINE__, __FILE__, $sql ); + } + + while ( $row = $db->sql_fetchrow($result) ) + { + $config[$row['config_name']] = $row['config_value']; + } + $db->sql_freeresult($result); + + if ($use_cache) + { + $this->put('phpbb_config', $config); + } + + return ( $config ); + } + } + /** * Get MX-Publisher config data * @@ -250,7 +290,6 @@ public function obtain_mxbb_config($use_cache = true) public function load_file($file = '', $force_shared = false) { global $mx_root_path, $phpbb_root_path, $phpEx, $mx_page, $mx_backend; - /* * Remember loaded files */ @@ -258,11 +297,11 @@ public function load_file($file = '', $force_shared = false) { return; } - + $mx_page->loaded_files[] = $file . (is_string($force_shared) ? $force_shared : ''); - + $path = $mx_backend->load_file($force_shared); - + if (file_exists($path . $file.'.'.$phpEx)) { @include_once($path . $file.'.'.$phpEx); @@ -276,13 +315,13 @@ public function load_file($file = '', $force_shared = false) public function init_mod_rewrite() { global $portal_config, $mx_root_path, $phpEx, $mx_mod_rewrite; - + if ($portal_config['mod_rewrite']) { if ( file_exists( $mx_root_path . 'modules/mx_mod_rewrite/includes/rewrite_functions.' . $phpEx ) ) { include_once( $mx_root_path . 'modules/mx_mod_rewrite/includes/rewrite_functions.' . $phpEx ); - + if (class_exists('mx_mod_rewrite')) { $mx_mod_rewrite = new mx_mod_rewrite(); @@ -306,7 +345,7 @@ public function init_mod_rewrite() public function _read_config($id = 1, $sub_id = 0, $type, $force_query = false) { global $portal_config, $mx_root_path; - + switch ($type) { case MX_CACHE_BLOCK_TYPE: @@ -502,7 +541,169 @@ public function _get_block_config($id = '', $sub_id = 0) unset($row); $db->sql_freeresult($result); } + // -------------------------------------------------------------------GET DATA + // Read the variable block configuration + function block_config($id = '', $sub_id = 0, $config = '') + { + global $db; + + $this->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, mdl.module_name, + fnc.function_file, fnc.function_id, 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_id = $row['block_id']; + + $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'], + "module_name" => $row['module_name'], + "block_file" => $row['function_file'], + "block_edit_file" => $row['function_admin'], + "function_id" => $row['function_id'] + ); + + $this->block_config[$block_id]['block_info'] = $block_row; + } + + $db->sql_freeresult($result); + $sql_block = !empty( $id ) ? ' AND sys.block_id = ' . $id : ''; + $sql_sub = !empty( $sub_id ) ? ' AND sys.sub_id = ' . $sub_id : ' AND sys.sub_id = 0'; + + // Generate block parameter data + $sql = "SELECT blk.*, + sys.parameter_id, sys.parameter_value, sys.parameter_opt, + par.*, + mdl.module_path, mdl.module_name, + bct.column_id, + fnc.function_file, fnc.function_id, fnc.function_admin + FROM " . BLOCK_SYSTEM_PARAMETER_TABLE . " sys, + " . PARAMETER_TABLE . " par, + " . BLOCK_TABLE . " blk, + " . FUNCTION_TABLE . " fnc, + " . MODULE_TABLE . " mdl, + " . COLUMN_BLOCK_TABLE . " bct + 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 .= $sql_sub; + $sql .= " ORDER BY sys.block_id, par.parameter_order"; + + 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'], + "module_name" => $row['module_name'], + "block_file" => $row['function_file'], + "block_edit_file" => $row['function_admin'], + "function_id" => $row['function_id'] + ); + + $param_row = array( + "parameter_id" => $row['parameter_id'], + "function_id" => $row['function_id'], + "parameter_name" => $row['parameter_name'], + "parameter_type" => $row['parameter_type'], + "parameter_auth" => $row['parameter_auth'], + "parameter_value" => $row['parameter_value'], + "parameter_default" => $row['parameter_default'], + "parameter_function" => $row['parameter_function'], + "parameter_opt" => $row['parameter_opt'], + "parameter_order" => $row['parameter_order'] + ); + + if ( $next_block ) + { + $temp_row = array(); + $temp_row = array( 'block_info' => $block_row ); + } + + $temp_row['block_parameters'][$param_row['parameter_name']] = $param_row; + // + // Compose the pages config array + // + $this->block_config[$block_id] = $temp_row; + } + unset($row); + $db->sql_freeresult($result); + + switch($config) + { + case 'block_info': + return $block_row; + break; + + case 'block_parameters': + return $param_row; + break; + + case 'block_config': + return $this->block_config; + break; + + default: + return $this->block_config; + break; + } + } /** * Query page data * @@ -1040,13 +1241,16 @@ public function _write($filename, $data = null, $expires = 0, $query = '') fclose($handle); - if (!function_exists('mx_chmod')) + if (!function_exists('mx3_chmod')) { - global $mx_root_path; - include($mx_root_path . 'includes/mx_functions.' . $phpEx); + //global $mx_root_path; + //include($mx_root_path . 'includes/mx_functions.' . $phpEx); + mx_chmod($file, CHMOD_READ | CHMOD_WRITE); + } + else + { + mx3_chmod($file, CHMOD_READ | CHMOD_WRITE); } - - mx_chmod($file, CHMOD_READ | CHMOD_WRITE); $return_value = true; } @@ -1140,10 +1344,10 @@ class cache */ public function __construct() { - global $mx_root_path, $phpEx; + global $mx_root_path; - $this->path = $mx_root_path; - $this->php_ext = $phpEx; + $this->path = ($mx_root_path) ? $mx_root_path : './'; + $this->php_ext = substr(strrchr(__FILE__, '.')); $this->cache_dir = $mx_root_path . 'cache/'; } @@ -1389,12 +1593,12 @@ public function sql_save($query, &$query_result, $ttl) public function sql2_save($query, &$query_result, $ttl) { global $db, $phpEx; - + // Remove extra spaces and tabs $query = preg_replace('/[\n\r\s\t]+/', ' ', $query); $hash = md5($query); - if ($fp = @fopen($this->cache_dir . 'sql_' . md5($query) . '.' . $phpEx, 'wb')) + if ($fp = @fopen($this->cache_dir . 'sql_' . md5($query) . '.' . $this->php_ext, 'wb')) { @flock($fp, LOCK_EX); @@ -1459,8 +1663,8 @@ public function _exists($var_name) { if ($var_name{0} == '_') { - global $phpEx; - return file_exists($this->cache_dir . 'data' . $var_name . ".$phpEx"); + $phpEx = substr(strrchr(__FILE__, '.'), 1); + return file_exists($this->cache_dir . 'data' . $var_name . "." . $phpEx); } else { @@ -1586,8 +1790,7 @@ public function put($var_name, $var, $ttl = 31536000) { if ($var_name{0} == '_') { - global $phpEx; - + $phpEx = substr(strrchr(__FILE__, '.'), 1); if ($fp = @fopen($this->cache_dir . 'data' . $var_name . ".$phpEx", 'wb')) { @flock($fp, LOCK_EX); @@ -1617,8 +1820,7 @@ public function put($var_name, $var, $ttl = 31536000) */ public function destroy($var_name, $table = '') { - global $phpEx; - + $phpEx = substr(strrchr(__FILE__, '.'), 1); if ($var_name == 'sql' && !empty($table)) { $regex = '(' . ((is_array($table)) ? implode('|', $table) : $table) . ')'; @@ -1652,7 +1854,7 @@ public function destroy($var_name, $table = '') if ($var_name{0} == '_') { - @unlink($this->cache_dir . 'data' . $var_name . ".$phpEx"); + @unlink($this->cache_dir . 'data' . $var_name . "." . $phpEx); } else if (isset($this->vars[$var_name])) { @@ -1816,8 +2018,8 @@ class mx_block extends mx_block_parameter * @access public * @var string */ - var $function_id = ''; - var $block_id = ''; + var $function_id = 0; + var $block_id = 0; var $block_title = ''; var $block_desc = ''; /**#@-*/ @@ -1841,8 +2043,9 @@ class mx_block extends mx_block_parameter * @access public * @var string */ - var $module_root_path = ''; - var $block_file = ''; + var $module_root_path = 'modules/mx_coreblocks/'; + var $php_ext = 'php7'; + var $block_file = 'app.php5'; var $block_edit_file = ''; /**#@-*/ @@ -1851,7 +2054,7 @@ class mx_block extends mx_block_parameter * * @access public */ - var $virtual_id = ''; + var $virtual_id = 0; var $block_virtual_parameters = array(); /**#@-*/ @@ -1860,7 +2063,7 @@ class mx_block extends mx_block_parameter * * @access public */ - var $dynamic_block_id = ''; + var $dynamic_block_id = 0; var $is_dynamic = false; /**#@-*/ @@ -1869,7 +2072,7 @@ class mx_block extends mx_block_parameter * * @access public */ - var $total_subs = ''; + var $total_subs = 0; var $sub_block_ids = ''; var $sub_block_sizes = ''; var $sub_inner_space = ''; @@ -1904,9 +2107,9 @@ class mx_block extends mx_block_parameter */ public function _set_all() { - global $userdata, $lang; + global $mx_user, $userdata, $lang; - $is_admin = ($userdata['user_level'] == ADMIN && $userdata['session_logged_in']) ? true : 0; + $is_admin = ($mx_user->data['user_level'] == ADMIN && $mx_user->data['session_logged_in']) ? true : 0; // Weird rewrite for php5 - anyone explaining why wins a medal ;) $temp_row = isset($this->block_config[$this->block_id]) ? $this->block_config[$this->block_id] : false; @@ -2000,7 +2203,7 @@ public function _is_dynamic() { global $mx_request_vars, $phpEx; - $is_dynamic = ( ( $this->block_file == 'mx_dynamic.' . $phpEx ) ? true : false ); + $is_dynamic = ( ( $this->block_file == 'mx_dynamic.' . $this->php_ext ) ? true : false ); if ( $is_dynamic ) { @@ -2019,7 +2222,8 @@ public function _is_dynamic() public function _is_sub() { global $phpEx; - $is_sub = ( ( $this->block_file == 'mx_multiple_blocks.' . $phpEx ) ? true : false ); + + $is_sub = ( ( $this->block_file == 'mx_multiple_blocks.' . $this->php_ext ) ? true : false ); if ( $is_sub ) { @@ -2153,10 +2357,7 @@ public function virtual_create($virtual_id = '', $project_name = '') } $db->sql_freeresult($result); } - - } - $mx_cache->_read_config($this->block_id, $virtual_id, MX_CACHE_BLOCK_TYPE); } @@ -2184,7 +2385,6 @@ public function virtual_update($virtual_id = '', $project_name = '') } $db->sql_freeresult($result); } - $mx_cache->update(MX_CACHE_BLOCK_TYPE, $this->block_id, $virtual_id); } @@ -2280,7 +2480,7 @@ public function output_full_page() { global $layouttemplate, $mx_page; - mx_message_die(GENERAL_MESSAGE,$this->block_contents); + mx_message_die(GENERAL_MESSAGE, $this->block_contents); } /** @@ -2289,18 +2489,18 @@ public function output_full_page() */ public function output_stats() { - global $layouttemplate, $board_config, $lang, $userdata; + global $layouttemplate, $board_config, $lang, $mx_user, $phpBB2, $userdata; if ( $this->show_stats && !empty($this->block_time) && !empty($this->editor_id) ) { - $is_admin = ( $userdata['user_level'] == ADMIN && $userdata['session_logged_in'] ) ? TRUE : 0; + $is_admin = ($mx_user->data['user_level'] == ADMIN && $mx_user->data['session_logged_in'] ) ? TRUE : 0; $editor_name_tmp = mx_get_userdata($this->editor_id); $editor_name = $editor_name_tmp['username']; - $edit_time = phpBB2::create_date( $board_config['default_dateformat'], $this->block_time, $board_config['board_timezone'] ); + $edit_time = $phpBB2->create_date( $board_config['default_dateformat'], $this->block_time, $board_config['board_timezone'] ); $layouttemplate->assign_block_vars('layout_column.blocks.block_stats', array( 'L_BLOCK_UPDATED' => $lang['Block_updated_date'], - 'EDITOR_NAME' => $is_admin ? $lang['Block_updated_by'] . $editor_name : '', + 'EDITOR_NAME' => $is_admin ? $lang['Block_updated_by'] . ' ' . $editor_name : '', 'EDIT_TIME' => $edit_time )); } @@ -2344,7 +2544,7 @@ public function output_title() */ public function output_cp_button($overall_header = false) { - global $layouttemplate, $userdata, $mx_root_path, $mx_page, $lang, $block_size, $images, $phpEx; + global $layouttemplate, $mx_user, $userdata, $mx_root_path, $mx_page, $lang, $block_size, $images, $phpEx; // // Define some hidden Edit Block parameters @@ -2376,7 +2576,7 @@ public function output_cp_button($overall_header = false) // Compose buttons and info // $block_desc = !empty( $this->block_desc ) ? ' (' . $this->block_desc . ')' : ''; - $edit_url = mx_append_sid( $mx_root_path . $edit_file . "?sid=" . $userdata['session_id'] ); + $edit_url = mx_append_sid($mx_root_path . $edit_file . "?sid=" . $mx_user->data['session_id']); $edit_img = ''; $this->virtual_id = isset($this->virtual_id) ? $this->virtual_id : ''; //Virtual Id is Not Set ? @@ -2389,9 +2589,13 @@ public function output_cp_button($overall_header = false) // Output // $temp_array = array( - 'BLOCK_SIZE' => ( !empty( $block_size ) ? $block_size : '100%' ), + 'BLOCK_SIZE' => (!empty($block_size) ? $block_size : '100%'), 'EDIT_ACTION' => $edit_url, 'EDIT_IMG' => $edit_img, + 'EDIT_BLOCK_ALT' => $block_edit_alt, + 'EDIT_BLOCK_TITLE' => $this->block_title, + 'EDIT_BLOCK_DESC' => $block_desc, + 'EDIT_IMG_SRC' => $block_edit_img, 'EDITCP_SHOW' => $mx_page->editcp_show ? '' : 'none', 'S_HIDDEN_FORM_FIELDS' => $s_hidden_fields ); @@ -2436,7 +2640,7 @@ public function get_parameters($key = MX_GET_ALL_PARS, $mode = MX_GET_PAR_VALUE) global $mx_request_vars; $block_config_temp = ''; - + if ($key == MX_GET_ALL_PARS) { return array_merge($this->block_info, $this->block_parameters); @@ -2446,7 +2650,32 @@ public function get_parameters($key = MX_GET_ALL_PARS, $mode = MX_GET_PAR_VALUE) { return $this->block_parameters[$key]['parameter_opt']; } - + /** **/ + if (!isset($this->block_parameters[$key]['parameter_value'])) + { + $keys = (array) $key; + + foreach ($keys as $key) + { + $level = 0; + if (is_array($key)) + { + $pars_key = $key[0]; + $param_key = $key[1]; + if (count($key) > 2) + { + $level = $key[2]; + } + } + else + { + $pars_key = $key; + $param_key = $keys[0]; + } + $key = trim($pars_key); + } + } + /** **/ return !empty($this->virtual_id) ? $this->block_virtual_parameters[$key]['parameter_value'] : $this->block_parameters[$key]['parameter_value']; } @@ -2466,20 +2695,20 @@ public function auth($type) case AUTH_ALL: $auth_fields = array('auth_view', 'auth_edit'); $auth_fields_groups = array('auth_view_group', 'auth_edit_group'); - break; + break; case AUTH_VIEW: $auth_fields = array('auth_view'); $auth_fields_groups = array('auth_view_group'); - break; + break; case AUTH_EDIT: $auth_fields = array('auth_edit'); $auth_fields_groups = array('auth_edit_group'); - break; + break; default: - break; + break; } $auth_user = array(); @@ -2522,27 +2751,27 @@ public function auth($type) case AUTH_ALL: $auth_user[$auth_fields[$i]] = TRUE; $auth_user[$auth_fields[$i] . '_type'] = $lang['Auth_Anonymous_Users']; - break; + break; case AUTH_REG: $auth_user[$auth_fields[$i]] = ( $userdata['session_logged_in'] ) ? TRUE : 0; $auth_user[$auth_fields[$i] . '_type'] = $lang['Auth_Registered_Users']; - break; + break; case AUTH_ANONYMOUS: $auth_user[$auth_fields[$i]] = ( ! $userdata['session_logged_in'] ) ? TRUE : 0; $auth_user[$auth_fields[$i] . '_type'] = $lang['Auth_Anonymous_Users']; - break; + break; case AUTH_ACL: // PRIVATE $auth_user[$auth_fields[$i]] = ( $userdata['session_logged_in'] ) ? mx_is_group_member($this->block_info[$auth_fields_groups[$i]]) || $is_admin : 0; $auth_user[$auth_fields[$i] . '_type'] = $lang['Auth_Users_granted_access']; - break; + break; case AUTH_MOD: $auth_user[$auth_fields[$i]] = ( $userdata['session_logged_in'] ) ? mx_is_group_member($this->block_info['auth_moderator_group']) || $is_admin : 0; $auth_user[$auth_fields[$i] . '_type'] = $lang['Auth_Moderators']; - break; + break; case AUTH_ADMIN: $auth_user[$auth_fields[$i]] = $is_admin; @@ -2551,7 +2780,7 @@ public function auth($type) default: $auth_user[$auth_fields[$i]] = 0; - break; + break; } } @@ -2562,9 +2791,136 @@ public function auth($type) return $auth_user; } -} // class mx_block + + /** + * Block authb extend + * + * @access private + * @param integer $type all, view or edit + * @return array + */ + 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; + } +} // class mx_block + +/** * Class: mx_block_parameter. * * This is the CORE mx_block_parameter object. @@ -2723,36 +3079,36 @@ public function submit_parameters( $block_id = false ) case 'Text': case 'TextArea': $parameter_value = htmlspecialchars( trim( $parameter_value ) ); - break; + break; case 'BBText': $bbcode_uid = $parameter_opt = $mx_bbcode->make_bbcode_uid(); $parameter_value = $mx_bbcode->prepare_message($parameter_value, true, true, true, $bbcode_uid); - break; + break; case 'Html': $parameter_value = $mx_bbcode->prepare_message($parameter_value, true, false, false); - break; + break; case 'Number': $parameter_value = intval($parameter_value); - break; + break; case 'Function': if( is_array($parameter_value) ) { //$parameter_value = implode(',' , htmlspecialchars($parameter_value)); $parameter_value = implode(',' , $parameter_value); } - break; + break; // Custom Fields case 'Radio_single_select': case 'Menu_single_select': $parameter_value = htmlspecialchars( trim( $parameter_value ) ); - break; + break; case 'Menu_multiple_select': case 'Checkbox_multiple_select': $parameter_value = addslashes( serialize( $parameter_value ) ); - break; + break; case 'Separator': - break; + break; default: $parameter_custom = $this->_submit_custom_module_parameters($parameter_data, $block_id); @@ -2816,8 +3172,6 @@ public function submit_parameters( $block_id = false ) // $mx_cache->update(MX_CACHE_BLOCK_TYPE, $block_id, $sub_id); // Maybe ambitious, but why not ;) $message .= $lang['AdminCP_action'] . ": " . $lang['Block'] . ' ' . $lang['was_updated']; - - } return $message; } @@ -2853,42 +3207,42 @@ public function load_block_parameters( $block_id = false ) { case 'Separator': $this->display_edit_Separator( $block_id, $parameter_data['parameter_id'], $parameter_data ); - break; + break; case 'Text': $this->display_edit_PlainTextField( $block_id, $parameter_data['parameter_id'], $parameter_data ); - break; + break; case 'TextArea': $this->display_edit_PlainTextAreaField( $block_id, $parameter_data['parameter_id'], $parameter_data ); - break; + break; case 'BBText': $this->display_edit_BBText( $block_id, $parameter_data['parameter_id'], $parameter_data ); - break; + break; case 'Html': $this->display_edit_Html( $block_id, $parameter_data['parameter_id'], $parameter_data ); - break; + break; case 'Boolean': $this->display_edit_Boolean( $block_id, $parameter_data['parameter_id'], $parameter_data ); - break; + break; case 'Number': $this->display_edit_Number( $block_id, $parameter_data['parameter_id'], $parameter_data ); break; case 'Function': $this->display_edit_Function( $block_id, $parameter_data['parameter_id'], $parameter_data ); - break; + break; // Custom Fields case 'Radio_single_select': $this->display_edit_Radio_single_select( $block_id, $parameter_data['parameter_id'], $parameter_data ); - break; + break; case 'Menu_single_select': $this->display_edit_Menu_single_select( $block_id, $parameter_data['parameter_id'], $parameter_data ); - break; + break; case 'Menu_multiple_select': $this->display_edit_Menu_multiple_select( $block_id, $parameter_data['parameter_id'], $parameter_data ); - break; + break; case 'Checkbox_multiple_select': $this->display_edit_Checkbox_multiple_select( $block_id, $parameter_data['parameter_id'], $parameter_data ); - break; + break; default: $module_root_path = $mx_root_path . $this->module_root_path; $this->is_panel = $this->_get_custom_module_parameters($parameter_data, $block_id); @@ -2948,7 +3302,6 @@ public function display_edit_Separator( $block_id, $parameter_id, $parameter_dat 'PARAMETER_TYPE' => ( !empty($lang["ParType_".$parameter_data['parameter_type']]) ) ? $lang["ParType_".$parameter_data['parameter_type']] : '', 'PARAMETER_TYPE_INFO' => ( !empty($lang["ParType_".$parameter_data['parameter_type'] . "_info"]) ) ? ' :: ' . $lang["ParType_".$parameter_data['parameter_type'] . "_info"] : '' )); - $template->pparse('parameter'); } @@ -2977,7 +3330,6 @@ public function display_edit_PlainTextField( $block_id, $parameter_id, $paramete 'PARAMETER_TYPE_INFO' => ( !empty($lang["ParType_".$parameter_data['parameter_type'] . "_info"]) ) ? ' :: ' . $lang["ParType_".$parameter_data['parameter_type'] . "_info"] : '', 'PARAMETER_FIELD' => $parameter_field )); - $template->pparse('parameter'); } @@ -3006,7 +3358,6 @@ public function display_edit_PlainTextAreaField( $block_id, $parameter_id, $para 'PARAMETER_TYPE_INFO' => ( !empty($lang["ParType_".$parameter_data['parameter_type'] . "_info"]) ) ? ' :: ' . $lang["ParType_".$parameter_data['parameter_type'] . "_info"] : '', 'PARAMETER_FIELD' => $parameter_field )); - $template->pparse('parameter'); } @@ -3039,7 +3390,6 @@ public function display_edit_BBText( $block_id, $parameter_id, $parameter_data ) 'PARAMETER_TYPE_INFO' => ( !empty($lang["ParType_".$parameter_data['parameter_type'] . "_info"]) ) ? ' :: ' . $lang["ParType_".$parameter_data['parameter_type'] . "_info"] : '', 'PARAMETER_FIELD' => $parameter_field )); - $template->pparse('parameter'); } @@ -3068,7 +3418,6 @@ public function display_edit_Html( $block_id, $parameter_id, $parameter_data ) 'PARAMETER_TYPE_INFO' => ( !empty($lang["ParType_".$parameter_data['parameter_type'] . "_info"]) ) ? ' :: ' . $lang["ParType_".$parameter_data['parameter_type'] . "_info"] : '', 'PARAMETER_FIELD' => $parameter_field )); - $template->pparse('parameter'); } @@ -3097,7 +3446,6 @@ public function display_edit_Number( $block_id, $parameter_id, $parameter_data ) 'PARAMETER_TYPE_INFO' => ( !empty($lang["ParType_".$parameter_data['parameter_type'] . "_info"]) ) ? ' :: ' . $lang["ParType_".$parameter_data['parameter_type'] . "_info"] : '', 'PARAMETER_FIELD' => $parameter_field )); - $template->pparse('parameter'); } @@ -3136,7 +3484,6 @@ public function display_edit_Boolean( $block_id, $parameter_id, $parameter_data 'PARAMETER_TYPE_INFO' => ( !empty($lang["ParType_".$parameter_data['parameter_type'] . "_info"]) ) ? ' :: ' . $lang["ParType_".$parameter_data['parameter_type'] . "_info"] : '', 'PARAMETER_FIELD' => $parameter_field )); - $template->pparse('parameter'); } @@ -3167,7 +3514,6 @@ public function display_edit_Function( $block_id, $parameter_id, $parameter_data 'PARAMETER_TYPE_INFO' => ( !empty($lang["ParType_".$parameter_data['parameter_type'] . "_info"]) ) ? ' :: ' . $lang["ParType_".$parameter_data['parameter_type'] . "_info"] : '', 'PARAMETER_FIELD' => $parameter_field )); - $template->pparse('parameter'); } @@ -3190,14 +3536,14 @@ public function display_edit_Radio_single_select( $block_id, $parameter_id, $par 'parameter' => 'admin/mx_core_parameters.tpl') ); - $template->assign_block_vars( 'radio', array( + $template->assign_block_vars('radio', array( 'PARAMETER_TITLE' => ( !empty($lang[$parameter_data['parameter_name']]) ) ? $lang[$parameter_data['parameter_name']] : $parameter_data['parameter_name'], 'PARAMETER_TITLE_EXPLAIN' => ( !empty($lang[$parameter_data['parameter_name']. "_explain"]) ) ? '
' . $lang[$parameter_data['parameter_name']. "_explain"] : '', 'FIELD_NAME' => ( !empty($lang[$parameter_data['parameter_name']]) ) ? $lang[$parameter_data['parameter_name']] : $parameter_data['parameter_name'], 'FIELD_ID' => $parameter_data['parameter_id'], 'FIELD_DESCRIPTION' => ( !empty($lang["ParType_".$parameter_data['parameter_type']]) ) ? $lang["ParType_".$parameter_data['parameter_type']] : '' - )); + )); if ( !empty( $parameter_datas ) ) { @@ -3208,7 +3554,6 @@ public function display_edit_Radio_single_select( $block_id, $parameter_id, $par ); } } - $template->pparse('parameter'); } @@ -3230,16 +3575,14 @@ public function display_edit_Menu_single_select( $block_id, $parameter_id, $para $template->set_filenames(array( 'parameter' => 'admin/mx_core_parameters.tpl') ); - - $template->assign_block_vars( 'select', array( + $template->assign_block_vars('select', array( 'PARAMETER_TITLE' => ( !empty($lang[$parameter_data['parameter_name']]) ) ? $lang[$parameter_data['parameter_name']] : $parameter_data['parameter_name'], 'PARAMETER_TITLE_EXPLAIN' => ( !empty($lang[$parameter_data['parameter_name']. "_explain"]) ) ? '
' . $lang[$parameter_data['parameter_name']. "_explain"] : '', 'FIELD_NAME' => ( !empty($lang[$parameter_data['parameter_name']]) ) ? $lang[$parameter_data['parameter_name']] : $parameter_data['parameter_name'], 'FIELD_ID' => $parameter_data['parameter_id'], 'FIELD_DESCRIPTION' => ( !empty($lang["ParType_".$parameter_data['parameter_type']]) ) ? $lang["ParType_".$parameter_data['parameter_type']] : '' - )); - + )); if ( !empty( $parameter_datas ) ) { foreach( $parameter_datas as $key => $value ) @@ -3249,7 +3592,6 @@ public function display_edit_Menu_single_select( $block_id, $parameter_id, $para ); } } - $template->pparse('parameter'); } @@ -3271,13 +3613,11 @@ public function display_edit_Menu_multiple_select( $block_id, $parameter_id, $pa $template->set_filenames(array( 'parameter' => 'admin/mx_core_parameters.tpl') ); - $template->assign_block_vars( 'select_multiple', array( 'FIELD_NAME' => ( !empty($lang[$parameter_data['parameter_name']]) ) ? $lang[$parameter_data['parameter_name']] : $parameter_data['parameter_name'], 'FIELD_ID' => $parameter_data['parameter_id'], 'FIELD_DESCRIPTION' => ( !empty($lang["ParType_".$parameter_data['parameter_type']]) ) ? $lang["ParType_".$parameter_data['parameter_type']] : '' - )); - + )); if ( !empty( $parameter_datas ) ) { foreach( $parameter_datas as $key => $value ) @@ -3299,7 +3639,6 @@ public function display_edit_Menu_multiple_select( $block_id, $parameter_id, $pa ); } } - $template->pparse('parameter'); } @@ -3352,7 +3691,6 @@ public function display_edit_Checkbox_multiple_select( $block_id, $parameter_id, ); } } - $template->pparse('parameter'); } @@ -3590,18 +3928,56 @@ public function modified( $true_false = false ) */ public function _set_all() { - global $userdata, $mx_root_path, $mx_request_vars, $portal_config, $theme, $lang; + global $mx_user, $db, $userdata, $board_config, $mx_root_path, $_COOKIE, $portal_config, $theme, $lang, $mx_request_vars; global $mx_block, $tplEx, $_GET; $this->info = &$this->page_config[$this->page_id]['page_info']; - $is_admin = ($userdata['user_level'] == ADMIN && $userdata['session_logged_in']) ? true : 0; + $is_admin = ($mx_user->data['user_level'] == ADMIN && $mx_user->data['session_logged_in']) ? true : 0; /* * IP filter */ $mx_ip = new mx_ip; - + + /* + /* We are trying to setup a style which does not exist in the database + /* Try to fallback to the board default (if the user had a custom style) + /* and then any users using this style to the default if it succeeds + * / + if (($mx_user->data['user_style'] == $board_config['default_style']) || ($mx_user->data['user_id'] == ANONYMOUS)) + { + $sql = 'SELECT template_name + FROM ' . THEMES_TABLE . ' + WHERE themes_id = ' . (int) $board_config['default_style']; + if ($theme = $db->sql_fetchrow($result = $db->sql_query($sql))) + { + $db->sql_freeresult($result); + } + } + else + { + $sql = 'SELECT template_name + FROM ' . THEMES_TABLE . ' + WHERE themes_id = ' . (int) $mx_user->data['user_style']; + if ($theme = $db->sql_fetchrow($result = $db->sql_query($sql))) + { + $db->sql_freeresult($result); + } + } + + if (file_exists($mx_root_path . 'templates/'. $theme['template_name'] . '/template/')) + { + $overall_header_tpl = (($this->page_id != 2) && file_exists($mx_root_path . 'templates/'. $theme['template_name'] . '/template/overall_header_navigation.'.$tplEx)) ? 'overall_header_navigation.'.$tplEx : $portal_config['overall_header']; + $overall_header_tpl = (($this->page_id == 2) && file_exists($mx_root_path . 'templates/'. $theme['template_name'] . '/template/overall_header_navigation_phpbb.'.$tplEx)) ? 'overall_header_navigation_phpbb.'.$tplEx : $overall_header_tpl; + } + else + { + $overall_header_tpl = (($this->page_id != 2) && file_exists($mx_root_path . 'templates/'. $theme['template_name'] . '/overall_header_navigation.'.$tplEx)) ? 'overall_header_navigation.'.$tplEx : $portal_config['overall_header']; + $overall_header_tpl = (($this->page_id == 2) && file_exists($mx_root_path . 'templates/'. $theme['template_name'] . '/overall_header_navigation_phpbb.'.$tplEx)) ? 'overall_header_navigation_phpbb.'.$tplEx : $overall_header_tpl; + } + /* */ + // // General // @@ -3611,17 +3987,20 @@ public function _set_all() $this->default_style = $this->info['default_style'] == -1 ? ($portal_config['default_style']) : ( $this->info['default_style'] ); $this->override_user_style = $this->info['override_user_style'] == -1 ? ($portal_config['override_user_style'] == 1 ? 1 : 0 ) : ( $this->info['override_user_style'] == 1 ? 1 : 0 ); + // // Setup demo style // - if (isset($_GET['strip']) && ($_GET['strip'] == true)) + if (isset($_GET['strip']) && ($mx_request_vars->is_get('strip') == true)) { $this->page_ov_header = 'overall_header_print.'.$tplEx; } else { $this->page_ov_header = !empty($this->info['page_header']) ? $this->info['page_header'] : $portal_config['overall_header']; + //$this->page_ov_header = !empty($this->info['page_header']) ? $this->info['page_header'] : $overall_header_tpl; } + $this->page_ov_footer = !empty($this->info['page_footer']) ? $this->info['page_footer'] : $portal_config['overall_footer']; $this->page_main_layout = !empty($this->info['page_main_layout']) ? $this->info['page_main_layout'] : $portal_config['main_layout']; $this->phpbb_stats = $this->info['phpbb_stats'] == -1 ? ($portal_config['top_phpbb_links'] == 1 ? true : false ) : ( $this->info['phpbb_stats'] == 1 ? true : false ); @@ -3642,7 +4021,7 @@ public function _set_all() $this->block_border_graphics = isset($theme['border_graphics']) ? $theme['border_graphics'] : false; - $s_hidden_fields = ''; + $s_hidden_fields = ''; $s_hidden_fields .= ''; $s_hidden_fields .= ''; $s_hidden_fields .= $mx_request_vars->is_get('f') ? '' : ''; @@ -3653,7 +4032,7 @@ public function _set_all() // // Generate the fold/unfold menu navigation switches (cookie based) // - $this->editcp_show = ( $userdata['user_level'] == ADMIN && isset($_COOKIE['editCP_switch']) ) ? $_COOKIE['editCP_switch'] == 1 : true; + $this->editcp_show = ($mx_user->data['user_level'] == ADMIN && isset($_COOKIE['editCP_switch'])) ? $_COOKIE['editCP_switch'] == 1 : true; $this->is_virtual = isset($this->page_config[$this->page_id]['virtual']) ? $this->page_config[$this->page_id]['virtual'] : false; } @@ -3665,25 +4044,25 @@ public function _set_all() * @param unknown_type $column * @return unknown */ - public function _get_colclass( $column ) + public function _get_colclass($column) { - if ( $this->total_column == 1 ) + if ($this->total_column == 1) { $colclass = 'middlecol'; } else { - switch( $column ) + switch($column) { case 0: $colclass = 'leftcol'; - break; + break; case 1: $colclass = 'middlecol'; - break; + break; case 2: $colclass = 'rightcol'; - break; + break; } } @@ -4020,17 +4399,17 @@ public function auth($auth_data = '', $group_data = '', $moderator_data = '') case AUTH_ALL: $auth_user[$auth_label[$i]] = TRUE; $auth_user[$auth_label[$i] . '_type'] = $lang['Auth_Anonymous_Users']; - break; + break; case AUTH_REG: $auth_user[$auth_label[$i]] = ($userdata['session_logged_in']) ? TRUE : 0; $auth_user[$auth_label[$i] . '_type'] = $lang['Auth_Registered_Users']; - break; + break; case AUTH_ANONYMOUS: $auth_user[$auth_label[$i]] = (!$userdata['session_logged_in']) ? TRUE : 0; $auth_user[$auth_label[$i] . '_type'] = $lang['Auth_Anonymous_Users']; - break; + break; case AUTH_ACL: // PRIVATE $auth_user[$auth_label[$i]] = ($userdata['session_logged_in']) ? mx_is_group_member($group_data) || $is_admin : 0; @@ -4040,16 +4419,16 @@ public function auth($auth_data = '', $group_data = '', $moderator_data = '') case AUTH_MOD: $auth_user[$auth_label[$i]] = ($userdata['session_logged_in']) ? mx_is_group_member($moderator_data) || $is_admin : 0; $auth_user[$auth_label[$i] . '_type'] = $lang['Auth_Moderators']; - break; + break; case AUTH_ADMIN: $auth_user[$auth_label[$i]] = $is_admin; $auth_user[$auth_label[$i] . '_type'] = $lang['Auth_Administrators']; - break; + break; default: $auth_user[$auth_label[$i]] = 0; - break; + break; } } // Is user a moderator? @@ -4057,7 +4436,80 @@ public function auth($auth_data = '', $group_data = '', $moderator_data = '') return $auth_user; } + /** + * Page auth extend. + * + * @access private + * @param unknown_type $auth_data + * @param unknown_type $group_data + * @param unknown_type $moderator_data + * @return array + */ + public function page_auth($type, $userdata, $f_access = '', $f_access_group = '') + { + global $db, $lang, $mx_user; + + $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 = ( $mx_user->data['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; + } } // class mx_page /** @@ -4195,31 +4647,184 @@ public function auth( $mx_page_allowed_ips = '' ) */ class mx_request_vars { + /**#@+ + * Constant identifying the super global with the same name. + */ + const POST = 0; + const GET = 1; + const REQUEST = 2; + const COOKIE = 3; + const SERVER = 4; + const FILES = 5; + /**#@-*/ + // // Implementation Conventions: // Properties and methods prefixed with underscore are intented to be private. ;-) // + + /** + * @var array The names of super global variables that this class should protect if super globals are disabled. + */ + protected $super_globals = array( + self::POST => '_POST', + self::GET => '_GET', + self::REQUEST => '_REQUEST', + self::COOKIE => '_COOKIE', + self::SERVER => '_SERVER', + self::FILES => '_FILES', + ); + + /** + * @var array Stores original contents of $_REQUEST array. + */ + protected $original_request = null; + + /** + * @var + */ + protected $super_globals_disabled = false; + /** + * @var array An associative array that has the value of super global constants as keys and holds their data as values. + */ + protected $input; + + /** + * @var \phpbb\request\type_cast_helper_interface An instance of a type cast helper providing convenience methods for type conversions. + */ + protected $type_cast_helper; + // ------------------------------ // Properties // - // ------------------------------ - // Constructor - // + /* ------------------------------ + * Constructor + * Initialises the request class, that means it stores all input data in {@link $input input} + * and then calls {@link deactivated_super_global deactivated_super_global} + */ + public function __construct($disable_super_globals = false) + { + foreach ($this->super_globals as $const => $super_global) + { + $this->input[$const] = isset($GLOBALS[$super_global]) ? $GLOBALS[$super_global] : array(); + } - // ------------------------------ - // Private Methods - // + // simulate request_order = GP + $this->original_request = $this->input[self::REQUEST]; + $this->input[self::REQUEST] = $this->input[self::POST] + $this->input[self::GET]; + + if ($disable_super_globals) + { + $this->disable_super_globals(); + } + } /** - * Function: _read(). - * - * Get the value of the specified request var (post or get) and force the result to be - * of specified type. It might also transform the result (stripslashes, htmlspecialchars) for security - * purposes. It all depends on the $type argument. - * If the specified request var does not exist, then the default ($dflt) value is returned. - * Note the $type argument behaves as a bit array where more than one option can be specified by OR'ing + * Getter for $super_globals_disabled + * + * @return bool Whether super globals are disabled or not. + */ + public function super_globals_disabled() + { + return $this->super_globals_disabled; + } + + /** + * Disables access of super globals specified in $super_globals. + * This is achieved by overwriting the super globals with instances of {@link \phpbb\request\deactivated_super_global \phpbb\request\deactivated_super_global} + */ + public function disable_super_globals() + { + if (!$this->super_globals_disabled) + { + foreach ($this->super_globals as $const => $super_global) + { + unset($GLOBALS[$super_global]); + $GLOBALS[$super_global] = new deactivated_super_global($this, $super_global, $const); + } + + $this->super_globals_disabled = true; + } + } + + /** + * Enables access of super globals specified in $super_globals if they were disabled by {@link disable_super_globals disable_super_globals}. + * This is achieved by making the super globals point to the data stored within this class in {@link $input input}. + */ + public function enable_super_globals() + { + if ($this->super_globals_disabled) + { + foreach ($this->super_globals as $const => $super_global) + { + $GLOBALS[$super_global] = $this->input[$const]; + } + + $GLOBALS['_REQUEST'] = $this->original_request; + + $this->super_globals_disabled = false; + } + } + + // ------------------------------ + // Public Methods + // + + /** + * This function allows overwriting or setting a value in one of the super global arrays. + * + * Changes which are performed on the super globals directly will not have any effect on the results of + * other methods this class provides. Using this function should be avoided if possible! It will + * consume twice the the amount of memory of the value + * + * @param string $var_name The name of the variable that shall be overwritten + * @param mixed $value The value which the variable shall contain. + * If this is null the variable will be unset. + * @param mx_request_vars::POST|GET|REQUEST|COOKIE $super_global + * Specifies which super global shall be changed + */ + public function overwrite($var_name, $value, $super_global = self::REQUEST) + { + if (!isset($this->super_globals[$super_global])) + { + return; + } + + $this->type_cast_helper->add_magic_quotes($value); + + // setting to null means unsetting + if ($value === null) + { + unset($this->input[$super_global][$var_name]); + if (!$this->super_globals_disabled()) + { + unset($GLOBALS[$this->super_globals[$super_global]][$var_name]); + } + } + else + { + $this->input[$super_global][$var_name] = $value; + if (!$this->super_globals_disabled()) + { + $GLOBALS[$this->super_globals[$super_global]][$var_name] = $value; + } + } + } + + // ------------------------------ + // Private Methods + // + + /** + * Function: _read(). + * + * Get the value of the specified request var (post or get) and force the result to be + * of specified type. It might also transform the result (stripslashes, htmlspecialchars) for security + * purposes. It all depends on the $type argument. + * If the specified request var does not exist, then the default ($dflt) value is returned. + * Note the $type argument behaves as a bit array where more than one option can be specified by OR'ing * the passed argument. This is tipical practice in languages like C, but it can also be done with PHP. * * @access private @@ -4320,6 +4925,152 @@ public function _read($var, $type = MX_TYPE_ANY, $dflt = '', $not_null = false) // Public Methods // + /** + * Central type safe input handling function. + * All variables in GET or POST requests should be retrieved through this function to maximise security. + * + * @param string|array $var_name The form variable's name from which data shall be retrieved. + * If the value is an array this may be an array of indizes which will give + * direct access to a value at any depth. E.g. if the value of "var" is array(1 => "a") + * then specifying array("var", 1) as the name will return "a". + * @param mixed $default A default value that is returned if the variable was not set. + * This function will always return a value of the same type as the default. + * @param bool $multibyte If $default is a string this parameter has to be true if the variable may contain any UTF-8 characters + * Default is false, causing all bytes outside the ASCII range (0-127) to be replaced with question marks + * @param mx_request_vars::POST|GET|REQUEST|COOKIE $super_global + * Specifies which super global should be used + * + * @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the + * the same as that of $default. If the variable is not set $default is returned. + */ + public function variable($var_name, $default, $multibyte = false, $super_global = self::REQUEST) + { + return $this->_variable($var_name, $default, $multibyte, $super_global, true); + } + + /** + * Get a variable, but without trimming strings. + * Same functionality as variable(), except does not run trim() on strings. + * This method should be used when handling passwords. + * + * @param string|array $var_name The form variable's name from which data shall be retrieved. + * If the value is an array this may be an array of indizes which will give + * direct access to a value at any depth. E.g. if the value of "var" is array(1 => "a") + * then specifying array("var", 1) as the name will return "a". + * @param mixed $default A default value that is returned if the variable was not set. + * This function will always return a value of the same type as the default. + * @param bool $multibyte If $default is a string this parameter has to be true if the variable may contain any UTF-8 characters + * Default is false, causing all bytes outside the ASCII range (0-127) to be replaced with question marks + * @param mx_request_vars::POST|GET|REQUEST|COOKIE $super_global + * Specifies which super global should be used + * + * @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the + * the same as that of $default. If the variable is not set $default is returned. + */ + public function untrimmed_variable($var_name, $default, $multibyte = false, $super_global = self::REQUEST) + { + return $this->_variable($var_name, $default, $multibyte, $super_global, false); + } + + /** + * {@inheritdoc} + */ + public function raw_variable($var_name, $default, $super_global = self::REQUEST) + { + $path = false; + + // deep direct access to multi dimensional arrays + if (is_array($var_name)) + { + $path = $var_name; + // make sure at least the variable name is specified + if (empty($path)) + { + return (is_array($default)) ? array() : $default; + } + // the variable name is the first element on the path + $var_name = array_shift($path); + } + + if (!isset($this->input[$super_global][$var_name])) + { + return (is_array($default)) ? array() : $default; + } + $var = $this->input[$super_global][$var_name]; + + if ($path) + { + // walk through the array structure and find the element we are looking for + foreach ($path as $key) + { + if (is_array($var) && isset($var[$key])) + { + $var = $var[$key]; + } + else + { + return (is_array($default)) ? array() : $default; + } + } + } + + return $var; + } + + /** + * Shortcut method to retrieve SERVER variables. + * + * Also fall back to getenv(), some CGI setups may need it (probably not, but + * whatever). + * + * @param string|array $var_name See \phpbb\request\request_interface::variable + * @param mixed $Default See \phpbb\request\request_interface::variable + * + * @return mixed The server variable value. + */ + public function server($var_name, $default = '') + { + $multibyte = true; + + if ($this->is_set($var_name, self::SERVER)) + { + return $this->variable($var_name, $default, $multibyte, self::SERVER); + } + else + { + $var = getenv($var_name); + //$this->type_cast_helper->recursive_set_var($var, $default, $multibyte); + return $var; + } + } + + /** + * Shortcut method to retrieve the value of client HTTP headers. + * + * @param string|array $header_name The name of the header to retrieve. + * @param mixed $default See \phpbb\request\request_interface::variable + * + * @return mixed The header value. + */ + public function header($header_name, $default = '') + { + $var_name = 'HTTP_' . str_replace('-', '_', strtoupper($header_name)); + return $this->server($var_name, $default); + } + + /** + * Shortcut method to retrieve $_FILES variables + * + * @param string $form_name The name of the file input form element + * + * @return array The uploaded file's information or an empty array if the + * variable does not exist in _FILES. + */ + public function file($form_name) + { + return $this->variable($form_name, array('name' => 'none'), true, self::FILES); + } + /** * Request POST variable. * @@ -4333,9 +5084,27 @@ public function _read($var, $type = MX_TYPE_ANY, $dflt = '', $not_null = false) */ public function post($var, $type = MX_TYPE_ANY, $dflt = '', $not_null = false) { - return $this->_read($var, ($type | MX_TYPE_POST_VARS), $dflt, $not_null); + if (!$this->super_globals_disabled()) + { + return $this->_read($var, ($type | MX_TYPE_POST_VARS), $dflt, $not_null); + } + else + { + $super_global = self::POST; + $multibyte = false; //UTF-8 ? + $default = $dflt; + return $this->_variable($var_name, $default, $multibyte, $super_global, true); + } + } - + + /** ** / + public function post($var_name, $default, $multibyte = false, $super_global = self::POST) + { + return $this->_variable($var_name, $default, $multibyte, $super_global, true); + } + /** **/ + /** * Request GET variable. * @@ -4349,9 +5118,27 @@ public function post($var, $type = MX_TYPE_ANY, $dflt = '', $not_null = false) */ public function get($var, $type = MX_TYPE_ANY, $dflt = '', $not_null = false) { - return $this->_read($var, ($type | MX_TYPE_GET_VARS), $dflt, $not_null); - } + if (!$this->super_globals_disabled()) + { + return $this->_read($var, ($type | MX_TYPE_GET_VARS), $dflt, $not_null); + } + else + { + $super_global = self::GET; + $multibyte = false; //UTF-8 ? + $default = $dflt; + return $this->_variable($var_name, $default, $multibyte, $super_global, true); + } + } + + /** ** / + public function get($var_name, $default, $multibyte = false, $super_global = self::GET) + { + return $this->_variable($var_name, $default, $multibyte, $super_global, true); + } + /** **/ + /** * Request GET or POST variable. * @@ -4365,7 +5152,17 @@ public function get($var, $type = MX_TYPE_ANY, $dflt = '', $not_null = false) */ public function request($var, $type = MX_TYPE_ANY, $dflt = '', $not_null = false) { - return $this->_read($var, ($type | MX_TYPE_POST_VARS | MX_TYPE_GET_VARS), $dflt, $not_null); + if (!$this->super_globals_disabled()) + { + return $this->_read($var, ($type | MX_TYPE_POST_VARS | MX_TYPE_GET_VARS), $dflt, $not_null); + } + else + { + $super_global = self::REQUEST; + $multibyte = false; //UTF-8 ? + $default = $dflt; + return $this->_variable($var_name, $default, $multibyte, $super_global, true); + } } /** @@ -4379,8 +5176,8 @@ public function request($var, $type = MX_TYPE_ANY, $dflt = '', $not_null = false */ public function is_post($var) { - // Note: _x and _y are used by (at least IE) to return the mouse position at onclick of INPUT TYPE="img" elements. - return (isset($_POST[$var]) || ( isset($_POST[$var.'_x']) && isset($_POST[$var.'_y']))) ? 1 : 0; + // Note: _x and _y are used by (at least IE) to return the mouse position at onclick of INPUT TYPE="img" elements. + return ($this->is_set_post($var) || $this->is_set_post($var.'_x') && $this->is_set_post($var.'_y')) ? 1 : 0; } /** @@ -4394,7 +5191,8 @@ public function is_post($var) */ public function is_get($var) { - return isset($_GET[$var]) ? 1 : 0 ; + //return isset($_GET[$var]) ? 1 : 0 ; + return $this->is_set($var, self::GET); } /** @@ -4409,7 +5207,9 @@ public function is_get($var) public function is_request($var) { return ($this->is_get($var) || $this->is_post($var)) ? 1 : 0; - } + //return $this->is_set($var, self::REQUEST); + } + /** * Is POST var empty? * @@ -4422,8 +5222,10 @@ public function is_request($var) */ public function is_empty_post($var) { - return (empty($_POST[$var]) && ( empty($_POST[$var.'_x']) || empty($_POST[$var.'_y']))) ? 1 : 0 ; + //return (empty($_POST[$var]) && ( empty($_POST[$var.'_x']) || empty($_POST[$var.'_y']))) ? 1 : 0 ; + return ($this->is_empty($var, self::POST) && ($this->is_empty($var.'_x', self::POST) || $this->is_empty($var.'_y', self::POST))) ? 1 : 0; } + /** * Is GET var empty? * @@ -4436,7 +5238,8 @@ public function is_empty_post($var) */ public function is_empty_get($var) { - return empty($_GET[$var]) ? 1 : 0 ; + //return empty($_GET[$var]) ? 1 : 0; + return $this->is_empty($var, self::GET); } /** @@ -4452,6 +5255,276 @@ public function is_empty_request($var) { return ($this->is_empty_get($var) && $this->is_empty_post($var)) ? 1 : 0; } + + /** + * Checks whether a certain variable was sent via POST. + * To make sure that a request was sent using POST you should call this function + * on at least one variable. + * + * @param string $name The name of the form variable which should have a + * _p suffix to indicate the check in the code that creates the form too. + * + * @return bool True if the variable was set in a POST request, false otherwise. + */ + public function is_set_post($name) + { + return $this->is_set($name, self::POST); + } + + + /** + * Checks whether a certain variable was sent via GET. + * To make sure that a request was sent using GET you should call this function + * on at least one variable. + * + * @param string $name The name of the form variable which should have a + * _p suffix to indicate the check in the code that creates the form too. + * + * @return bool True if the variable was set in a GET request, false otherwise. + */ + public function is_set_get($name) + { + return $this->is_set($name, self::GET); + } + + /** + * Checks whether a certain variable is empty in one of the super global + * arrays. + * + * @param string $var Name of the variable + * @param mx_request_vars::POST|GET|REQUEST|COOKIE $super_global + * Specifies the super global which shall be checked + * + * @return bool True if the variable was sent as input + */ + public function is_empty($var, $super_global = self::REQUEST) + { + return empty($this->input[$super_global][$var]); + } + + /** + * Checks whether a certain variable is set in one of the super global + * arrays. + * + * @param string $var Name of the variable + * @param mx_request_vars::POST|GET|REQUEST|COOKIE $super_global + * Specifies the super global which shall be checked + * + * @return bool True if the variable was sent as input + */ + public function is_set($var, $super_global = self::REQUEST) + { + return isset($this->input[$super_global][$var]); + } + + /** + * Checks whether the current request is an AJAX request (XMLHttpRequest) + * + * @return bool True if the current request is an ajax request + */ + public function is_ajax() + { + return $this->header('X-Requested-With') == 'XMLHttpRequest'; + } + + /** + * Checks if the current request is happening over HTTPS. + * + * @return bool True if the request is secure. + */ + public function is_secure() + { + $https = $this->server('HTTPS'); + $https = $this->server('HTTP_X_FORWARDED_PROTO') === 'https' ? 'on' : $https; + return !empty($https) && $https !== 'off'; + } + + /** + * Returns all variable names for a given super global + * + * @param mx_request_vars::POST|GET|REQUEST|COOKIE $super_global + * The super global from which names shall be taken + * + * @return array All variable names that are set for the super global. + * Pay attention when using these, they are unsanitised! + */ + public function variable_names($super_global = self::REQUEST) + { + if (!isset($this->input[$super_global])) + { + return array(); + } + + return array_keys($this->input[$super_global]); + } + + /** + * Helper function used by variable() and untrimmed_variable(). + * + * @param string|array $var_name The form variable's name from which data shall be retrieved. + * If the value is an array this may be an array of indizes which will give + * direct access to a value at any depth. E.g. if the value of "var" is array(1 => "a") + * then specifying array("var", 1) as the name will return "a". + * @param mixed $default A default value that is returned if the variable was not set. + * This function will always return a value of the same type as the default. + * @param bool $multibyte If $default is a string this parameter has to be true if the variable may contain any UTF-8 characters + * Default is false, causing all bytes outside the ASCII range (0-127) to be replaced with question marks + * @param mx_request_vars::POST|GET|REQUEST|COOKIE $super_global + * Specifies which super global should be used + * @param bool $trim Indicates whether trim() should be applied to string values. + * + * @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the + * the same as that of $default. If the variable is not set $default is returned. + */ + protected function _variable($var_name, $default, $multibyte = false, $super_global = self::REQUEST, $trim = true) + { + $var = $this->raw_variable($var_name, $default, $super_global); + + // Return prematurely if raw variable is empty array or the same as + // the default. Using strict comparison to ensure that one can't + // prevent proper type checking on any input variable + if ($var === array() || $var === $default) + { + return $var; + } + + //$this->type_cast_helper->recursive_set_var($var, $default, $multibyte, $trim); + + return $var; + } + + /** + * {@inheritdoc} + */ + public function get_super_global($super_global = self::REQUEST) + { + return $this->input[$super_global]; + } + + /** + * {@inheritdoc} + */ + public function escape($var, $multibyte) + { + if (is_array($var)) + { + $result = array(); + foreach ($var as $key => $value) + { + //$this->type_cast_helper->set_var($key, $key, gettype($key), $multibyte); + $result[$key] = $this->escape($value, $multibyte); + } + $var = $result; + } + else + { + //$this->type_cast_helper->set_var($var, $var, 'string', $multibyte); + } + + return $var; + } } // class mx_request_vars + +/** +* Replacement for a superglobal (like $_GET or $_POST) which calls +* trigger_error on all operations but isset, overloads the [] operator with SPL. +*/ +class deactivated_super_global implements \ArrayAccess, \Countable, \IteratorAggregate +{ + /** + * @var string Holds the name of the superglobal this is replacing. + */ + private $name; + + /** + * @var \phpbb\request\request_interface::POST|GET|REQUEST|COOKIE Super global constant. + */ + private $super_global; + + /** + * @var mx_request_vars The request class instance holding the actual request data. + */ + private $request; + + /** + * Constructor generates an error message fitting the super global to be used within the other functions. + * + * @param mx_request_vars $request A request class instance holding the real super global data. + * @param string $name Name of the super global this is a replacement for - e.g. '_GET'. + * @param mx_request_vars::POST|GET|REQUEST|COOKIE $super_global The variable's super global constant. + */ + public function __construct(mx_request_vars $request, $name, $super_global) + { + $this->request = $request; + $this->name = $name; + $this->super_global = $super_global; + } + + /** + * Calls trigger_error with the file and line number the super global was used in. + */ + private function error() + { + $file = ''; + $line = 0; + + $message = 'Illegal use of $' . $this->name . '. You must use the request class to access input data. Found in %s on line %d. This error message was generated by deactivated_super_global.'; + + $backtrace = debug_backtrace(); + if (isset($backtrace[1])) + { + $file = $backtrace[1]['file']; + $line = $backtrace[1]['line']; + } + trigger_error(sprintf($message, $file, $line), E_USER_ERROR); + } + + /** + * Redirects isset to the correct request class call. + * + * @param string $offset The key of the super global being accessed. + * + * @return bool Whether the key on the super global exists. + */ + public function offsetExists($offset) + { + return $this->request->is_set($offset, $this->super_global); + } + + /**#@+ + * Part of the \ArrayAccess implementation, will always result in a FATAL error. + */ + public function offsetGet($offset) + { + $this->error(); + } + + public function offsetSet($offset, $value) + { + $this->error(); + } + + public function offsetUnset($offset) + { + $this->error(); + } + /**#@-*/ + + /** + * Part of the \Countable implementation, will always result in a FATAL error + */ + public function count() + { + $this->error(); + } + + /** + * Part of the Traversable/IteratorAggregate implementation, will always result in a FATAL error + */ + public function getIterator() + { + $this->error(); + } +} // class deactivated_super_global ?> \ No newline at end of file diff --git a/includes/mx_functions_style.php b/includes/mx_functions_style.php index ce692625..0a39e487 100644 --- a/includes/mx_functions_style.php +++ b/includes/mx_functions_style.php @@ -69,7 +69,20 @@ function mx_session_begin() * @access public */ class mx_Template extends Template -{ +{ + var $inherit_root = ''; + var $css_style_include = array(); + var $css_include = array(); + var $js_include = array(); + + var $cloned_template_name = 'subSilver'; + var $default_template_name = 'subsilver2'; + + var $template_path = 'templates/'; + var $style_path = 'templates/'; + + var $debug_paths; + /** * Constructor. * @@ -89,6 +102,16 @@ function mx_Template($root = '.') { $this->root = $root; } + + if (empty($this->template_path)) + { + $this->template_path = $this->style_path; + } + + if (empty($this->style_path)) + { + $this->style_path = $this->template_path; + } } var $module_template_path = ''; @@ -106,22 +129,28 @@ function mx_Template($root = '.') function make_filename($filename, $xs_include = false) { global $module_root_path, $mx_root_path, $phpbb_root_path, $theme, $mx_user, $mx_block; - + // ? if($this->subtemplates) { $filename = $this->subtemplates_make_filename($filename); } + // // Check replacements list + // if(!$xs_include && isset($this->replace[$filename])) { $filename = $this->replace[$filename]; } $style_path = $mx_user->template_name; - + $this->styles_path = $mx_root_path . $this->template_path; + + // // Also search for "the other" file extension + // + $filename = substr_count($filename, 'tpl') ? str_replace(".tpl", ".html", $filename) : str_replace(".html", ".tpl", $filename); $filename2 = substr_count($filename, 'html') ? str_replace(".html", ".tpl", $filename) : str_replace(".tpl", ".html", $filename); // @@ -151,8 +180,59 @@ function make_filename($filename, $xs_include = false) return $temppath; } } + + // + // Look for new template files at MX-Publisher-Module folder.........................................................................MX-Publisher-module + // + if (!empty($module_root_path)) + { + if (isset($mx_block->module_root_path)) + { + $moduleDefault = !empty($mx_user->loaded_default_styles[$mx_block->module_root_path]) ? $mx_user->loaded_default_styles[$mx_block->module_root_path] : $mx_user->default_template_name; + } + else + { + $moduleDefault = !empty($mx_user->loaded_default_styles[$module_root_path]) ? $mx_user->loaded_default_styles[$module_root_path] : $mx_user->default_template_name; + } + + $this->debug_paths .= '
Module'; + $fileSearch = array(); + $fileSearch[] = $style_path . '/template'; // First check current template + $fileSearch[] = $mx_user->cloned_template_name . '/template'; // Then check Cloned template + $fileSearch[] = $moduleDefault . '/template'; // Finally check Default template + $fileSearch[] = './'; // Compatibility with primitive modules + $temppath = $this->doFileSearch($fileSearch, $filename2, $filename, 'templates/', $module_root_path); + if (!empty($this->module_template_path)) + { + return $temppath; + } + } + + // + // Look at Root folder + // + if (!empty($phpbb_root_path)) + { + $moduleDefault = $this->default_template_name; + + + $this->debug_paths .= '
xs_mod'; + $fileSearch = array(); + $fileSearch[] = 'tpl'; + $fileSearch[] = $this->tpldir; + //$fileSearch[] = $style_path; // First check current template + //$fileSearch[] = $this->cloned_template_name; // Then check Cloned template + //$fileSearch[] = $moduleDefault; // Finally check Default template + $fileSearch[] = './'; // Compatibility with primitive modules + $temppath = $this->doFileSearch($fileSearch, $filename, $filename2, 'xs_mod/', $phpbb_root_path); + if (!empty($this->module_template_path)) + { + return $temppath; + } + } + // // Look at MX-Publisher-Root folder.........................................................................MX-Publisher-Root // @@ -168,7 +248,23 @@ function make_filename($filename, $xs_include = false) { return $temppath; } + + // + // Look at MX-Publisher-Root folder.........................................................................MX-Publisher-Root + // + $this->debug_paths .= '
CORE'; + $fileSearch = array(); + $fileSearch[] = $style_path . '/template'; // First check current template + $fileSearch[] = $mx_user->cloned_template_name . '/template'; // Then check Cloned template + $fileSearch[] = $mx_user->default_template_name . '/template'; // Then check Default template + $fileSearch[] = './'; + $temppath = $this->doFileSearch($fileSearch, $filename2, $filename, 'templates/', $mx_root_path); + if (!empty($this->module_template_path)) + { + return $temppath; + } + // // Look at Custom Root folder..............this is used my mx_mod installers too.......this does not use standard templates folders wich are set when the template was re-initialized and defined as custom var // @@ -180,13 +276,14 @@ function make_filename($filename, $xs_include = false) $fileSearch[] = $mx_user->default_template_name; // Then check Default template $temppath = $this->doFileSearch($fileSearch, $filename, $filename2, $this->root, $mx_root_path); + if (!empty($this->module_template_path)) { return $temppath; } // - // phpBB.........................................................................phpBB + // Look at Forums for new styles // switch (PORTAL_BACKEND) { @@ -196,13 +293,18 @@ function make_filename($filename, $xs_include = false) case 'mybb': case 'phpbb2': $this->debug_paths .= '
phpbb2'; - $fileSearch = array(); + $fileSearch = array(); + $fileSearch[] = $style_path; // First check current template $fileSearch[] = $mx_user->cloned_template_name; // Then check Cloned template $fileSearch[] = $mx_user->default_template_name; // Then check Default template + + $fileSearch[] = $style_path . '/template'; // First check current template + $fileSearch[] = $mx_user->cloned_template_name . '/template'; // Then check Cloned template + $fileSearch[] = $mx_user->default_template_name . '/template'; // Then check Default template $fileSearch[] = './'; - - $temppath = $this->doFileSearch($fileSearch, $filename, $filename2, 'templates/', $phpbb_root_path, false); + + $temppath = $this->doFileSearch($fileSearch, $filename2, $filename, 'templates/', $phpbb_root_path, true); if (!empty($this->module_template_path)) { return $temppath; @@ -219,7 +321,7 @@ function make_filename($filename, $xs_include = false) $fileSearch[] = $mx_user->cloned_template_name . '/' . 'template'; // Then check Cloned template $fileSearch[] = $mx_user->default_template_name . '/' . 'template'; // Then check Default template $fileSearch[] = './'; - $temppath = $this->doFileSearch($fileSearch, $filename, $filename2, 'styles/', $phpbb_root_path, false); + $temppath = $this->doFileSearch($fileSearch, $filename, $filename2, 'styles/', $phpbb_root_path, true); /* if (!empty($this->module_template_path)) { @@ -290,8 +392,9 @@ function make_filename($filename, $xs_include = false) } break; - case 'rhea': - $this->debug_paths .= '
phpbb4'; + case 'rhea': + case 'proteus': + $this->debug_paths .= '
phpbb3'; $fileSearch = array(); $fileSearch[] = $style_path . '/' . 'template'; // First check current template $fileSearch[] = $mx_user->cloned_template_name . '/' . 'template'; // Then check Cloned template @@ -318,7 +421,12 @@ function make_filename($filename, $xs_include = false) break; } - + + if( !file_exists($filename) ) + { + die("Template->make_filename(): Error - file $filename does not exist.
Class-Root: $this->root
$this->debug_paths"); + } + echo($this->debug_paths); die("Template->make_filename(): Error - file $filename does not exist.
Class-Root: $this->root
Module: $module_root_path
Current style: $style_path
Cloned style: $mx_user->cloned_template_name
Default style: $mx_user->default_template_name
Custom module default style: $moduleDefault"); } @@ -495,12 +603,22 @@ function doFileSearch($fileSearch, $filename, $filename2, $root, $root_path = '' $this->module_template_path = $root . $path . '/'; return $root_path . $root . $path . '/' . $filename; } - + else if( file_exists($root . '/' . $filename) ) + { + $this->module_template_path = $root . '/'; + return $root . '/' . $filename; + } + if ($check_file2 && @file_exists($root_path . $root . $path . '/' . $filename2)) { $this->module_template_path = $root . $path . '/'; return $root_path . $root . $path . '/' . $filename2; } + else if ($check_file2 && file_exists($root . '/' . $filename2)) + { + $this->module_template_path = $root . '/'; + return $root . '/' . $filename2; + } } else if ($path == './') { @@ -522,22 +640,188 @@ function doFileSearch($fileSearch, $filename, $filename2, $root, $root_path = '' } /** - * Set template location - * phpBB3 - * @access public - */ + * set_template + * + * This set_template implementation overrides parent method. + * Generates a full path, which can either + * be an absolute, or relative to the rootdir for this Template + * object. + * + * @access public + */ function set_template() { - global $phpbb_root_path, $mx_root_path, $mx_user; + global $module_root_path, $mx_root_path, $phpbb_root_path, $theme, $mx_user, $mx_block; + + $style_path = $theme['template_name'] . '/'; + + // + // Look at mxBB-Module folder.........................................................................mxBB-module + // + if (!empty($module_root_path)) + { + $this->module_template_path = ''; + $moduleDefault = !empty($mx_user->loaded_default_styles[$mx_block->module_root_path]) ? $mx_user->loaded_default_styles[$mx_block->module_root_path] : $mx_user->default_template_name; + + if( file_exists($module_root_path . 'templates/' . $style_path . '/') ) + { + // + // First check current template + // + $this->root = $module_root_path . 'templates/' . $style_path . '/'; + $this->module_template_path = 'templates/' . $style_path . '/'; + } + else if( file_exists($module_root_path . 'templates/' . $mx_user->cloned_template_name . '/') && !empty($mx_user->cloned_template_name)) + { + // + // Then check Cloned template + // + $this->root = $module_root_path . 'templates/' . $mx_user->cloned_template_name . '/'; + $this->module_template_path = 'templates/' . $mx_user->cloned_template_name . '/'; + } + else if( file_exists($module_root_path . 'templates/' . $moduleDefault . '/') ) + { + // + // Then check default template + // + $this->root = $module_root_path . 'templates/' . $moduleDefault . '/'; + $this->module_template_path = 'templates/' . $moduleDefault . '/'; + } + else if( file_exists($module_root_path . 'templates/') ) + { + // + // Finally check the template root (for compatibility with some old modules) + // + $this->root = $module_root_path . 'templates/'; + $this->module_template_path = 'templates/'; + } + + if (!empty($this->module_template_path)) + { + return ''; + } + } - if (file_exists($phpbb_root_path . 'styles/' . $mx_user->theme['template_path'] . '/template')) + // + // Look at mxBB-Root folder.........................................................................mxBB-Root + // + if( file_exists($mx_root_path . 'templates/' . $style_path . '/') ) + { + // + // First check current template + // + $this->root = $mx_root_path . 'templates/' . $style_path . '/'; + $this->cachepath = $mx_root_path . 'cache/tpl_' . $style_path . '_'; + } + else if( file_exists($mx_root_path . 'templates/' . $mx_user->cloned_template_name . '/') && !empty($mx_user->cloned_template_name)) + { + // + // Then check Cloned template + // + $this->root = $mx_root_path . 'templates/' . $mx_user->cloned_template_name . '/'; + $this->cachepath = $mx_root_path . 'cache/tpl_' . $mx_user->cloned_template_name . '_'; + } + else if( file_exists($mx_root_path . 'templates/' . $mx_user->default_template_name . '/') ) + { + // + // Then check Default template + // + $this->root = $mx_root_path . 'templates/' . $mx_user->default_template_name . '/'; + $this->cachepath = $mx_root_path . 'cache/tpl_' . $mx_user->default_template_name . '_'; + } + // + // Look at Custom Root folder..............this is used my mx_mod installers too.......this does not use standard templates folders wich are set when the template was re-initialized and defined as custom var + // + else if( file_exists( $this->root . '/') ) + { + $this->root = $this->root . '/'; + $this->cachepath = $mx_root_path . 'cache/tpl_' . $this->root . '_'; + } + else if( file_exists($this->root . '/' . $style_path . '/') ) + { + // + // First check current template + // + $this->root = $this->root . '/' . $style_path . '/'; + $this->cachepath = $mx_root_path . 'cache/tpl_' . $style_path . '_'; + } + else if( file_exists($this->root . '/' . $style_path . '/') ) { - $this->root = $phpbb_root_path . 'styles/' . $mx_user->theme['template_path'] . '/template'; - $this->cachepath = $phpbb_root_path . 'cache/tpl_' . $mx_user->theme['template_path'] . '_'; + // + // tpl - html + // + $this->root = $this->root. '/' . $style_path . '/'; + } + else if( file_exists($this->root . '/' . $mx_user->default_template_name . '/') ) + { + // + // Then check current template + // + $this->root = $mx_root_path . '/' . $mx_user->default_template_name . '/'; + $this->cachepath = $mx_root_path . 'cache/tpl_' . $mx_user->default_template_name . '_'; + } + else if( file_exists($this->root . '/' . $moduleDefault . '/') ) + { + // + // Finally check the Custom Root folde(for compatibility with some old modules) + // + $this->root = $this->root . '/' . $moduleDefault . '/'; + $this->cachepath = $mx_root_path . 'cache/tpl_' . $moduleDefault . '_'; } else { - print_r('Template path could not be found: styles/' . $mx_user->theme['template_path'] . '/template', E_USER_ERROR); + // + // phpBB.........................................................................phpBB + // + if( file_exists($phpbb_root_path . 'templates/' . $style_path . '/') ) + { + // + // First check current template + // + $this->root = $phpbb_root_path . 'templates/' . $style_path . '/'; + $this->cachepath = $phpbb_root_path . 'cache/tpl_' . $style_path. '_'; + } + else if( file_exists($phpbb_root_path . 'templates/' . $mx_user->cloned_template_name . '/') && !empty($mx_user->cloned_template_name)) + { + // + // Then check Cloned + // + $this->root = $phpbb_root_path . 'templates/' . $mx_user->cloned_template_name . '/'; + $this->cachepath = $phpbb_root_path . 'cache/tpl_' . $mx_user->cloned_template_name . '_'; + } + else if( file_exists($phpbb_root_path . 'templates/' . $mx_user->default_template_name . '/') && !empty($mx_user->default_template_name)) + { + // + // Then check Default + // + $this->root = $phpbb_root_path . 'templates/' . $mx_user->default_template_name . '/'; + $this->cachepath = $phpbb_root_path . 'cache/tpl_' . $mx_user->default_template_name . '_'; + } + else if (file_exists($phpbb_root_path . 'styles/' . $mx_user->theme['template_path'] . '/template')) + { + // + // Then check phpBB3 style + // + $this->root = $phpbb_root_path . 'styles/' . $mx_user->theme['template_path'] . '/template'; + $this->cachepath = $phpbb_root_path . 'cache/tpl_' . $mx_user->theme['template_path'] . '_'; + } + else if( file_exists($phpbb_root_path . $this->root . '/') ) + { + $this->root = $phpbb_root_path . $this->root . '/'; + $this->cachepath = $phpbb_root_path . 'cache/tpl_' . $this->root . '_'; + } + else if( file_exists($this->root . '/') ) + { + // + // Check if it's an absolute or relative path. + // + $this->root = phpbb_realpath($this->root . '/'); + $this->cachepath = $phpbb_root_path . 'cache/tpl_' . phpbb_realpath($this->root . '/') . '_'; + } + else + { + trigger_error('Template path could not be found: styles/' . $mx_user->theme['template_path'] . '/template', E_USER_ERROR); + } } $this->_rootref = &$this->_tpldata['.'][0]; @@ -548,9 +832,24 @@ function set_template() } // class mx_Template /**#@+ - * mx_user class specific definitions - * - */ +| Class: mx_user +| The mx_user class +| +| // +| // Properties +| // +| +| // +| // Methods +| // +| +| +| // +| // Usage examples: +| // +| +| +\** **/ define('MX_LANG_MAIN' , 10); define('MX_LANG_ADMIN' , 20); define('MX_LANG_ALL' , 30); @@ -588,21 +887,68 @@ class mx_user extends mx_session var $loaded_langs = array(); var $loaded_styles = array(); var $loaded_default_styles = array(); - + + var $lang_path = 'language/'; var $template_path = 'templates/'; - var $theme = array(); + var $styles_path = 'templates/'; + var $template_name = ''; var $template_names = array(); - var $current_template_path = ''; + var $current_template_path = ''; + + /** + * @var string ISO code of the default board language + */ + var $default_language; + var $default_language_name; + /** + * @var string ISO code of the User's language + */ + var $user_language; + var $user_language_name; + + var $lang; + var $lang_iso = 'en'; + var $lang_dir = 'lang_english'; + + protected $common_language_files_loaded; + + var $img_lang_dir = 'en'; + var $lang_english_name = 'English'; + var $lang_local_name = 'English United Kingdom'; + var $language_list = array(); + + /**** / + var $cloned_template_name = 'subSilver'; + var $default_template_name = 'subsilver2'; + + var $cloned_current_template_name = 'prosilver'; + var $default_current_template_name = ''; + + var $cloned_current_template_path = 'templates/subSilver'; + var $default_current_template_path = 'templates/subsilver2'; + /****/ + + var $block_border_graphics = ''; + + var $parent_template_name = ''; + var $parent_template_path = ''; var $cloned_template_name = ''; var $cloned_current_template_path = ''; var $current_template_phpbb_path = ''; - var $current_template_phpbb_images = ''; + var $current_template_phpbb_images = ''; var $default_template_name = '_core'; var $default_current_template_path = ''; + var $imageset_backend = PORTAL_BACKEND; + var $ext_imageset_backend = PORTAL_BACKEND; + + var $imageset_path = '/theme/images/'; + var $img_array = array(); + var $images; + var $style_name = ''; var $style_path = 'styles/'; @@ -614,21 +960,82 @@ class mx_user extends mx_session var $default_style_phpbb_path = ''; var $default_module_style = ''; + var $module_lang_path = array(); + + var $style = array(); + var $theme = array(); + // Able to add new options (up to id 31) + var $keyoptions = array('viewimg' => 0, 'viewflash' => 1, 'viewsmilies' => 2, 'viewsigs' => 3, 'viewavatars' => 4, 'viewcensors' => 5, 'attachsig' => 6, 'bbcode' => 8, 'smilies' => 9, 'sig_bbcode' => 15, 'sig_smilies' => 16, 'sig_links' => 17); + var $is_admin = false; - var $keyoptions = false; + var $page_id = ''; + var $user_ip = ''; + + /** @var \phpbb\cache\driver\driver_interface */ + protected $cache; + /** @var \phpbb\config\config */ + protected $config; + /** @var \phpbb\db\driver\driver_interface */ + protected $db; + + var $cookie_data = array(); + var $page = array(); + var $data = array(); // For future Olympus comp. + var $service_providers; // For future Ascraeus comp. + var $browser = ''; + var $forwarded_for = ''; + var $host = ''; + var $session_id = ''; + var $ip = ''; + var $datetime = ''; + var $load = 0; + var $time_now = 0; + var $update_session_page = true; + + //var $phpbb_root_path; + //var $mx_root_path; /**#@-*/ // ------------------------------ // Properties // - // ------------------------------ - // Constructor - // - + /** + * ------------------------------ + * Constructor to set the lang path + * + * @param \phpbb\language\language $lang phpBB's Language loader + * @param string $datetime_class Class name of datetime class + */ + function __construct() + { + global $mx_cache, $db, $mx_root_path, $module_root_path, $phpbb_root_path; + global $lang, $language, $board_config, $phpbb_auth; + + $this->cache = $mx_cache; + $this->mx_root_path = $mx_root_path; + $this->phpbb_root_path = $phpbb_root_path; + $this->module_root_path = $module_root_path; + + + $this->language = $language; + $this->common_language_files_loaded = false; + + $this->lang_path = $mx_root_path . 'language/'; + $this->phpbb_lang_path = $phpbb_root_path . 'language/'; + $this->shared_lang_path = $mx_root_path . 'includes/shared/phpbb2/'; + $this->language = $lang; + $this->config = $board_config; + $this->db = $db; + $this->auth = $phpbb_auth; + $this->phpEx = substr(strrchr(__FILE__, '.'), 1); + $this->php_ext = substr(strrchr(__FILE__, '.'), 1); + + } + // ------------------------------ // Private Methods // @@ -645,92 +1052,178 @@ class mx_user extends mx_session */ function _init_session() { - $this->mx_session_begin(); + global $userdata; + $this->mx_session_begin(); + $this->data = $userdata; //for compatibility with Olympus style modules + + // Give us some basic information + //$this->time_now = time(); + + //$this->browser = $_SERVER['HTTP_USER_AGENT']; + //$this->referer = $_SERVER['Referer']; + //$this->forwarded_for = $_SERVER['X-Forwarded-For']; + + //$this->host = extract_current_hostname(); + //$this->page = extract_current_page($mx_root_path); + $this->is_admin = $this->data['user_level'] == ADMIN && $this->data['session_logged_in']; } + + // ------------------------------ + // Public Methods + // /** - * Init userprefs. - * - * Initialise user settings on page load. - * - populate $lang, $theme, $images and initiate $template + * Init user class. + * Populate $userdata, $lang * - * @access private + * @access public + * @param unknown_type $user_ip + * @param unknown_type $page_id */ - function _init_userprefs() + function init($user_ip, $page_id, $init_style = true) { - global $userdata, $board_config, $portal_config, $theme, $images; - global $template, $lang, $phpEx, $phpbb_root_path, $mx_root_path, $db; - global $nav_links; + // + // Define basic constants + // + $this->page_id = $page_id; + $this->user_ip = $user_ip; // - // Clean up and ensure we are using mxp internal (long) lang format + // Inititate User data // - $board_config['phpbb_lang'] = $board_config['default_lang']; // Handy switch - $this->lang['default_lang'] = phpBB2::phpbb_ltrim(basename(phpBB2::phpbb_rtrim($this->decode_lang($board_config['default_lang']))), "'"); - $this->data['user_lang'] = phpBB2::phpbb_ltrim(basename(phpBB2::phpbb_rtrim($this->decode_lang($this->data['user_lang']))), "'"); + $this->_init_session($user_ip, $page_id); + $this->_init_userprefs(); - //if ( $this->data['session_logged_in'] ) // Old code - if ( $this->data['user_id'] != ANONYMOUS ) + // + // Inititate User style + // + if ($init_style) { - if ( !empty($this->data['user_lang'])) - { - $this->lang['default_lang'] = $this->data['user_lang']; - } + $this->_init_style(); + } + } + + // ------------------------------ + // Public Methods + // + /** + * Init userprefs. + * + * Initialise user settings on page load. + * - populate $lang, $theme, $images and initiate $template + * + * @access private + */ + function _init_userprefs($lang_set = false) + { + global $mx_cache, $mx_user, $userdata, $board_config, $portal_config, $theme, $images; + global $template, $lang, $phpEx, $phpbb_root_path, $mx_root_path, $db; + global $phpBB2, $phpBB3, $nav_links; + + $this->data = !empty($this->data['user_id']) ? $this->data : $this->session_pagestart($this->user_ip, $this->page_id); + + $this->cache = is_object($mx_cache) ? $mx_cache : new mx_cache(); + + if (preg_match('/bot|crawl|curl|dataprovider|search|get|spider|find|java|majesticsEO|google|yahoo|teoma|contaxe|yandex|libwww-perl|facebookexternalhit/i', $_SERVER['HTTP_USER_AGENT'])) + { + $this->data['is_bot'] = true; + } + else + { + $this->data['is_bot'] = false; + } + + $this->data['user_options'] = isset($this->data['user_options']) ? $this->data['user_options'] : '230271'; // + + // + // Populate session_id + // + $this->session_id = $this->data['session_id']; + + $this->lang_path = $mx_root_path . 'language/'; + + $lang_set = !isset($lang_set) ? ((defined('IN_ADMIN') ? 'lang_admin' : 'lang_main')) : $lang_set; + + // + // Send a proper content-language to the output in phpBB2 format i.e english + // Clean up and ensure we are using mxp internal (long) lang format + // + $img_lang = $board_config['phpbb_lang'] = $board_config['default_lang']; // Handy switch + $this->lang['default_lang'] = $phpBB2->phpbb_ltrim(basename($phpBB2->phpbb_rtrim($this->decode_lang($board_config['default_lang']))), "'"); + $this->data['user_lang'] = $phpBB2->phpbb_ltrim(basename($phpBB2->phpbb_rtrim($this->decode_lang($this->data['user_lang']))), "'"); + + // + // Old code: $this->data['session_logged_in'] + // It is not important watever is session_logged_in but if userdata array keys are populated + // + if ( $this->data['user_id'] != ANONYMOUS ) + { + if ( !empty($this->data['user_lang'])) + { + $img_lang = $this->lang['default_lang'] = $this->data['user_lang']; + } + if ( !empty($this->data['user_dateformat']) ) { $board_config['default_dateformat'] = $this->data['user_dateformat']; } - + if ( isset($this->data['user_timezone']) ) { $board_config['board_timezone'] = $this->data['user_timezone']; } } + //Enable URL Language Detection if (isset($_GET['lang'])) { - $this->lang['default_lang'] = ((file_exists($mx_root_path . 'language/lang_' . $this->decode_lang(strval(phpBB3::request_var('lang', ''))) . "/lang_main.$phpEx")) ? strval(phpBB3::request_var('lang', '')) : ((file_exists($mx_root_path . 'language/lang_' . strval(phpBB3::request_var('lang', '')) . "/lang_main.$phpEx")) ? strval(phpBB3::request_var('lang', '')) : $this->lang['default_lang'])); + $img_lang = $this->lang['default_lang'] = ((file_exists($mx_root_path . 'language/lang_' . $this->decode_lang(strval($phpBB3->request_var('lang', ''))) . "/lang_main.$phpEx")) ? $this->decode_lang(strval($phpBB3->request_var('lang', ''))) : ((file_exists($mx_root_path . 'language/lang_' . strval($phpBB3->request_var('lang', '')) . "/lang_main.$phpEx")) ? strval($phpBB3->request_var('lang', '')) : $this->lang['default_lang'])); } + // Now, $this->lang['default_lang'] is populated, but do we have a mathing MX-Publisher lang file installed? - if ( !file_exists(@phpBB2::phpbb_realpath($mx_root_path . 'language/lang_' . $this->lang['default_lang'] . '/lang_main.'.$phpEx)) ) + if ( !file_exists($phpBB2->phpbb_realpath($mx_root_path . 'language/lang_' . $this->lang['default_lang'] . '/lang_main.'.$phpEx)) ) { // If not, try english (desperate try) $this->lang['default_lang'] = 'english'; - if ( !file_exists(@phpBB2::phpbb_realpath($mx_root_path . 'language/lang_' . $this->lang['default_lang'] . '/lang_main.'.$phpEx)) ) + if ( !file_exists($phpBB2->phpbb_realpath($mx_root_path . 'language/lang_' . $this->lang['default_lang'] . '/lang_main.'.$phpEx)) ) { mx_message_die(CRITICAL_ERROR, 'Could not locate valid language pack: ' . $mx_root_path . 'language/lang_' . $this->lang['default_lang'] . '/lang_main.'.$phpEx); } } + // Language DataBase switch (PORTAL_BACKEND) { - //Load vanilla phpBB lang files if is possible - case 'internal': + case 'internal': + case 'phpbb2': + case 'mybb': $sql_users = 'UPDATE ' . USERS_TABLE . " - SET user_lang = '" . $this->encode_lang($this->lang['default_lang']) . "' - WHERE user_lang = '" . $this->encode_lang($this->data['user_lang']) . "'"; + SET user_lang = '" . $this->decode_lang($this->lang['default_lang']) . "' + WHERE user_lang = '" . $this->decode_lang($this->data['user_lang']) . "'"; $sql_config = "UPDATE " . PORTAL_TABLE . " SET default_lang = '" . $this->decode_lang($this->lang['default_lang']) . "' WHERE portal_id = '1'"; - break; - case 'mybb': + break; + case 'phpbb3': case 'olympus': case 'ascraeus': - case 'rhea': - case 'phpbb2': + case 'rhea': + case 'proteus': + $sql_users = 'UPDATE ' . USERS_TABLE . " SET user_lang = '" . $this->encode_lang($this->lang['default_lang']) . "' WHERE user_lang = '" . $this->encode_lang($this->data['user_lang']) . "'"; $sql_config = 'UPDATE ' . CONFIG_TABLE . " SET config_value = '" . $this->encode_lang($this->lang['default_lang']) . "' - WHERE config_name = 'default_lang'"; - + WHERE config_name = 'default_lang'"; break; + + case 'smf2': $sql_users = 'UPDATE ' . USERS_TABLE . " SET lng_file = '" . $this->decode_lang($this->lang['default_lang']) . "' @@ -749,9 +1242,10 @@ function _init_userprefs() //display an error debuging message only if the portal is installed/upgraded if(!@$db->sql_query($sql_users) && !file_exists($mx_root_path.'/install/')) { - mx_message_die(CRITICAL_ERROR, 'Could not update user language info'); + mx_message_die(CRITICAL_ERROR, 'Could not update user language info', '', __LINE__, __FILE__, $sql_users); } - $this->data['user_lang'] = $this->lang['default_lang']; + + $userdata['user_lang'] = $this->data['user_lang'] = $this->lang['default_lang']; } elseif ( !$this->data['session_logged_in'] && $board_config['default_lang'] !== $this->lang['default_lang'] ) { @@ -762,54 +1256,163 @@ function _init_userprefs() } } + /* * Pointless here, since we do not know watever we have queried language vanilla phpBB2 lang files installed + * Just in case we do fallback on $board_config['phpbb_lang'] * */ + $board_config['default_lang'] = $this->lang['default_lang']; + + $this->lang_name = $this->lang['default_lang'] = $this->lang['default_lang']; + $this->lang_path = 'language/lang_' . $this->lang_name . '/'; + + /* * Load MXP lang keys + * Load vanilla phpBB2 lang files if is possible */ - //Load vanilla phpBB2 lang files if is possible switch (PORTAL_BACKEND) { case 'internal': case 'smf2': case 'mybb': + $shared_lang_path = $mx_root_path . 'includes/shared/phpbb2/language/'; + + break; case 'phpbb3': case 'olympus': case 'ascraeus': case 'rhea': + case 'proteus': $shared_lang_path = $mx_root_path . 'includes/shared/phpbb2/language/'; - //$template_path = 'styles/'; + break; case 'phpbb2': - $shared_lang_path = $phpbb_root_path . 'language/'; + $shared_lang_path = $mx_root_path . 'includes/shared/phpbb2/language/'; + break; } + // + // We setup common user language variables + // We include common language file here with funtion load_common_language_files() to not load it every time a custom language file is included + // + //$this->load_common_language_files(); + //$lang = &$this->lang; + + // + // + // + //$this->lang = &$lang; + + /** Sort of pointless here, since we have already included all main lang files **/ + //this will fix the path for anonymouse users + if ((@include $mx_root_path . $this->lang_path . "lang_main.$phpEx") === false) + { + echo('
'); + echo(filesize($mx_root_path . $this->lang_path . "lang_main.$phpEx") . ''); + echo('
'); + die('Language file ' . $mx_root_path . $this->lang_path . "lang_main.$phpEx" . '' . ' couldn\'t be opened.'); + } + + //$this->lang = &$lang; + + // Shared phpBB keys + if ((@include $shared_lang_path . "lang_" . $this->lang_name . "/lang_main.$phpEx") === false) + { + if ((@include $shared_lang_path . "lang_english/lang_main.$phpEx") === false) + { + mx_message_die(GENERAL_ERROR, 'Language file ' . $shared_lang_path . "lang_" . $this->lang_name . "/lang_main.$phpEx" . ' couldn\'t be opened.'); + } + } + + //$this->lang = &$lang; + + $this->add_lang($lang_set); + + unset($lang_set); + + // // AdminCP + // if (defined('IN_ADMIN')) { // Core - include($mx_root_path . 'language/lang_' . $this->lang['default_lang'] . '/lang_admin.' . $phpEx); + if(!file_exists(@phpbb_realpath($mx_root_path . 'language/lang_' . $this->lang_name . '/lang_admin.'.$phpEx))) + { + $board_config['default_lang'] = 'english'; + } + + include($mx_root_path . 'language/lang_' . $this->lang_name . '/lang_admin.' . $phpEx); + + $this->lang = &$lang; + // Shared phpBB keys - if ((include $shared_lang_path . "lang_" . $this->lang['default_lang'] . "/lang_admin.$phpEx") === false) + if ((include $shared_lang_path . "lang_" . $this->lang_name . "/lang_admin.$phpEx") === false) { if ((@include $shared_lang_path . "lang_english/lang_admin.$phpEx") === false) { - mx_message_die(GENERAL_ERROR, 'Language file ' . $shared_lang_path . "lang_" . $this->lang['default_lang'] . "/lang_admin.$phpEx" . ' couldn\'t be opened.'); + mx_message_die(GENERAL_ERROR, 'Language file ' . $shared_lang_path . "lang_" . $this->lang_name . "/lang_admin.$phpEx" . ' couldn\'t be opened.'); } - } + } } - // Shared phpBB keys - if ((@include $shared_lang_path . "lang_" . $this->lang['default_lang'] . "/lang_main.$phpEx") === false) - { - if ((@include $shared_lang_path . "lang_english/lang_main.$phpEx") === false) + // + // + // We include common language file here to not load it every time a custom language file is included + // + //$lang = &$this->lang; + $this->lang = &$lang; + $this->user_lang = !empty($this->lang['USER_LANG']) ? $this->lang['USER_LANG'] : $this->encode_lang($this->lang_name); + $user_lang = $this->user_lang; + + $this->user_language = $this->encode_lang($this->lang_name); + $this->default_language = $this->encode_lang($board_config['default_lang']); + + $this->user_language_name = $this->decode_lang($this->lang_name); + $this->default_language_name = $this->decode_lang($board_config['default_lang']); + + $counter = 0; //First language pack lang_id + $lang_ids = array(); + + $lang_list = $this->get_lang_list(); + + if (is_array($lang_list)) + { + foreach ($lang_list as $lang_english_name => $lang_local_name) { - mx_message_die(GENERAL_ERROR, 'Language file ' . $shared_lang_path . "lang_" . $this->lang['default_lang'] . "/lang_main.$phpEx" . ' couldn\'t be opened.'); - } - } + $lang_ids[$lang_english_name] = $counter; + $counter++; + } + } + + $lang_entries = array( + 'lang_id' => !empty($lang_ids['lang_' . $this->user_language_name]) ? $lang_ids['lang_' . $this->user_language_name] : $counter, + 'lang_iso' => !empty($lang['USER_LANG']) ? $lang['USER_LANG'] : $this->encode_lang($this->lang_name), + 'lang_dir' => 'lang_' . $this->lang_name, + 'lang_english_name' => $this->user_language_name, + 'lang_local_name' => $this->ucstrreplace('lang_', '', $this->lang_name), + 'lang_author' => !empty($lang['TRANSLATION_INFO']) ? $lang['TRANSLATION_INFO'] : 'Language pack author not set in ACP.' + ); // Core Main Translation after shared phpBB keys so we can overwrite some settings - include($mx_root_path . 'language/lang_' . $this->lang['default_lang'] . '/lang_main.' . $phpEx); + include($mx_root_path . 'language/lang_' . $this->lang_name . '/lang_main.' . $phpEx); + + // + // Finishing setting language variables to ouput + // + $this->lang_iso = $lang_iso = $lang_entries['lang_iso']; + $this->lang_dir = $lang_dir = $lang_entries['lang_dir']; + $this->lang_english_name = $lang_english_name = $lang_entries['lang_english_name']; + + if(file_exists(@phpbb_realpath($phpbb_root_path . $this->lang_path . '/common.'.$phpEx))) + { + //$this->set_lang($this->lang, $this->help, 'common'); + + //this will fix the path for anonymouse users + if ((@include $phpbb_root_path . $this->lang_path . '/common.'.$phpEx) === false) + { + die('Language file (_init_userprefs) ' . $phpbb_root_path . $this->lang_path . '/common.'.$phpEx . ' couldn\'t be opened by _init_userprefs().'); + } + } // // Load backend specific lang defs. @@ -844,6 +1447,8 @@ function _init_userprefs() 'url' => mx_append_sid($phpbb_root_path . 'memberlist.' . $phpEx), 'title' => $lang['Memberlist'] ); + + $this->nav_links = $nav_links; } /** @@ -856,7 +1461,7 @@ function _init_style() { global $userdata, $board_config, $portal_config, $theme, $images; global $template, $lang, $phpEx, $phpbb_root_path, $mx_root_path, $db; - global $mx_page, $mx_request_vars, $_GET, $_COOKIE; + global $mx_page, $mx_request_vars, $_GET, $_COOKIE, $phpBB3; /* * Build Portal style @@ -876,7 +1481,7 @@ function _init_style() } else if (isset($mx_page)) { - $init_style = $mx_page->default_style == -1 ? $portal_config['default_style'] : $mx_page->default_style; + $init_style = $mx_page->default_style == -1 ? $portal_config['default_style'] : $mx_page->default_style; $init_override = intval($mx_page->override_user_style) == -1 ? $portal_config['override_user_style'] : $mx_page->override_user_style; } else @@ -884,132 +1489,210 @@ function _init_style() $init_style = $portal_config['default_style']; $init_override = $portal_config['override_user_style']; } - /**/ - if (!empty($_GET['style']) || isset($_COOKIE['style'])) + + /* + * Setup demo style + */ + if (isset($_GET['style'])) { global $SID, $_EXTRA_URL; - $style = phpBB3::request_var('style', 0); - $SID .= '&style=' . $style; - $_EXTRA_URL = array('style=' . $style); + $init_style = $phpBB3->request_var('style', 0); + $SID .= '&style=' . $init_style; + $_EXTRA_URL = array('style=' . $init_style); - if ( $theme = $this->_setup_style($style) ) - { - setcookie('style', $style, (time()+21600), $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']); - return; - } + //if ( $theme = $this->_setup_style($init_style) ) + //{ + setcookie('style', $init_style, (time() + 21600), $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']); + // return; + //} } /**/ /* * Setup demo style */ - if ( isset($_GET['demo_theme']) || isset($_COOKIE['demo_theme'])) + if ( isset($_GET['demo_theme'])) { - $style = isset($_GET['demo_theme']) ? intval($_GET['demo_theme']) : intval($_COOKIE['demo_theme']); - if ( $theme = $this->_setup_style($style) ) - { - setcookie('demo_theme', $style, (time()+21600), $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']); - return; - } - } + $init_style = isset($_GET['demo_theme']) ? intval($_GET['demo_theme']) : intval($_COOKIE['demo_theme']); + //if ( $theme = $this->_setup_style($init_style) ) + //{ + setcookie('demo_theme', $init_style, (time() + 21600), $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']); + // return; + //} + } + /**/ + + /* + * Setup demo style + */ + if ( isset($_GET['demostyle'])) + { + $init_style = isset($_GET['demostyle']) ? intval($_GET['demostyle']) : intval($_COOKIE['demostyle']); + //if ( $theme = $this->_setup_style($init_style) ) + //{ + setcookie('demostyle', $init_style, (time() + 21600), $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']); + // return; + //} + } + /**/ + + /* + * Request demostyle or style, style_name or themes_id/style_id i.e. for prosilver + */ if (!$mx_request_vars->is_empty_request('demostyle') || !$mx_request_vars->is_empty_request('style') && !defined('IN_ADMIN')) { - $init_style = !$mx_request_vars->is_empty_request('demostyle') ? phpBB3::request_var('demostyle', '') : phpBB3::request_var('style', ''); - if (intval($init_style) == 0) + $init_style = !$mx_request_vars->is_empty_request('demostyle') ? $phpBB3->request_var('demostyle', '') : $phpBB3->request_var('style', ''); + } + + /* + * Query id for default_style, or for demostyle-style, style_name or themes_id + */ + if (!is_numeric($init_style)) + { + switch (PORTAL_BACKEND) { - switch (PORTAL_BACKEND) - { - case 'internal': - case 'smf2': - case 'mybb': - $sql = "SELECT themes_id, style_name - FROM " . MX_THEMES_TABLE . " - WHERE portal_backend = '" . PORTAL_BACKEND . "' - AND style_name = '$init_style'"; - break; - case 'phpbb2': - $sql = "SELECT mxt.themes_id, bbt.style_id, bbt.style_name - FROM " . MX_THEMES_TABLE . " mxt, " . THEMES_TABLE . " bbt - WHERE mxt.style_name = bbt.style_name + case 'internal': + case 'smf2': + case 'mybb': + $sql = "SELECT themes_id, style_name + FROM " . MX_THEMES_TABLE . " + WHERE portal_backend = '" . PORTAL_BACKEND . "' + AND style_name = '$init_style'"; + break; + case 'phpbb2': + $sql = "SELECT s.themes_id as style_id, mxt.themes_id, mxt.template_name as style_path + FROM " . MX_THEMES_TABLE . " mxt, " . THEMES_TABLE . " s + WHERE mxt.template_name = s.template_name + AND mxt.portal_backend = '" . PORTAL_BACKEND . "' + AND s.style_name = '$init_style'"; + break; + case 'phpbb3': + case 'olympus': + case 'ascraeus': + case 'rhea': + case 'proteus': + $sql = "SELECT mxt.themes_id, bbt.style_id, bbt.style_name + FROM " . MX_THEMES_TABLE . " AS mxt, " . STYLES_TEMPLATE_TABLE . " AS stt, " . STYLES_TABLE . " AS bbt + WHERE bbt.style_active = 1 AND bbt.style_name = '$init_style' + AND bbt.style_name = mxt.style_name AND mxt.portal_backend = '" . PORTAL_BACKEND . "' - AND mxt.style_name = '$init_style'"; - break; - case 'phpbb3': - case 'olympus': - case 'ascraeus': - case 'rhea': - $sql = "SELECT mxt.themes_id, bbt.style_id, bbt.style_name - FROM " . MX_THEMES_TABLE . " AS mxt, " . STYLES_TEMPLATE_TABLE . " AS stt, " . STYLES_TABLE . " AS bbt - WHERE bbt.style_active = 1 AND bbt.style_name = '$init_style' - AND bbt.style_name = mxt.style_name - AND mxt.portal_backend = '" . PORTAL_BACKEND . "' - AND stt.template_id = bbt.template_id"; - break; - } - if(($result = $db->sql_query($sql)) && ($row = $db->sql_fetchrow($result))) - { - $init_style = $row['themes_id']; //Portal Style Id - } - else - { - die('Could not find style name: ' . $init_style . '!'); - } + AND stt.template_id = bbt.template_id"; + break; + } + /* + * Query ed id for default_style, or for demostyle-style, style_name or themes_id from mxt.themes_id + */ + if(($result = $db->sql_query($sql)) && ($row = $db->sql_fetchrow($result))) + { + $init_style = $row['themes_id']; //Portal Style Id i.e. 7 } else { + die('Could not find style name: ' . $init_style . '!'); + } + } + else + { + switch (PORTAL_BACKEND) + { + case 'internal': + case 'smf2': + case 'mybb': + $sql = "SELECT themes_id, style_name + FROM " . MX_THEMES_TABLE . " + WHERE portal_backend = '" . PORTAL_BACKEND . "' + AND themes_id = " . (int) $init_style; + break; + case 'phpbb2': + $sql = "SELECT s.themes_id as style_id, mxt.themes_id, mxt.template_name as style_path + FROM " . MX_THEMES_TABLE . " mxt, " . THEMES_TABLE . " s + WHERE mxt.template_name = s.template_name + AND mxt.portal_backend = '" . PORTAL_BACKEND . "' + AND mxt.themes_id = " . (int) $init_style; + break; + case 'phpbb3': + case 'olympus': + case 'ascraeus': + case 'rhea': + case 'proteus': + $sql = "SELECT mxt.themes_id, bbt.style_id, bbt.style_name + FROM " . MX_THEMES_TABLE . " AS mxt, " . STYLES_TEMPLATE_TABLE . " AS stt, " . STYLES_TABLE . " AS bbt + WHERE bbt.style_active = 1 AND bbt.style_id = " . (int) $init_style . " + AND bbt.style_name = mxt.style_name + AND mxt.portal_backend = '" . PORTAL_BACKEND . "' + AND stt.template_id = bbt.template_id"; + break; + } + + if(($result = $db->sql_query($sql)) && ($row = $db->sql_fetchrow($result))) + { + $init_style = $row['themes_id']; //Portal Style Id + } + else + { switch (PORTAL_BACKEND) { case 'internal': case 'smf2': case 'mybb': - $sql = "SELECT themes_id, style_name + $sql2 = "SELECT themes_id, style_name FROM " . MX_THEMES_TABLE . " - WHERE portal_backend = '" . PORTAL_BACKEND . "' - AND themes_id = " . (int) $init_style; + WHERE portal_backend = '" . PORTAL_BACKEND . "'"; break; case 'phpbb2': - $sql = "SELECT mxt.themes_id, bbt.style_id, bbt.style_name - FROM " . MX_THEMES_TABLE . " mxt, " . THEMES_TABLE . " bbt - WHERE mxt.style_name = bbt.style_name - AND mxt.portal_backend = '" . PORTAL_BACKEND . "' - AND bbt.style_id = " . (int) $init_style; + $sql2 = "SELECT s.themes_id as style_id, mxt.themes_id, mxt.template_name as style_path + FROM " . MX_THEMES_TABLE . " mxt, " . THEMES_TABLE . " s + WHERE mxt.template_name = s.template_name + AND mxt.portal_backend = '" . PORTAL_BACKEND . "'"; break; case 'phpbb3': case 'olympus': case 'ascraeus': case 'rhea': - $sql = "SELECT mxt.themes_id, bbt.style_id, bbt.style_name + case 'proteus': + $sql2 = "SELECT mxt.themes_id, bbt.style_id, bbt.style_name FROM " . MX_THEMES_TABLE . " AS mxt, " . STYLES_TEMPLATE_TABLE . " AS stt, " . STYLES_TABLE . " AS bbt - WHERE bbt.style_active = 1 AND bbt.style_id = " . (int) $init_style . " + WHERE bbt.style_active = 1 AND bbt.style_name = mxt.style_name AND mxt.portal_backend = '" . PORTAL_BACKEND . "' AND stt.template_id = bbt.template_id"; break; - } - if(($result = $db->sql_query($sql)) && ($row = $db->sql_fetchrow($result))) + } + + if(($result = $db->sql_query_limit($sql2, 1)) && ($row = $db->sql_fetchrow($result))) { $init_style = $row['themes_id']; //Portal Style Id } - else + else { - die('style_id: ' . $init_style . ', no style with this id found ...'); + die('style_id: ' . $init_style . ', no style with this id found ... ' . $sql); } } - if ($theme = $this->_setup_style($init_style, false) ) - { - @setcookie((!$mx_request_vars->is_empty_request('demostyle') ? 'demostyle' : 'style'), $init_style, (time()+21600), $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']); - return; - } + + } + + /* + * Init queried id for demostyle or style, style_name or style_id + */ + if ($theme = $this->_setup_style($init_style, false) ) + { + @setcookie((!$mx_request_vars->is_empty_request('demostyle') ? 'demostyle' : 'style'), $init_style, (time() + 21600), $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']); + return; } + + /* + * Init overwrite queried + */ if (!$init_style) { $init_style = 1; $init_override = 1; } - // - // Setup MXP Style - // + + /* + * Setup user_style, style_id + */ $user_style = false; if (!$init_override) { @@ -1018,46 +1701,219 @@ function _init_style() $user_style = $mx_request_vars->post('user_style', MX_TYPE_INT, $this->data['user_style']); } } - $init_style = $mx_request_vars->post('default_style', MX_TYPE_INT, $init_style); + + $init_style = isset($_POST['default_style']) ? $mx_request_vars->post('default_style', MX_TYPE_INT, $init_style) : $init_style; $theme = $this->_setup_style($init_style, $user_style); } /** - * Setup style. + * Enter description here... * - * @access private * @param unknown_type $style * @return unknown */ - function _setup_style($init_style, $user_style = false) + function _style_query($style = true) { global $db, $board_config, $portal_config, $template, $phpbb_root_path, $mx_root_path; - global $images, $theme; - - $row = false; + global $mx_request_vars, $theme; - // Are we trying a userstyle? - if ((intval($user_style) !== 0) && !empty($user_style)) + // + // Set up style to output + // + if ($this->data['user_id'] == ANONYMOUS && empty($this->data['user_style'])) { - $row = $this->_style_query($user_style); + $this->data['user_style'] = $board_config['default_style']; } - - // ...or a Custom Page/AdminCP Style - if (!isset($row['style_name'])) + + $style_request = $mx_request_vars->request('style', 0); + + if ($style_request && (!$board_config['override_user_style'] || !defined('IN_ADMIN'))) { - $row = $this->_style_query($init_style); + global $SID, $_EXTRA_URL; + + $style = $style_request; + $SID .= '&style=' . $style; + $_EXTRA_URL = array('style=' . $style); } - - // Seems like we need to try the default style - if (!isset($row['style_name'])) + else { - $row = $this->_style_query($portal_config['default_style']); - } + // Set up style + $style = ($style) ? $style : ((!$board_config['override_user_style']) ? $this->data['user_style'] : $board_config['default_style']); + } + // END Styles_Demo MOD + if (!is_numeric($style)) + { + //Query MX style_name + $sql_and = "style_name"; + } + else + { + //Query MX themes_id + $sql_and = "themes_id"; + } + + switch (PORTAL_BACKEND) + { + case 'internal': + case 'smf2': + case 'mybb': + $sql = "SELECT * + FROM " . MX_THEMES_TABLE . " + WHERE portal_backend = '" . PORTAL_BACKEND . "' + AND " . $sql_and . " = '" . $style . "'"; + break; + case 'phpbb2': + $sql = "SELECT s.themes_id as style_id, + mxt.themes_id, + mxt.template_name as style_path, + s.template_name, + s.style_name, + s.head_stylesheet, + s.body_background, + s.body_bgcolor, + s.body_text, + s.body_link, + s.body_vlink, + s.body_alink, + s.body_hlink, + s.tr_color1, + s.tr_color2, + s.tr_color3, + s.tr_class1, + s.tr_class2, + s.tr_class3, + s.th_color1, + s.th_color2, + s.th_color3, + s.th_class1, + s.th_class2, + s.th_class3, + s.td_color1, + s.td_color2, + s.td_color3, + s.td_class1, + s.td_class2, + s.td_class3, + s.fontface1, + s.fontface2, + s.fontface3, + s.fontsize1, + s.fontsize2, + s.fontsize3, + s.fontcolor1, + s.fontcolor2, + s.fontcolor3, + s.span_class1, + s.span_class2, + s.span_class3, + s.img_size_poll, + s.img_size_privmsg + FROM " . MX_THEMES_TABLE . " mxt, " . THEMES_TABLE . " s + WHERE mxt.style_name = s.style_name + AND mxt.portal_backend = '" . PORTAL_BACKEND . "' + AND mxt." . $sql_and . " = '" . $style . "'"; + break; + case 'phpbb3': + case 'olympus': + case 'ascraeus': + #1146 - Table STYLES_TEMPLATE_TABLE 'rhea.phpbb_styles_template' doesn't exist + case 'rhea': + case 'proteus': + $sql = "SELECT t.* , s.* + FROM " . MX_THEMES_TABLE . " AS m, " . STYLES_TABLE . " AS s, " . STYLES_TEMPLATE_TABLE . " AS t, " . STYLES_THEME_TABLE . " AS c, " . STYLES_IMAGESET_TABLE . " i + WHERE m.style_name = s.style_name + AND m.portal_backend = '" . PORTAL_BACKEND . "' + AND t.template_id = s.template_id + AND c.theme_id = s.theme_id + AND i.imageset_id = s.imageset_id + AND m." . $sql_and . " = '" . $style . "'"; + break; + } + if (!$result = $db->sql_query_limit($sql, 1)) + { + mx_message_die(CRITICAL_ERROR, "Could not query database for theme info '$style'", '', __LINE__, __FILE__, $sql); + } + + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + $style_value = !isset($row['style_name']) ? $row['style_name'] : $style; + + return $row; + } + + /** + * Setup style. + * + * @access private + * @param unknown_type $style + * @return unknown + */ + function _setup_style($init_style, $user_style = false) + { + global $db, $board_config, $portal_config, $template, $phpbb_root_path, $mx_root_path; + + global $mx_request_vars, $images, $theme; + + $row = false; + + // + // Are we trying a userstyle? + // + if (@is_numeric($user_style) && ($user_style !== false)) + { + $row = $this->style = $this->theme = $theme = $this->_style_query($user_style); + } + + // + // ...or a Custom Page/AdminCP Style + // + if (!$row) + { + $row = $this->style = $this->theme = $theme = $this->_style_query($init_style); + } + + // + // Seems like we need to try the default style + // + if (!$row) + { + $row = $this->style = $this->theme = $theme = $this->_style_query($portal_config['default_style']); + } + + // // Last desperate try... + // if (!isset($row['style_name'])) - { + { + // + // Set up style to output + // + if ($this->data['user_id'] == ANONYMOUS && empty($this->data['user_style'])) + { + $this->data['user_style'] = $board_config['default_style']; + } + + $style_request = $mx_request_vars->request('style', 1); + + if ($style_request && (!$board_config['override_user_style'] || !defined('IN_ADMIN'))) + { + global $SID, $_EXTRA_URL; + + $init_style = $style_request; + $SID .= '&style=' . $init_style; + $_EXTRA_URL = array('style=' . $init_style); + } + else + { + // Set up style + $init_style = ($init_style) ? $init_style : ((!$board_config['override_user_style']) ? $this->data['user_style'] : $board_config['default_style']); + } + + + switch (PORTAL_BACKEND) { case 'internal': @@ -1067,28 +1923,29 @@ function _setup_style($init_style, $user_style = false) FROM ' . MX_THEMES_TABLE; break; case 'phpbb2': - $sql = 'SELECT * - FROM ' . THEMES_TABLE; + $sql = "SELECT s.*, mxt.*, mxt.template_name as style_path + FROM " . MX_THEMES_TABLE . " AS mxt, " . THEMES_TABLE . " AS s + WHERE mxt.themes_id = " . (int) $init_style . " + AND s.template_name = mxt.template_name"; break; case 'phpbb3': case 'olympus': case 'ascraeus': case 'rhea': + case 'proteus': $sql = "SELECT bbt.*, stt.* FROM " . MX_THEMES_TABLE . " mxt, " . STYLES_TABLE . " bbt, " . STYLES_TEMPLATE_TABLE . " stt WHERE mxt.template_name = stt.template_path"; break; } - if ( !($result = $db->sql_query_limit($sql, 1)) ) - { - mx_message_die(CRITICAL_ERROR, 'Could not query database for theme info - desperate try'); - } - if ( !($row = $db->sql_fetchrow($result)) ) + $result = $db->sql_query($sql, 3600); + $row = $this->style = $this->theme = $theme = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + if (!isset($row)) { mx_message_die(CRITICAL_ERROR, "Could not get MX-Publisher style data for themes_id [$init_style]"); - } - + } $db->sql_freeresult($result); } @@ -1109,6 +1966,7 @@ function _setup_style($init_style, $user_style = false) case 'olympus': case 'ascraeus': case 'rhea': + case 'proteus': $this->template_name = $row['template_path']; $this->style_name = $row['style_name']; $style = $row['style_id']; @@ -1160,6 +2018,7 @@ function _setup_style($init_style, $user_style = false) case 'olympus': case 'ascraeus': case 'rhea': + case 'proteus': $row['style_copy'] = $template_config_row['template_copy']; $row['head_stylesheet'] = $row['template_path'] . '.css'; break; @@ -1182,83 +2041,25 @@ function _setup_style($init_style, $user_style = false) case 'phpbb2': $this->_load_phpbb_images(); $this->_load_mxbb_images(); - break; + break; case 'internal': case 'smf2': case 'mybb': + $this->_load_mxbb_images(); + break; case 'phpbb3': case 'olympus': case 'ascraeus': - case 'rhea': + case 'rhea': + case 'proteus': $this->_load_mxbb_images(); - break; + $this->_load_phpbb_images(); + break; } // Load backend specific style defs. - $this->setup_style(); + //$this->setup_style(); return $row; - } - - /** - * Enter description here... - * - * @param unknown_type $style - * @return unknown - */ - function _style_query($style = true) - { - global $db, $board_config, $portal_config, $template, $phpbb_root_path, $mx_root_path, $theme; - // END Styles_Demo MOD - if (intval($style) == 0) - { - //Query MX style_name - $sql_and = "style_name"; - } - else - { - //Query MX themes_id - $sql_and = "themes_id"; - } - switch (PORTAL_BACKEND) - { - case 'internal': - case 'smf2': - case 'mybb': - $sql = "SELECT * - FROM " . MX_THEMES_TABLE . " - WHERE portal_backend = '" . PORTAL_BACKEND . "' - AND " . $sql_and . " = " . (int) $style; - break; - case 'phpbb2': - $sql = "SELECT bbt.* - FROM " . MX_THEMES_TABLE . " mxt, " . THEMES_TABLE . " bbt - WHERE mxt.style_name = bbt.style_name - AND mxt.portal_backend = '" . PORTAL_BACKEND . "' - AND mxt." . $sql_and . " = " . (int) $style; - break; - case 'phpbb3': - case 'olympus': - case 'ascraeus': - case 'rhea': - $sql = "SELECT t . * , s . * - FROM " . MX_THEMES_TABLE . " AS m, " . STYLES_TABLE . " AS s, " . STYLES_TEMPLATE_TABLE . " AS t, " . STYLES_THEME_TABLE . " AS c, " . STYLES_IMAGESET_TABLE . " i - WHERE m.style_name = s.style_name - AND m.portal_backend = '" . PORTAL_BACKEND . "' - AND t.template_id = s.template_id - AND c.theme_id = s.theme_id - AND i.imageset_id = s.imageset_id - AND m." . $sql_and . " = " . (int) $style; - break; - } - if (!$result = $db->sql_query_limit($sql, 1)) - { - mx_message_die(CRITICAL_ERROR, "Could not query database for theme info '$style_id'", '', __LINE__, __FILE__, $sql); - } - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - //$style_value = $row['style_name']; - //print_R($style_value); - return $row; } /** @@ -1271,7 +2072,7 @@ function _load_template_config() { global $board_config, $images, $theme, $template, $phpbb_root_path, $mx_root_path; - //unset($GLOBALS['MX_TEMPLATE_CONFIG']); + unset($GLOBALS['MX_TEMPLATE_CONFIG']); $mx_template_config = false; // Load MX-Publisher Template configuration data @@ -1288,25 +2089,42 @@ function _load_template_config() case 'internal': case 'smf2': case 'mybb': + //$phpbb_images = $images; + break; case 'phpbb2': - $phpbb_images = $images; + //$phpbb_images = $this->_load_phpbb_images(); break; case 'phpbb3': case 'olympus': case 'ascraeus': case 'rhea': - $phpbb_images = $this->_load_phpbb_images(); + //$phpbb_images = $this->_load_phpbb_images(); break; } - $images = (is_array($phpbb_images) && is_array($images)) ? array_merge($phpbb_images, @$images) : (is_array($images) ? $images: $phpbb_images); - $template_config_filename = $mx_root_path . $this->current_template_path . '/' . $this->template_name . '.cfg'; + + //$images = (is_array($phpbb_images) && is_array($images)) ? array_merge($phpbb_images, @$images) : (is_array($images) ? $images: $phpbb_images); + + // + // Load mxBB Template configuration data + // + $template_config_filename = $mx_root_path . $this->current_template_path . '/' . $this->template_name . '.cfg'; /* *fix for mxp **/ - if ((include $template_config_filename) === false) + if ((@include $template_config_filename) === false) { - print('template config filename ' . $template_config_filename . ' couldn\'t be opened.'); + print('The files for ' . $this->template_name . ' are missing. The template configuration filename ' . $template_config_filename . ' couldn\'t be opened.
'); + // + // Since we have no Template Config file, use default (subSilver) instead + // + @include($mx_root_path . $this->default_current_template_path . '/' . $this->default_template_name . '.cfg'); + + // + // Make default template -> current template + // + $this->template_name = $this->default_template_name; + $this->current_template_path = $this->default_current_template_path; } $this->theme = (is_array($this->theme) && is_array($theme)) ? array_merge($this->theme, @$theme) : (is_array($theme) ? $theme: $this->theme); @@ -1341,10 +2159,7 @@ function _load_template_config() return $template_config_row; } - /** - * Enter description here... - * @access private - */ + /** * Enter description here... * @access private @@ -1361,392 +2176,533 @@ function _load_phpbb_images() case 'smf2': case 'mybb': @define(TEMPLATE_CONFIG, TRUE); + return $images; break; - case 'phpbb2': - /* - * Load phpBB Template configuration data - * - First try current template - */ - if ( file_exists( $phpbb_root_path . $this->current_template_path . "/images" ) ) - { - $current_template_path = $current_template_phpbb_path = $this->current_template_path; - $current_template_phpbb_images = $current_template_path . $this->template_name . "/images"; - $template_name = $this->template_name; - - @include($phpbb_root_path . $this->current_template_path . '/' . $this->template_name . '.cfg'); - } - - /* - * Since we have no current Template Config file, try the cloned template instead - */ - if ( file_exists( $phpbb_root_path . $this->cloned_current_template_path . "/images" ) && !defined('TEMPLATE_CONFIG') ) - { - $current_template_path = $current_template_phpbb_path = $this->cloned_current_template_path; - $current_template_phpbb_images = $current_template_path . "/images"; - $template_name = $this->cloned_template_name; - - @include($phpbb_root_path . $this->cloned_current_template_path . '/' . $this->cloned_template_name . '.cfg'); - } - /* - * Last attempt, use default template intead - */ - if ( file_exists( $phpbb_root_path . $this->default_current_template_path . "/images" ) && !defined('TEMPLATE_CONFIG') ) - { - $current_template_path = $current_template_phpbb_path = $this->default_current_template_path; - $current_template_phpbb_images = $this->default_current_template_path . "/images"; - $template_name = $this->default_template_name; - @include($phpbb_root_path . $this->default_current_template_path . '/' . $this->default_template_name . '.cfg'); - } - break; - case 'phpbb3': - case 'olympus': + default: /* * Load phpBB Template configuration data - * - First prepare the variables - */ - $this->setup_style(); - if (!$this->template_name) - { - trigger_error("Could not get style data: $this->template_name", E_USER_ERROR); - } - if ($this->data['session_logged_in']) - { - $this->lang_name = (file_exists($phpbb_root_path . 'language/' . $this->encode_lang($this->data['user_lang']) . "/common.$phpEx")) ? $this->encode_lang($this->data['user_lang']) : ((file_exists($phpbb_root_path . 'language/' . $this->encode_lang($this->lang['default_lang']) . "/common.$phpEx")) ? $this->encode_lang($this->lang['default_lang']) : 'en'); - $this->lang_path = $phpbb_root_path . 'language/' . $this->lang_name . '/'; + */ + break; + } + + $style_found = ''; //default + + // + // Load phpBB Template configuration data + // - First try current template + // + if (is_dir($phpbb_root_path . $this->current_template_path . "/images/") || is_dir($phpbb_root_path . $this->current_template_path . "/theme/images/")) + { + $current_template_path = $this->current_template_path; + $template_name = $this->template_name; + + $style_found = '_'; //default + } + + // + // Since we have no current Template Config file, try the cloned template instead + // + if ((is_dir($phpbb_root_path . $this->cloned_current_template_path . "/images/") || is_dir($phpbb_root_path . $this->cloned_current_template_path . "/theme/images/")) && empty($style_found) ) + { + $current_template_path = $this->cloned_current_template_path; + $template_name = $this->cloned_template_name; + + $style_found = 'cloned_'; //default + } - $this->date_format = $this->data['user_dateformat']; - $this->timezone = $this->data['user_timezone'] * 3600; - $this->dst = $this->data['user_dst'] * 3600; - } - else - { - $this->lang_name = (file_exists($phpbb_root_path . 'language/' . $this->encode_lang($this->lang['default_lang']) . "/common.$phpEx")) ? $this->encode_lang($this->lang['default_lang']) : 'en'; - $this->lang_path = $phpbb_root_path . 'language/' . $this->lang_name . '/'; - $this->date_format = $board_config['default_dateformat']; - $this->timezone = $board_config['board_timezone'] * 3600; - $this->dst = $board_config['board_dst'] * 3600; - } - $this->img_lang = (@file_exists($phpbb_root_path . 'styles/' . $this->theme['imageset_path'] . '/imageset/' . $this->lang_name)) ? $this->lang_name : $this->encode_lang($board_config['default_lang']); - //$this->template_name = $this->theme['imageset_path']; - //trigger_error("Could not get style data: $this->template_name", E_USER_ERROR); + // + // Last attempt, use default template intead + // + if ((is_dir($phpbb_root_path . $this->default_current_template_path . "/images/") || is_dir($phpbb_root_path . $this->default_current_template_path . "/theme/images/")) && empty($style_found) ) + { + $current_template_path = $this->default_current_template_path; + $template_name = $this->default_template_name; + + $style_found = 'default_'; //default + } + + if(is_dir($phpbb_root_path . $current_template_path . '/theme/images/')) + { + $current_template_images = $this->current_template_images = $current_template_path . "/theme/images"; + } + elseif(is_dir($phpbb_root_path . $this->current_template_path . '/images/')) + { + $current_template_images = $this->current_template_images = $current_template_path . "/images"; + } + + /** + /* Try phpBB2 then phpBB3 style + /* mx_user->_load_phpbb_images( ) + /* Icludes here old phpBB styles configuration file + /* include( 'www\phpbb2\templates\prosilver2\prosilver2.cfg' ) + **/ + if(@file_exists(@phpbb_realpath($phpbb_root_path . $current_template_path . '/' . $template_name . '.cfg')) ) + { + @include($phpbb_root_path . $current_template_path . '/' . $template_name . '.cfg'); + if (!defined('TEMPLATE_CONFIG')) + { // - // Load phpBB Template configuration data - // - Try current template - // - if (file_exists("{$phpbb_root_path}styles/{$this->template_name}/imageset/{$this->img_lang}/imageset.cfg")) - { - $cfg_data_imageset_data = phpBB3::parse_cfg_file("{$phpbb_root_path}styles/{$this->template_name}/imageset/{$this->img_lang}/imageset.cfg"); - - $template_name = $this->template_name; - $default_style_name = $this->default_style_name; - - $current_style_phpbb_path = $this->current_style_phpbb_path = $this->style_path . $this->template_name; //new - $current_template_phpbb_path = $current_style_phpbb_path . "/template"; - $current_template_phpbb_images = @file_exists($phpbb_root_path . $current_style_phpbb_path . "/imageset") ? $current_style_phpbb_path. "/imageset" : (@file_exists($phpbb_root_path . $this->default_style2_name . "/imageset") ? $phpbb_root_path . $this->default_style2_name . "/imageset" : $phpbb_root_path . $this->default_template_name . "/imageset"); - //@include($phpbb_root_path . $current_template_phpbb_images . '/imageset.cfg'); - @define('TEMPLATE_CONFIG', true); - } + // Do not alter this line! // - // Since we have no current Template Config file, try the cloned template instead - /**/ - else if (@file_exists($phpbb_root_path . $this->style_path . $this->cloned_template_name . "/imageset" )) - { - $cfg_data_imageset_data = phpBB3::parse_cfg_file("{$phpbb_root_path}styles/{$this->cloned_template_name}/imageset/{$this->img_lang}/imageset.cfg"); - - $template_name = $this->cloned_template_name; - $default_style_name = $this->default_style_name; - - $cloned_style_phpbb_path = $this->cloned_style_phpbb_path = $this->style_path . $this->cloned_template_name; //new - $current_template_phpbb_path = $cloned_style_phpbb_path . "/template"; - $current_template_phpbb_images = @file_exists($phpbb_root_path . $cloned_style_phpbb_path . "/imageset") ? $this->style_path . $this->cloned_template_name . "/imageset" : (@file_exists($phpbb_root_path . $this->default_style2_name . "/imageset") ? $phpbb_root_path . $this->default_style2_name . "/imageset" : $phpbb_root_path . $this->default_template_name . "/imageset"); - //@include($phpbb_root_path . $this->cloned_current_template_path . '/imageset.cfg'); - @define('TEMPLATE_CONFIG', file_exists($phpbb_root_path . $current_template_phpbb_images . '/imageset.cfg') ? $phpbb_root_path . $current_template_phpbb_images . '/imageset.cfg' : false); - } - /**/ - // Last attempt, use default template intead - /**/ - else if (@file_exists($phpbb_root_path . $this->style_path . $this->default_style_name . "/imageset" )) - { - $cfg_data_imageset_data = phpBB3::parse_cfg_file("{$phpbb_root_path}styles/{$this->default_template_name}/imageset/{$this->img_lang}/imageset.cfg"); - - $template_name = $this->default_template_name; - $default_style_name = $this->default_style_name; - - $default_style_phpbb_path = $this->default_style_phpbb_path = $this->style_path . $this->default_style_name; //new - $current_template_phpbb_path = $default_style_phpbb_path . "/template"; - $current_template_phpbb_images = @file_exists($phpbb_root_path . $default_style_phpbb_path . "/imageset") ? $this->style_path . $this->default_style_name . "/imageset" : (@file_exists($phpbb_root_path . $this->default_style2_name . "/imageset") ? $phpbb_root_path . $this->default_style2_name . "/imageset" : $phpbb_root_path . $this->default_template_name . "/imageset"); - //@include($phpbb_root_path . $this->default_current_template_path . '/' . $this->default_template_name . '.cfg'); - @define('TEMPLATE_CONFIG', file_exists($phpbb_root_path . $current_template_phpbb_images . '/imageset.cfg') ? $phpbb_root_path . $current_template_phpbb_images . '/imageset.cfg' : false); - } - - foreach ($cfg_data_imageset_data as $image_name => $value) - { - if (strpos($value, '*') !== false) - { - if (substr($value, -1, 1) === '*') - { - list($image_filename, $image_height) = explode('*', $value); - $image_width = 0; - } - else - { - list($image_filename, $image_height, $image_width) = explode('*', $value); - } - } - else + @define(TEMPLATE_CONFIG, TRUE); + } + + } + elseif( @file_exists(@phpbb_realpath($phpbb_root_path . $current_template_path . "/style.cfg")) ) + { + // + // Do not alter this line! + // + @define(TEMPLATE_CONFIG, TRUE); + + // + // - First try phpBB2 then phpBB3 template lang images then old Olympus image sets + // + if (is_dir($phpbb_root_path . $current_template_path . '/images/')) + { + $this->current_template_images = $current_template_path . '/images'; + } + else if (is_dir($phpbb_root_path . $current_template_path . '/theme/images/') ) + { + $this->current_template_images = $current_template_path . '/theme/images'; + } + + if (is_dir($phpbb_root_path . $current_template_path . '/imageset/') ) + { + $this->current_template_images = $current_template_path . '/imageset'; + } + + $current_template_images = $this->current_template_images; + + $images['icon_quote'] = "$current_template_images/{LANG}/" . $this->img('icon_post_quote.gif', '', '', '', 'filename'); + $images['icon_edit'] = "$current_template_images/{LANG}/" . $this->img('icon_post_edit.gif', '', '', '', 'filename'); + $images['icon_search'] = "$current_template_images/{LANG}/" . $this->img('icon_user_search.gif', '', '', '', 'filename'); + $images['icon_profile'] = "$current_template_images/{LANG}/" . $this->img('icon_user_profile.gif', '', '', '', 'filename'); + $images['icon_pm'] = "$current_template_images/{LANG}/" . $this->img('icon_contact_pm.gif', '', '', '', 'filename'); + $images['icon_email'] = "$current_template_images/{LANG}/" . $this->img('icon_contact_email.gif', '', '', '', 'filename'); + $images['icon_delpost'] = "$current_template_images/{LANG}/" . $this->img('icon_post_delete.gif', '', '', '', 'filename'); + $images['icon_ip'] = "$current_template_images/{LANG}/" . $this->img('icon_user_ip.gif', '', '', '', 'filename'); + $images['icon_www'] = "$current_template_images/{LANG}/" . $this->img('icon_contact_www.gif', '', '', '', 'filename'); + $images['icon_icq'] = "$current_template_images/{LANG}/" . $this->img('icon_contact_icq_add.gif', '', '', '', 'filename'); + $images['icon_aim'] = "$current_template_images/{LANG}/" . $this->img('icon_contact_aim.gif', '', '', '', 'filename'); + $images['icon_yim'] = "$current_template_images/{LANG}/" . $this->img('icon_contact_yim.gif', '', '', '', 'filename'); + $images['icon_msnm'] = "$current_template_images/{LANG}/" . $this->img('icon_contact_msnm.gif', '', '', '', 'filename'); + $images['icon_minipost'] = "$current_template_images/" . $this->img('icon_post_target.gif', '', '', '', 'filename'); + $images['icon_gotopost'] = "$current_template_images/" . $this->img('icon_gotopost.gif', '', '', '', 'filename'); + $images['icon_minipost_new'] = "$current_template_images/" . $this->img('icon_post_target_unread.gif', '', '', '', 'filename'); + $images['icon_latest_reply'] = "$current_template_images/" . $this->img('icon_latest_reply.gif', '', '', '', 'filename'); + $images['icon_newest_reply'] = "$current_template_images/" . $this->img('icon_newest_reply.gif', '', '', '', 'filename'); + + $images['forum'] = "$current_template_images/" . $this->img('forum_read.gif', '', '27', '', 'filename'); + $images['forum_new'] = "$current_template_images/" . $this->img('forum_unread.gif', '', '', '', 'filename'); + $images['forum_locked'] = "$current_template_images/" . $this->img('forum_read_locked.gif', '', '', '', 'filename'); + + // Begin Simple Subforums MOD + $images['forums'] = "$current_template_images/" . $this->img('forum_read_subforum.gif', '', '', '', 'filename'); + $images['forums_new'] = "$current_template_images/" . $this->img('forum_unread_subforum.gif', '', '', '', 'filename'); + // End Simple Subforums MOD + + $images['folder'] = "$current_template_images/" . $this->img('topic_read.gif', '', '', '', 'filename'); + $images['folder_new'] = "$current_template_images/" . $this->img('topic_unread.gif', '', '', '', 'filename'); + $images['folder_hot'] = "$current_template_images/" . $this->img('topic_read_hot.gif', '', '', '', 'filename'); + $images['folder_hot_new'] = "$current_template_images/" . $this->img('topic_unread_hot.gif', '', '', '', 'filename'); + $images['folder_locked'] = "$current_template_images/" . $this->img('topic_read_locked.gif', '', '', '', 'filename'); + $images['folder_locked_new'] = "$current_template_images/" . $this->img('topic_unread_locked.gif', '', '', '', 'filename'); + $images['folder_sticky'] = "$current_template_images/" . $this->img('topic_read_mine.gif', '', '', '', 'filename'); + $images['folder_sticky_new'] = "$current_template_images/" . $this->img('topic_unread_mine.gif', '', '', '', 'filename'); + $images['folder_announce'] = "$current_template_images/" . $this->img('announce_read.gif', '', '', '', 'filename'); + $images['folder_announce_new'] = "$current_template_images/" . $this->img('announce_unread.gif', '', '', '', 'filename'); + + $images['post_new'] = "$current_template_images/{LANG}/" . $this->img('button_topic_new.gif', '', '', '', 'filename'); + $images['post_locked'] = "$current_template_images/{LANG}/" . $this->img('button_topic_locked.gif', '', '', '', 'filename'); + $images['reply_new'] = "$current_template_images/{LANG}/" . $this->img('button_topic_reply.gif', '', '', '', 'filename'); + $images['reply_locked'] = "$current_template_images/{LANG}/" . $this->img('icon_post_target_unread.gif', '', '', '', 'filename'); + + $images['pm_inbox'] = "$current_template_images/" . $this->img('msg_inbox.gif', '', '', '', 'filename'); + $images['pm_outbox'] = "$current_template_images/" . $this->img('msg_outbox.gif', '', '', '', 'filename'); + $images['pm_savebox'] = "$current_template_images/" . $this->img('msg_savebox.gif', '', '', '', 'filename'); + $images['pm_sentbox'] = "$current_template_images/" . $this->img('msg_sentbox.gif', '', '', '', 'filename'); + $images['pm_readmsg'] = "$current_template_images/" . $this->img('topic_read.gif', '', '', '', 'filename'); + $images['pm_unreadmsg'] = "$current_template_images/" . $this->img('topic_unread.gif', '', '', '', 'filename'); + $images['pm_replymsg'] = "$current_template_images/{LANG}/" . $this->img('reply.gif', '', '', '', 'filename'); + $images['pm_postmsg'] = "$current_template_images/{LANG}/" . $this->img('msg_newpost.gif', '', '', '', 'filename'); + $images['pm_quotemsg'] = "$current_template_images/{LANG}/" . $this->img('icon_quote.gif', '', '', '', 'filename'); + $images['pm_editmsg'] = "$current_template_images/{LANG}/" . $this->img('icon_edit.gif', '', '', '', 'filename'); + $images['pm_new_msg'] = ""; + $images['pm_no_new_msg'] = ""; + + $images['Topic_watch'] = ""; + $images['topic_un_watch'] = ""; + $images['topic_mod_lock'] = "$current_template_images/" . $this->img('topic_lock.gif', '', '', '', 'filename'); + $images['topic_mod_unlock'] = "$current_template_images/" . $this->img('topic_unlock.gif', '', '', '', 'filename'); + $images['topic_mod_split'] = "$current_template_images/" . $this->img('topic_split.gif', '', '', '', 'filename'); + $images['topic_mod_move'] = "$current_template_images/" . $this->img('topic_move.gif', '', '', '', 'filename'); + $images['topic_mod_delete'] = "$current_template_images/" . $this->img('topic_delete.gif', '', '', '', 'filename'); + + $images['voting_graphic'][0] = "$current_template_images/voting_bar.gif"; + $images['voting_graphic'][1] = "$current_template_images/voting_bar.gif"; + $images['voting_graphic'][2] = "$current_template_images/voting_bar.gif"; + $images['voting_graphic'][3] = "$current_template_images/voting_bar.gif"; + $images['voting_graphic'][4] = "$current_template_images/voting_bar.gif"; + + @include($phpbb_root_path . $this->cloned_current_template_path . '/' . $this->cloned_template_name . '.cfg'); + + // + // Vote graphic length defines the maximum length of a vote result + // graphic, ie. 100% = this length + // + $board_config['vote_graphic_length'] = 205; + $board_config['privmsg_graphic_length'] = 175; + } + else + { + if ((@include $phpbb_root_path . $this->template_path . "prosilver2/prosilver2.cfg") === false) + { + mx_message_die(CRITICAL_ERROR, "Could not open phpBB $this->template_name template config file", '', __LINE__, __FILE__); + } + else + { + print_r("Could not open phpBB $this->template_name template config file"); + } + } + + // + // We have no template to use - die + // + if ( !defined('TEMPLATE_CONFIG') ) + { + // + // Load phpBB Template configuration data + // - Last try current template + // + if ((@include $phpbb_root_path . $this->template_path . $this->template_name . '/' . $this->template_name . '.cfg') === false) + { + mx_message_die(CRITICAL_ERROR, "Could not open phpBB $this->template_name template config file", '', __LINE__, __FILE__); + } + } + + $parsed_array = $this->cache->get('_cfg_' . $this->template_path); + + if ($parsed_array === false) + { + $parsed_array = array(); + } + + // + // Try phpBB2 then phpBB3 style configuration file + // + if(@file_exists(@phpbb_realpath($phpbb_root_path . $current_template_path . '/' . $template_name . '.cfg')) ) + { + //parse phpBB2 style cfg file + $cfg_file_name = $this->template_name . '.cfg'; + $cfg_file = $phpbb_root_path . $this->current_template_path . '/' . $cfg_file_name; + + if (file_exists($phpbb_root_path . $this->current_template_path . '/' . $cfg_file_name)) + { + if (!isset($parsed_array['filetime']) || (@filemtime($cfg_file) > $parsed_array['filetime'])) + { + $parsed_array = parse_cfg_file($cfg_file); + $parsed_array['filetime'] = @filemtime($cfg_file); + $this->cache->put('_cfg_' . $this->template_path, $parsed_array); + } + } + } + elseif( @file_exists(@phpbb_realpath($phpbb_root_path . $this->current_template_path . '/style.cfg')) ) + { + //parse phpBB3 style cfg file + $cfg_file_name = 'style.cfg'; + $cfg_file = $phpbb_root_path . $this->current_template_path . '/style.cfg'; + + if (!isset($parsed_array['filetime']) || (@filemtime($cfg_file) > $parsed_array['filetime'])) + { + // Re-parse cfg file + $parsed_array = parse_cfg_file($cfg_file); + $parsed_array['filetime'] = @filemtime($cfg_file); + $this->cache->put('_cfg_' . $this->template_path, $parsed_array); + } + } + $check_for = array( + 'pagination_sep' => (string) ', ' + ); + + foreach ($check_for as $key => $default_value) + { + //$this->style[$key] = (isset($parsed_array[$key])) ? $parsed_array[$key] : $default_value; + $this->theme[$key] = (isset($parsed_array[$key])) ? $parsed_array[$key] : $default_value; + //settype($this->style[$key], gettype($default_value)); + settype($this->theme[$key], gettype($default_value)); + if (is_string($default_value)) + { + //$this->style[$key] = htmlspecialchars($this->style[$key]); + $this->theme[$key] = htmlspecialchars($this->theme[$key]); + } + } + + // If the style author specified the theme needs to be cached + // (because of the used paths and variables) than make sure it is the case. + // For example, if the theme uses language-specific images it needs to be stored in db. + if (file_exists($phpbb_root_path . $this->template_path . $this->template_name . '/theme/stylesheet.css')) + { + //phpBB3 Style Sheet + $theme_file = 'stylesheet.css'; + $css_file_path = $this->template_path . $this->template_name . '/theme/'; + $stylesheet = file_get_contents("{$phpbb_root_path}{$this->template_path}{$this->template_name}/theme/stylesheet.css"); + } + else + { + //phpBB2 Style Sheet + $theme_file = !empty($this->theme['head_stylesheet']) ? $this->theme['head_stylesheet'] : $this->template_name . '.css'; + $css_file_path = $this->template_path . $this->template_name . '/'; + if (file_exists($phpbb_root_path . $this->template_path . $this->template_name . '/' . $theme_file)) + { + $stylesheet = file_get_contents("{$phpbb_root_path}{$this->template_path}{$this->template_name}/{$theme_file}"); + } + } + + if (!empty($stylesheet)) + { + // Match CSS imports + $matches = array(); + preg_match_all('/@import url\(["\'](.*)["\']\);/i', $stylesheet, $matches); + + if (sizeof($matches)) + { + $content = ''; + foreach ($matches[0] as $idx => $match) + { + if ($content = @file_get_contents("{$phpbb_root_path}{$css_file_path}" . $matches[1][$idx])) { - $image_filename = $value; - $image_height = $image_width = 0; + $content = trim($content); } - - if (strpos($image_name, 'img_') === 0 && $image_filename) + else { - $image_name = substr($image_name, 4); - /* - $image_ary[] = array( - 'image_name' => (string) $image_name, - 'image_filename' => (string) $image_filename, - 'image_height' => (int) $image_height, - 'image_width' => (int) $image_width, - 'imageset_id' => (int) $this->theme['imageset_id'], - 'image_lang' => (string) $this->img_lang, - ); - */ - //Here we overwrite phpBB3 images names from the template configuration file with images file names from database - //$phpbb_images[$image_name] = $image_filename; - $images[$image_name] = $this->images($image_name); - //$images = is_array($images) ? array_merge($phpbb_images, $images) : $phpbb_images; - } + $content = ''; + } + $stylesheet = str_replace($match, $content, $stylesheet); } - - /**/ - //Here we overwrite phpBB images from the template configuration file with images from database - $images['icon_quote'] = $this->images('img_icon_post_quote'); - $images['icon_edit'] = $this->images('img_icon_post_edit'); - $images['icon_search'] = $this->images('img_icon_user_search'); - $images['icon_profile'] = $this->images('img_icon_user_profile'); - $images['icon_pm'] = $this->images('img_icon_contact_pm'); - $images['icon_email'] = $this->images('img_icon_contact_email'); - $images['icon_delpost'] = $this->images('img_icon_post_delete'); - //$images['icon_ip'] = $this->images('icon_ip'); - $images['icon_www'] = $this->images('img_icon_contact_www'); - $images['icon_icq'] = $this->images('img_icon_contact_icq'); - $images['icon_aim'] = $this->images('img_icon_contact_aim'); - $images['icon_yim'] = $this->images('img_icon_contact_yahoo'); - $images['icon_msnm'] = $this->images('img_icon_contact_msnm'); - $images['icon_minipost'] = $this->images('img_icon_minipost'); - $images['icon_gotopost'] = $this->images('img_icon_gotopost'); - $images['icon_minipost_new'] = $this->images('img_icon_minipost_new'); - $images['icon_latest_reply'] = $images['img_icon_topic_latest'] = $this->images('img_icon_topic_latest'); - $images['icon_newest_reply'] = $this->images('img_icon_newest_reply'); - - $images['forum'] = $this->images('img_forum_read'); - $images['forums'] = $this->images('img_forum_read_subforum'); - $images['forum_new'] = $this->images('img_forum_unread'); - $images['forum_locked'] = $this->images('img_forum_read_locked'); - - $images['folder'] = $images['topic_read'] = $this->images('img_topic_read'); - $images['folder_new'] = $images['topic_unread'] = $this->images('img_topic_unread'); - $images['folder_hot'] = $images['topic_hot'] = $this->images('img_topic_read_hot'); - $images['folder_hot_new'] = $images['topic_hot_unread'] = $this->images('img_topic_unread_hot'); - $images['folder_locked'] = $images['topic_locked'] = $this->images('img_topic_unread_locked'); - $images['folder_locked_new'] = $images['topic_locked_unread'] = $this->images('img_topic_locked_unread'); - $images['folder_sticky'] = $images['topic_sticky'] = $this->images('img_topic_read_mine'); - $images['folder_sticky_new'] = $images['topic_sticky_unread'] = $this->images('img_topic_unread_mine'); - $images['folder_announce'] = $images['topic_announce'] = $this->images('img_announce_read'); - $images['folder_announce_new'] = $images['topic_announce_unread'] = $this->images('img_announce_unread'); - - $images['post_new'] = $this->images('img_button_topic_new'); - $images['post_locked'] = $this->images('img_button_topic_locked'); - $images['reply_new'] = $this->images('img_button_topic_reply'); - $images['reply_locked'] = $this->images('img_icon_post_target_unread'); - - /* - $images['pm_inbox'] = $this->images('pm_inbox'); - $images['pm_outbox'] = $this->images('pm_outbox'); - $images['pm_savebox'] = $this->images('pm_savebox'); - $images['pm_sentbox'] = $this->images('pm_sentbox'); - $images['pm_readmsg'] = $this->images('pm_readmsg'); - $images['pm_unreadmsg'] = $this->images('pm_unreadmsg'); - $images['pm_replymsg'] = $this->images('pm_replymsg'); - $images['pm_postmsg'] = $this->images('pm_postmsg'); - $images['pm_quotemsg'] = $this->images('pm_quotemsg'); - $images['pm_editmsg'] = $this->images('pm_editmsg'); - $images['pm_new_msg'] = $this->images('pm_new_msg'); - $images['pm_no_new_msg'] = $this->images('pm_no_new_msg'); - - $images['Topic_watch'] = $this->images('Topic_watch'); - $images['topic_un_watch'] = $this->images('topic_un_watch'); - $images['topic_mod_lock'] = $this->images('topic_mod_lock'); - $images['topic_mod_unlock'] = $this->images('topic_mod_unlock'); - $images['topic_mod_split'] = $this->images('topic_mod_split'); - $images['topic_mod_move'] = $this->images('topic_mod_move'); - $images['topic_mod_delete'] = $this->images('topic_mod_delete'); - - $images['voting_graphic'] = $this->images('voting_graphic'); - /**/ - - @define('TEMPLATE_CONFIG', TRUE); - // We include common temlate config file here to not load it every time a module template config file is included - //$this->theme = is_array($this->theme) ? array_merge($this->theme, $theme) : $theme; - //$this->theme = &$theme; - - break; - case 'ascraeus': - case 'rhea': - /* - * Load phpBB Template configuration data - * - First prepare the variables - */ - $this->setup_style(); - if (!$this->template_name) + unset($content); + } + + $stylesheet = str_replace('./', $css_file_path, $stylesheet); + + $theme_info = array( + 'theme_data' => $stylesheet, + 'theme_mtime' => time(), + 'theme_storedb' => 0 + ); + $theme_data = &$theme_info['theme_data']; + } + + // + // - First try old Olympus image sets then phpBB2 and phpBB3 Proteus template lang images + // + if (is_dir("{$phpbb_root_path}{$this->template_path}{$this->template_name}/imageset/")) + { + $this->imageset_path = '/imageset/'; //Olympus ImageSet + $this->img_lang = (file_exists($phpbb_root_path . $this->template_path . $this->template_name . $this->imageset_path . $this->lang_iso)) ? $this->lang_iso : $this->default_language; + $this->img_lang_dir = $this->img_lang; + $this->imageset_backend = 'olympus'; + } + elseif (@is_dir("{$phpbb_root_path}{$this->template_path}{$this->template_name}/theme/images/")) + { + if ((@is_dir("{$phpbb_root_path}{$this->template_path}{$this->template_name}/theme/lang_{$this->user_language_name}")) || (@is_dir("{$phpbb_root_path}{$this->template_path}{$this->template_name}/theme/lang_{$this->default_language_name}"))) + { + $this->imageset_path = '/theme/images/'; //phpBB3 Images + $this->img_lang = (file_exists($phpbb_root_path . $this->template_path . $this->template_name . '/theme/' . 'lang_' . $this->user_language_name)) ? $this->user_language_name : $this->default_language_name; + $this->img_lang_dir = 'lang_' . $this->img_lang; + $this->imageset_backend = 'phpbb2'; + } + if ((@is_dir("{$phpbb_root_path}{$this->template_path}{$this->template_name}/theme/{$this->user_language}")) || (@is_dir("{$phpbb_root_path}{$this->template_path}{$this->template_name}/theme/{$this->default_language}"))) + { + $this->imageset_path = '/theme/images/'; //phpBB3 Images + $this->img_lang = (file_exists($phpbb_root_path . $this->template_path . $this->template_name . '/theme/' . $this->user_language_name)) ? $this->user_language : $this->default_language; + $this->img_lang_dir = $this->img_lang; + $this->imageset_backend = 'phpbb3'; + } + } + elseif (@is_dir("{$phpbb_root_path}{$this->template_path}{$this->template_name}/images/")) + { + $this->imageset_path = '/images/'; //phpBB2 Images + $this->img_lang = (is_dir($phpbb_root_path . $this->template_path . $this->template_name . $this->imageset_path . '/images/lang_' . $this->user_language_name)) ? $this->user_language_name : $this->default_language_name; + $this->img_lang_dir = 'lang_' . $this->img_lang; + $this->imageset_backend = 'phpbb2'; + } + + // + // phpBB2 image sets main images + // + $img_lang = ( is_dir($phpbb_root_path . $this->current_template_path . $this->img_lang_dir) ) ? $this->img_lang : $this->default_language_name; + + // + // Import phpBB Graphics, prefix with PHPBB_URL, and apply LANG info + // + while( list($key, $value) = @each($images) ) + { + if (is_array($value)) + { + foreach( $value as $key2 => $val2 ) { - trigger_error("Could not get style data: $this->template_name", E_USER_ERROR); + $this->images[$key][$key2] = $images[$key][$key2] = PHPBB_URL . $val2; } + } + else + { + $this->images[$key] = $images[$key] = str_replace('{LANG}', 'lang_' . $img_lang, $value); + $this->images[$key] = $images[$key] = PHPBB_URL . $images[$key]; + } + + if(empty($images['forum'])) + { + //print_r('Your style configuration file has a typo! '); + //print_r($images); + $images['forum'] = 'folder.gif'; + } + + /* Here we overwrite phpBB images from the template db or configuration file */ + $rows = $this->image_rows($images); + + foreach ($rows as $row) + { + $row['image_filename'] = rawurlencode($row['image_filename']); - if ($this->data['session_logged_in']) + if(empty($row['image_name'])) { - $this->lang_name = (file_exists($phpbb_root_path . 'language/' . $this->encode_lang($this->data['user_lang']) . "/common.$phpEx")) ? $this->encode_lang($this->data['user_lang']) : ((file_exists($phpbb_root_path . 'language/' . $this->encode_lang($this->lang['default_lang']) . "/common.$phpEx")) ? $this->encode_lang($this->lang['default_lang']) : 'en'); - $this->lang_path = $phpbb_root_path . 'language/' . $this->lang_name . '/'; - - $this->date_format = $this->data['user_dateformat']; - $this->timezone = $this->data['user_timezone'] * 3600; - $this->dst = $this->data['user_dst'] * 3600; + //print_r('Your style configuration file has a typo! '); + //print_r($row); + $row['image_name'] = 'spacer.gif'; + } + + $this->img_array[$row['image_name']] = $row; + } + } + + //print_r($images); + // Import phpBB Olympus image sets main images + // + if (@file_exists("{$phpbb_root_path}{$this->template_path}{$this->template_name}{$this->imageset_path}/imageset.cfg")) + { + $cfg_data_imageset = parse_cfg_file("{$phpbb_root_path}{$this->template_path}{$this->template_name}{$this->imageset_path}/imageset.cfg"); + + foreach ($cfg_data_imageset as $image_name => $value) + { + if (strpos($value, '*') !== false) + { + if (substr($value, -1, 1) === '*') + { + list($image_filename, $image_height) = explode('*', $value); + $image_width = 0; + } + else + { + list($image_filename, $image_height, $image_width) = explode('*', $value); + } } else { - $this->lang_name = (file_exists($phpbb_root_path . 'language/' . $this->encode_lang($this->lang['default_lang']) . "/common.$phpEx")) ? $this->encode_lang($this->lang['default_lang']) : 'en'; - $this->lang_path = $phpbb_root_path . 'language/' . $this->lang_name . '/'; - $this->date_format = $board_config['default_dateformat']; - $this->timezone = $board_config['board_timezone'] * 3600; - $this->dst = $board_config['board_dst'] * 3600; + $image_filename = $value; + $image_height = $image_width = 0; } - $this->img_lang = (@file_exists($phpbb_root_path . 'styles/' . $this->theme['imageset_path'] . '/theme/' . $this->lang_name)) ? $this->lang_name : $this->encode_lang($board_config['default_lang']); - //$this->template_name = $this->theme['imageset_path']; - //trigger_error("Could not get style data: $this->template_name", E_USER_ERROR); - - // - // Load phpBB Template configuration data - // - Try current template - // - if (file_exists("{$phpbb_root_path}styles/{$this->template_name}/style.cfg")) - { - $template_name = $this->template_name; - $default_style_name = $this->default_style_name; - - $current_style_phpbb_path = $this->current_style_phpbb_path = $this->style_path . $this->template_name; //new - $current_template_phpbb_path = $current_style_phpbb_path . "/template"; - $current_template_phpbb_images = @file_exists($phpbb_root_path . $current_style_phpbb_path . "/theme/images") ? $current_style_phpbb_path. "/theme/images" : (@file_exists($phpbb_root_path . $this->default_style2_name . "/theme/images") ? $phpbb_root_path . $this->default_style2_name . "/theme/images" : $phpbb_root_path . $this->default_template_name . "/theme/images"); - @define('TEMPLATE_CONFIG', true); - } - // - // Since we have no cloned Template Config file, try the cloned template instead - /**/ - else if (@file_exists($phpbb_root_path . $this->style_path . $this->cloned_template_name . "/style.cfg")) - { - $template_name = $this->cloned_template_name; - $default_style_name = $this->default_style_name; - - $cloned_style_phpbb_path = $this->cloned_style_phpbb_path = $this->style_path . $this->cloned_template_name; //new - $current_template_phpbb_path = $cloned_style_phpbb_path . "/template"; - $current_template_phpbb_images = @file_exists($phpbb_root_path . $cloned_style_phpbb_path . "/theme/images") ? $this->style_path . $this->cloned_template_name . "/theme/images" : (@file_exists($phpbb_root_path . $this->default_style2_name . "/theme/images") ? $phpbb_root_path . $this->default_style2_name . "/theme/images" : $phpbb_root_path . $this->default_template_name . "/theme/images"); - @define('TEMPLATE_CONFIG', true); - } - /**/ - // Last attempt, use default template intead - /**/ - else if (@file_exists($phpbb_root_path . $this->style_path . $this->default_style_name . "/style.cfg" )) - { - $template_name = $this->default_template_name; - $default_style_name = $this->default_style_name; + if (strpos($image_name, 'img_') === 0 && $image_filename) + { + $image_name = substr($image_name, 4); + $row[] = array( + 'image_name' => (string) $image_name, + 'image_filename' => (string) $image_filename, + 'image_height' => (int) $image_height, + 'image_width' => (int) $image_width, + 'imageset_id' => (int) $style_id, + 'image_lang' => '', + ); - $default_style_phpbb_path = $this->default_style_phpbb_path = $this->style_path . $this->default_style_name; //new - $current_template_phpbb_path = $default_style_phpbb_path . "/template"; - $current_template_phpbb_images = @file_exists($phpbb_root_path . $default_style_phpbb_path . "/theme/images") ? $this->style_path . $this->default_style_name . "/imageset" : (@file_exists($phpbb_root_path . $this->default_style2_name . "/imageset") ? $phpbb_root_path . $this->default_style2_name . "/imageset" : $phpbb_root_path . $this->default_template_name . "/imageset"); - @define('TEMPLATE_CONFIG', true); + if (!empty($row['image_lang'])) + { + $localised_images = true; + } + $row['image_filename'] = !empty($row['image_filename']) ? rawurlencode($row['image_filename']) : ''; + $row['image_name'] = !empty($row['image_name']) ? rawurlencode($row['image_name']) : ''; + $this->img_array[$row['image_name']] = $row; } - - - /**/ - //Here we overwrite phpBB images from the template configuration file with images from css - $images['icon_quote'] = $this->images('img_icon_post_quote'); - $images['icon_edit'] = $this->images('img_icon_post_edit'); - $images['icon_search'] = $this->images('img_icon_user_search'); - $images['icon_profile'] = $this->images('img_icon_user_profile'); - $images['icon_pm'] = $this->images('img_icon_contact_pm'); - $images['icon_email'] = $this->images('img_icon_contact_email'); - $images['icon_delpost'] = $this->images('img_icon_post_delete'); - //$images['icon_ip'] = $this->images('icon_ip'); - $images['icon_www'] = $this->images('img_icon_contact_www'); - $images['icon_icq'] = $this->images('img_icon_contact_icq'); - $images['icon_aim'] = $this->images('img_icon_contact_aim'); - $images['icon_yim'] = $this->images('img_icon_contact_yahoo'); - $images['icon_msnm'] = $this->images('img_icon_contact_msnm'); - $images['icon_minipost'] = $this->images('img_icon_minipost'); - $images['icon_gotopost'] = $this->images('img_icon_gotopost'); - $images['icon_minipost_new'] = $this->images('img_icon_minipost_new'); - $images['icon_latest_reply'] = $images['img_icon_topic_latest'] = $this->images('img_icon_topic_latest'); - $images['icon_newest_reply'] = $this->images('img_icon_newest_reply'); - - $images['forum'] = $this->images('img_forum_read'); //images/forum_read.gif - $images['forums'] = $this->images('img_forum_read_subforum'); - $images['forum_new'] = $this->images('img_forum_unread'); - $images['forum_locked'] = $this->images('img_forum_read_locked'); - - $images['folder'] = $images['topic_read'] = $this->images('img_topic_read'); - $images['folder_new'] = $images['topic_unread'] = $this->images('img_topic_unread'); - $images['folder_hot'] = $images['topic_hot'] = $this->images('img_topic_read_hot'); - $images['folder_hot_new'] = $images['topic_hot_unread'] = $this->images('img_topic_unread_hot'); - $images['folder_locked'] = $images['topic_locked'] = $this->images('img_topic_unread_locked'); - $images['folder_locked_new'] = $images['topic_locked_unread'] = $this->images('img_topic_locked_unread'); - $images['folder_sticky'] = $images['topic_sticky'] = $this->images('img_topic_read_mine'); - $images['folder_sticky_new'] = $images['topic_sticky_unread'] = $this->images('img_topic_unread_mine'); - $images['folder_announce'] = $images['topic_announce'] = $this->images('img_announce_read'); - $images['folder_announce_new'] = $images['topic_announce_unread'] = $this->images('img_announce_unread'); - - $images['post_new'] = $this->images('img_button_topic_new'); - $images['post_locked'] = $this->images('img_button_topic_locked'); - $images['reply_new'] = $this->images('img_button_topic_reply'); - $images['reply_locked'] = $this->images('img_icon_post_target_unread'); - - //@define('TEMPLATE_CONFIG', TRUE); - // We include common temlate config file here to not load it every time a module template config file is included - //$this->theme = is_array($this->theme) ? array_merge($this->theme, $theme) : $theme; - //$this->theme = &$theme; - break; + } } - /* - * We have no template to use - die - */ - if ( !defined('TEMPLATE_CONFIG') ) + // + // - Olympus image sets lolalised images + // + if (@file_exists("{$phpbb_root_path}{$this->template_path}{$this->template_name}{$this->imageset_path}{$this->img_lang}/imageset.cfg")) { - mx_message_die(CRITICAL_ERROR, "Could not open phpBB $this->template_name template config file", '', __LINE__, __FILE__); + $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}{$this->template_path}{$this->template_name}{$this->imageset_path}{$this->img_lang}/imageset.cfg"); + foreach ($cfg_data_imageset_data as $image_name => $value) + { + if (strpos($value, '*') !== false) + { + if (substr($value, -1, 1) === '*') + { + list($image_filename, $image_height) = explode('*', $value); + $image_width = 0; + } + else + { + list($image_filename, $image_height, $image_width) = explode('*', $value); + } + } + else + { + $image_filename = $value; + $image_height = $image_width = 0; + } + + if (strpos($image_name, 'img_') === 0 && $image_filename) + { + $image_name = substr($image_name, 4); + $row[] = array( + 'image_name' => (string) $image_name, + 'image_filename' => (string) $image_filename, + 'image_height' => (int) $image_height, + 'image_width' => (int) $image_width, + 'imageset_id' => !empty($this->theme['imageset_id']) ? (int) $this->theme['imageset_id'] : 0, + 'image_lang' => (string) $this->img_lang, + ); + + if (!empty($row['image_lang'])) + { + $localised_images = true; + } + $row['image_filename'] = !empty($row['image_filename']) ? rawurlencode($row['image_filename']) : ''; + $row['image_name'] = !empty($row['image_name']) ? rawurlencode($row['image_name']) : ''; + $this->img_array[$row['image_name']] = $row; + } + } } - $img_lang = ( file_exists($phpbb_root_path . $this->current_template_path . '/images/lang_' . $this->encode_lang($this->lang['default_lang'])) ) ? $this->encode_lang($this->lang['default_lang']) : 'english'; - - /* - * Import phpBB Graphics, prefix with PHPBB_URL, and apply LANG info - */ - while( list($key, $value) = @each($images) ) + // + // - Import phpBB phpBB3 Rhea and Proteus images + // + if (empty($this->img_array)) { - if (is_array($value)) + /** + * Now check for the correct existance of all of the images into + * each image of a prosilver based style. + * / + + /* Here we overwrite phpBB images from the template db or configuration file */ + $rows = $this->image_rows($this->images); + + foreach ($rows as $row) { - foreach( $value as $key2 => $val2 ) + $row['image_filename'] = rawurlencode($row['image_filename']); + + if(empty($row['image_name'])) { - $images[$key][$key2] = str_replace(PORTAL_URL . PHPBB_URL, PHPBB_URL, $val2); + //print_r('Your style configuration file has a typo! '); + //print_r($row); + $row['image_name'] = 'spacer.gif'; } - } - else - { - $images[$key] = str_replace('{LANG}', 'lang_' . $img_lang, $value); - $images[$key] = str_replace(PORTAL_URL . PHPBB_URL, PHPBB_URL, $images[$key]); - } - } - return $images; + + $this->img_array[$row['image_name']] = $row; + } + } } /** @@ -1776,16 +2732,19 @@ function _load_mxbb_images($module_root_path = '') case 'internal': case 'smf2': case 'mybb': + $template_name2 = 'mxSilver'; @define(TEMPLATE_CONFIG, TRUE); break; - case 'phpbb2': + case 'phpbb2': + $template_name2 = 'subSilver'; break; case 'phpbb3': case 'olympus': case 'ascraeus': - case 'rhea': + case 'rhea': + $template_name2 = 'subsilver2'; /**/ // Here we overwrite phpBB images from the template configuration file with images from database $images['icon_quote'] = $this->images('icon_quote'); @@ -1863,18 +2822,41 @@ function _load_mxbb_images($module_root_path = '') $default_template_path = $default_template_path_d = $module_root_path . $this->default_current_template_path; $template_name = $template_name_d = $this->template_name; $template_config_d = TEMPLATE_CONFIG; - - //@define('MX_TEMPLATE_CONFIG', false); + + /** + /* Try phpBB2 then phpBB3 style + /* mx_user->_load_mxbb_images( ) + /* Icludes here MXP styles configuration file + /* include( 'www\templates\prosilver2\prosilver2.cfg' ) + **/ + unset($GLOBALS['MX_TEMPLATE_CONFIG']); $mx_template_config = false; if (@file_exists($mx_root_path . $module_root_path . $this->current_template_path . '/' . $template_name . '.cfg')) - { + { include($mx_root_path . $module_root_path . $this->current_template_path . '/' . $template_name . '.cfg'); } + if ($module_root_path == 'modules/mx_coreblocks/') + { + // - default module already populated in root core folder + $mx_template_config = true; + } + if (!$mx_template_config) { - include($mx_root_path . $module_root_path . $this->current_template_path . '/' . $moduleCfgFile . '.cfg'); - } + if (@file_exists($mx_root_path . $module_root_path . $this->current_template_path . '/' . $moduleCfgFile . '.cfg')) + { + include($mx_root_path . $module_root_path . $this->current_template_path . '/' . $moduleCfgFile . '.cfg'); + } + } + + if (!$mx_template_config) + { + if (@file_exists($mx_root_path . $module_root_path . $this->current_template_path . '/_core.cfg')) + { + include($mx_root_path . $module_root_path . $this->current_template_path . '/_core.cfg'); + } + } /* * Since we have no current Template Config file, try the cloned template instead @@ -1911,8 +2893,6 @@ function _load_mxbb_images($module_root_path = '') */ if (!$mx_template_config) { - $template_name2 = 'subSilver'; - $current_template_path = $module_root_path . $this->default_current_template_path; $template_name = $this->default_template_name; @@ -1955,41 +2935,244 @@ function _load_mxbb_images($module_root_path = '') $this->template_names[$module_key] = $template_name; //This will keep loaded images - $images = &$mx3_images; + $this->images = $images = &$mx3_images; // We include common temlate config file here to not load it every time a module template config file is included //$this->theme = is_array($this->theme) ? array_merge($this->theme, $theme) : $theme; $this->theme = &$theme; unset($mx_images); } - + /** * Enter description here... * * @access private * @param unknown_type $lang_mode - */ - function _load_module_lang($lang_mode = MX_LANG_MAIN) + */ + function _load_lang($path, $filename, $require = true) { - global $lang, $board_config, $mx_block, $phpEx, $mx_root_path; - $default_lang = ($this->lang['default_lang']) ? $this->decode_lang($this->lang['default_lang']) : $board_config['default_lang']; - if (empty($default_lang)) + $lang = array(); + + $board_config = $this->config; + $php_ext = $this->php_ext; + + // Now only the root for mxp blocks + $user_path = $path . 'language/lang_' . $this->data['user_lang'] . '/' . $filename . '.' . $php_ext; + $board_path = $path . 'language/lang_' . $board_config['default_lang'] . '/' . $filename . '.' . $php_ext; + $default_path = $path . 'language/lang_english/' . $filename . '.' . $php_ext; + + // phpBB + if (($path != 'phpbb2') && ($path != 'phpbb3')) { - // - populate $default_lang - $default_lang= 'english'; - } - if (!isset($this->loaded_langs[$mx_block->module_root_path])) + $phpbb_user_path = $path . 'language/' . $this->data['user_lang'] . '/' . $filename . '.' . $php_ext; + $phpbb_board_path = $path . 'language/' . $board_config['default_lang'] . '/' . $filename . '.' . $php_ext; + $phpbb_default_path = $path . 'language/en/' . $filename . '.' . $php_ext; + } + + // Shared phpBB2 + if ($path = 'phpbb2') { - if ($lang_mode == MX_LANG_MAIN || $lang_mode == MX_LANG_ALL) - { - if (!empty($this->module_lang_path[$mx_block->module_root_path])) - { - $module_lang_path = $this->module_lang_path[$mx_block->module_root_path]; - } + $phpbb2_shared_path = $this->mx_root_path . 'includes/shared/phpbb2/'; + + $phpbb_user_path = $phpbb2_shared_path . 'language/lang_' . $this->data['user_lang'] . '/' . $filename . '.' . $php_ext; + $phpbb_board_path = $phpbb2_shared_path . 'language/lang_' . $board_config['default_lang'] . '/' . $filename . '.' . $php_ext; + $phpbb_default_path = $phpbb2_shared_path . 'language/lang_english/' . $filename . '.' . $php_ext; + } + + // Shared phpBB3 + if ($path = 'phpbb3') + { + $phpbb3_shared_path = $this->mx_root_path . 'includes/shared/phpbb3/'; + + $phpbb_user_path = $phpbb3_shared_path . 'language/lang_' . $this->data['user_lang'] . '/' . $filename . '.' . $php_ext; + $phpbb_board_path = $phpbb3_shared_path . 'language/lang_' . $board_config['default_lang'] . '/' . $filename . '.' . $php_ext; + $phpbb_default_path = $phpbb3_shared_path . 'language/lang_english/' . $filename . '.' . $php_ext; + } + + if (file_exists($user_path)) + { + include_once($user_path); + } + else if ($require) + { + if (file_exists($board_path)) + { + include_once($board_path); + } + else if (file_exists($default_path)) + { + include_once($default_path); + } + } + else if (is_file($phpbb_user_path)) + { + include_once($phpbb_user_path); + } + if ((@include $phpbb_user_path) === false) + { + if ($require) + { + if ((@include $phpbb_board_path) === false) + { + if ((@include $phpbb_default_path) === false) + { + continue; + } + } + } + } + + if (count($lang) == 0) + { + // If the language entry is an empty array, we just return the language key $this->lang = $this->lang; + // The language file is not exist throw new language_file_not_found( + print_r('Language file ' . $path . '|' . $filename . '.' . $php_ext . '|' . ($require ? $phpbb_user_path : $phpbb_board_path) . ' couldn\'t be opened.'); + } + else + { + // If the language entry is not an empty array, we merge the language keys + $this->lang = array_merge($this->lang, $lang); + } + } + + /** + * Loads common language files + */ + protected function load_common_language_files() + { + if (!$this->common_language_files_loaded) + { + /* + * Load MXP lang keys + * Load vanilla phpBB2 lang files for old modules if is possible + */ + switch (PORTAL_BACKEND) + { + case 'internal': + case 'smf2': + case 'mybb': + + //Load shared phpBB2 language files for old modules + $shared_lang_path = $this->mx_root_path . 'includes/shared/phpbb2/language/'; + + // AdminCP + if (defined('IN_ADMIN')) + { + // Shared phpBB2 AdminCP keys + $this->_load_lang($this->mx_root_path . 'includes/shared/phpbb2/', 'lang_admin'); + // Core MXP AdminCP + $this->_load_lang($this->mx_root_path, 'lang_admin'); + //Load Shared phpBB3 common language file + $this->_load_lang($this->mx_root_path . 'includes/shared/phpbb3/', 'acp/common'); + } + // Shared phpBB keys + $this->_load_lang($this->mx_root_path . 'includes/shared/phpbb2/', 'lang_main'); + // Core Main Translation after shared phpBB keys so we can overwrite some settings + $this->_load_lang($this->mx_root_path, 'lang_main'); + //Load Shared phpBB3 common language file + $this->_load_lang($this->mx_root_path . 'includes/shared/phpbb3/', 'common'); + break; + + case 'phpbb2': + + //Load vanilla phpBB2 language files for old modules if is possible + $shared_lang_path = $this->mx_root_path . 'includes/shared/phpbb2/language/'; + + // AdminCP + if (defined('IN_ADMIN')) + { + // Load vanilla phpBB2 AdminCP keys + $this->_load_lang($this->phpbb_root_path, 'lang_admin'); + // Core MXP AdminCP + $this->_load_lang($this->mx_root_path, 'lang_admin'); + //Load Shared phpBB3 AdminCP common language file + $this->_load_lang($this->mx_root_path . 'includes/shared/phpbb3/', 'acp/common'); + } + // Load vanilla phpBB2 keys + $this->_load_lang($this->phpbb_root_path, 'lang_main'); + // Core Main Translation after shared phpBB keys so we can overwrite some settings + $this->_load_lang($this->mx_root_path, 'lang_main'); + //Load Shared phpBB3 common language file + $this->_load_lang($this->mx_root_path . 'includes/shared/phpbb3/', 'common'); + break; + case 'phpbb3': + case 'olympus': + case 'ascraeus': + case 'rhea': + case 'proteus': + + //Load vanilla phpBB3 common language files for new modules if is possible + $shared_lang_path = $this->mx_root_path . 'includes/shared/phpbb2/language/'; + + // AdminCP + if (defined('IN_ADMIN')) + { + // Shared phpBB2 AdminCP keys + $this->_load_lang($this->mx_root_path . 'includes/shared/phpbb2/', 'lang_admin'); + // Core MXP AdminCP + $this->_load_lang($this->mx_root_path, 'lang_admin'); + //Load vanilla phpBB3 AdminCP common language file + $this->_load_lang($this->phpbb_root_path, 'acp/common'); + } + // Shared phpBB keys + $this->_load_lang($this->mx_root_path . 'includes/shared/phpbb2/', 'lang_main'); + // Core Main Translation after shared phpBB keys so we can overwrite some settings + $this->_load_lang($this->mx_root_path, 'lang_main'); + //Load vanilla phpBB3 common language file + $this->_load_lang($this->phpbb_root_path, 'common'); + break; + } + + // + // backend specific common language defs loaded. + // + $this->common_language_files_loaded = true; + } + } + + /** + * Enter description here... + * + * @access private + * @param unknown_type $lang_mode + */ + function _load_module_lang($lang_mode = MX_LANG_MAIN) + { + global $lang, $board_config, $mx_block, $phpEx, $mx_root_path; + + $default_lang = ($this->lang['default_lang']) ? $this->decode_lang($this->lang['default_lang']) : $board_config['default_lang']; + + if ($mx_block->module_root_path == 'modules/mx_coreblocks/') + { + // - default module already populated in root core language pack + $this->loaded_langs[$mx_block->module_root_path] = '1'; + } + + if (empty($mx_block->module_root_path)) + { + global $module_root_path; + $mx_block->module_root_path = $module_root_path; + } + + if (empty($default_lang)) + { + // - populate $default_lang + $default_lang = 'english'; + } + + if (!isset($this->loaded_langs[$mx_block->module_root_path])) + { + if ($lang_mode == MX_LANG_MAIN || $lang_mode == MX_LANG_ALL) + { + if (!empty($this->module_lang_path[$mx_block->module_root_path])) + { + $module_lang_path = $this->module_lang_path[$mx_block->module_root_path]; + } else { $module_lang_path = $mx_root_path . $mx_block->module_root_path; } + // ------------------------------------------------------------------------- // Read Module Main Language Definition // ------------------------------------------------------------------------- @@ -2011,7 +3194,7 @@ function _load_module_lang($lang_mode = MX_LANG_MAIN) { if ((@include $module_lang_path . "language/lang_english/lang_admin.$phpEx") === false) { - mx_message_die(CRITICAL_ERROR, 'Modiule admin language file ' . $mx_root_path . $module_lang_path . "language/lang_" . $default_lang . "/lang_admin.$phpEx" . ' couldn\'t be opened.'); + mx_message_die(CRITICAL_ERROR, 'Module admin language file ' . $mx_root_path . $module_lang_path . "language/lang_" . $default_lang . "/lang_admin.$phpEx" . ' couldn\'t be opened.'); } } } @@ -2026,14 +3209,14 @@ function _load_module_lang($lang_mode = MX_LANG_MAIN) function _load_module_style() { global $mx_block, $phpEx; - + if (!isset($this->loaded_styles[$mx_block->module_root_path])) { // ------------------------------------------------------------------------- // Read Module Style Definition // ------------------------------------------------------------------------- $this->_load_mxbb_images($mx_block->module_root_path); - + $this->loaded_styles[$mx_block->module_root_path] = '1'; $this->loaded_default_styles[$mx_block->module_root_path] = $this->default_module_style; } @@ -2052,35 +3235,47 @@ function optionget($key, $data = false) return $this->keyvalues[$key]; } - - // ------------------------------ - // Public Methods - // - + /** - * Init user class. - * Populate $userdata, $lang - * - * @access public - * @param unknown_type $user_ip - * @param unknown_type $page_id + * Load available languages list + * author: Jan Kalah aka culprit_cz + * @return array available languages list: KEY = folder name */ - function init($user_ip, $page_id, $init_style = true) + function get_lang_list($ext_root_path = '') { - // Define basic constants - $this->page_id = $page_id; - $this->user_ip = $user_ip; - - // Inititate User data - $this->_init_session($user_ip, $this->page_id); - $this->_init_userprefs(); - - // Inititate User style - if ($init_style) + if (count($this->language_list)) { - $this->_init_style(); + return $this->language_list; + } + /* c:\Wamp\www\Rhea\language\ */ + $dir = opendir($this->mx_root_path . 'language/'); + while($f = readdir($dir)) + { + if (($f == '.' || $f == '..') || !is_dir($this->mx_root_path . 'language/' . $f)) + { + continue; + } + $this->language_list[$f] = $this->ucstrreplace('lang_', '', $f); } + closedir($dir); + if (is_dir($this->phpbb_root_path . 'language/')) + { + $dir = opendir($this->phpbb_root_path . 'language/'); + while($f = readdir($dir)) + { + if (($f == '.' || $f == '..') || !is_dir($this->phpbb_root_path . 'language/' . $f)) + { + continue; + } + $this->phpbb_language_list[$f] = $this->ucstrreplace('lang_', '', $f); + } + closedir($dir); + return $this->language_list = array_merge($this->phpbb_language_list, $this->language_list); + } + return $this->language_list; } + + /** * Init user style. @@ -2121,7 +3316,8 @@ function init_style() case 'phpbb3': case 'olympus': case 'ascraeus': - case 'rhea': + case 'rhea': + case 'proteus': $this->_load_phpbb_images(); break; } @@ -2150,24 +3346,26 @@ function init_style() * @param unknown_type $lang_mode * @param unknown_type $image_mode */ - function extend($lang_mode = MX_LANG_MAIN, $image_mode = MX_IMAGES) + function extend($lang_mode = MX_LANG_MAIN, $image_mode = MX_IMAGES, $module_root_path = '') { - global $mx_block; - - if (defined('IN_ADMIN')) - { - return; - } - + global $mx_root_path, $mx_block; + + + if (defined('IN_ADMIN') && !empty($module_root_path) && (empty($mx_block->module_root_path) || ($mx_block->module_root_path == 'modules/mx_coreblocks/'))) + { + + $mx_block->module_root_path = $module_root_path; + } + if (!empty($this->loaded_default_styles[$mx_block->module_root_path])) { $this->default_module_style = $this->loaded_default_styles[$mx_block->module_root_path]; $this->default_template_name = $this->default_module_style; $this->default_current_template_path = 'templates/' . $this->default_template_name; - } - + } + if ($lang_mode != MX_LANG_NONE) - { + { $this->_load_module_lang($lang_mode); } @@ -2181,9 +3379,21 @@ function extend($lang_mode = MX_LANG_MAIN, $image_mode = MX_IMAGES) // if (!empty($this->default_module_style)) { - $this->default_template_name = '_core'; - $this->default_current_template_path = 'templates/' . $this->default_template_name; - $this->default_module_style = ''; + if(@is_dir($mx_root_path . 'templates/' . '_core' . '/') ) + { + $this->default_template_name = '_core'; + $this->default_current_template_path = 'templates/' . $this->default_template_name; + } + elseif(@is_dir($mx_root_path . 'styles/' . 'all' . '/') ) + { + $this->default_template_name = 'all'; + $this->default_current_template_path = 'styles/' . $this->default_template_name; + } + elseif(@is_dir($mx_root_path . 'templates/' . 'all' . '/') ) + { + $this->default_template_name = 'all'; + $this->default_current_template_path = 'templates/' . $this->default_template_name; + } } } @@ -2191,7 +3401,7 @@ function set_module_default_style($default_module_style = '') { global $mx_block; - $this->loaded_default_styles[$mx_block->module_root_path] = $default_module_style; + $this->loaded_default_styles[$mx_block->module_root_path] = $default_module_style; } function set_module_lang_path($module_lang_path = '') @@ -2200,6 +3410,84 @@ function set_module_lang_path($module_lang_path = '') $this->module_lang_path[$mx_block->module_root_path] = $module_lang_path; } + + /** + * Loads all extension information from the database + * + * @return null + */ + public function load_extensions() + { + $this->extensions = array(); + + // Do not try to load any extensions if the extension table + // does not exist or when installing or updating. + // Note: database updater invokes this code, and in 3.0 + // there is no extension table therefore the rest of this function + // fails + if (defined('IN_INSTALL') || version_compare($this->config['version'], '3.1.0-dev', '<')) + { + return; + } + + $sql = 'SELECT * + FROM ' . $this->extension_table; + + $result = $this->db->sql_query($sql); + $extensions = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + + foreach ($extensions as $extension) + { + $extension['ext_path'] = $this->get_extension_path($extension['ext_name']); + $this->extensions[$extension['ext_name']] = $extension; + } + + ksort($this->extensions); + + if ($this->cache) + { + $this->cache->put($this->cache_name, $this->extensions); + } + } + + /** + * Generates the path to an extension + * + * @param string $name The name of the extension + * @param bool $phpbb_relative Whether the path should be relative to phpbb root + * @return string Path to an extension + */ + public function get_extension_path($name, $phpbb_relative = false) + { + $name = str_replace('.', '', $name); + + return (($phpbb_relative) ? $this->phpbb_root_path : '') . 'ext/' . $name . '/'; + } + + /** + * Instantiates the extension meta class for the extension with the given name + * + * @param string $name The extension name + * @return \phpbb\extension\extension_interface Instance of the extension meta class or + * \phpbb\extension\base if the class does not exist + */ + public function get_extension($name) + { + $extension_class_name = str_replace('/', '\\', $name) . '\\ext'; + + //Not implemented yet + $migrator = new mx_nothing(); + + if (class_exists($extension_class_name)) + { + return new $extension_class_name($this->cache, $this->get_finder(), $migrator, $name, $this->get_extension_path($name, true)); + } + else + { + return new \phpbb\extension\base($this->container, $this->get_finder(), $migrator, $name, $this->get_extension_path($name, true)); + } + } /** * Create buttons. @@ -2224,19 +3512,19 @@ function create_button($key, $label, $url) { case MX_BUTTON_TEXT: return '' . $label . ''; - break; + break; case MX_BUTTON_IMAGE: return ''; - break; + break; case MX_BUTTON_GENERIC: return '' . $label . ''; - break; + break; default: return '
'; - break; + break; } } @@ -2263,21 +3551,2192 @@ function create_icon($key, $label, $url) { case MX_BUTTON_TEXT: return '' . $label . ''; - break; + break; case MX_BUTTON_IMAGE: return '
'; - break; + break; case MX_BUTTON_GENERIC: return '' . $label . ''; - break; + break; default: return '
'; - break; + break; } } +} // class mx_user +/** + * Language file loader + */ +class mx_language_file_loader +{ + /** + * @var string Path to MXP root + */ + protected $mx_root_path; + /** + * @var string Path to phpBB's root + */ + protected $phpbb_root_path; + /** + * @var string Path to Module root + */ + protected $module_root_path; + /** + * @var string Extension of PHP files + */ + protected $php_ext; + + /** + * @var \phpbb\extension\manager Extension manager + */ + protected $extension_manager; + + /** + * Constructor + * + * @param string $phpbb_root_path Path to phpBB's root + * @param string $php_ext Extension of PHP files + */ + public function __construct() + { + global $mx_root_path, $phpbb_root_path, $module_root_path; + + $this->mx_root_path = $mx_root_path; + $this->phpbb_root_path = $phpbb_root_path; + $this->module_root_path = $module_root_path; + $this->php_ext = substr(strrchr(__FILE__, '.'), 1); + + $this->extension_manager = null; + } + + /** + * Extension manager setter + * + * @param \phpbb\extension\manager $extension_manager Extension manager + */ + public function set_extension_manager() + { + $extension_manager = new mx_user(); + $this->extension_manager = $extension_manager; + } + + /** + * Loads language array for the given component + * + * @param string $component Name of the language component + * @param string|array $locale ISO code of the language to load, or array of ISO codes if you want to + * specify additional language fallback steps + * @param array $lang Array reference containing language strings + */ + public function load($component, $locale, &$lang) + { + $locale = (array) $locale; + + // Determine path to language directory + $path = $this->phpbb_root_path . 'language/'; + + $this->load_file($path, $component, $locale, $lang); + } + /** + * Load core language file + * + * @param string $component Name of the component to load + */ + protected function load_core_file($component) + { + // Check if the component is already loaded + if (isset($this->loaded_language_sets['PHPBB'][$component])) + { + return; + } -} // class mx_user + $this->loader->load($component, $this->language_fallback, $this->lang); + $this->loaded_language_sets['PHPBB'][$component] = true; + } + /** + * Loads language array for the given extension component + * + * @param string $extension Name of the extension + * @param string $component Name of the language component + * @param string|array $locale ISO code of the language to load, or array of ISO codes if you want to + * specify additional language fallback steps + * @param array $lang Array reference containing language strings + */ + public function load_extension($extension, $component, $locale = '', &$lang = '') + { + // Check if extension manager was loaded + if ($this->extension_manager === null) + { + // If not, let's return + return; + } + $locale = !empty($locale) ? (array) $locale : $this->language_fallback; + + $lang = !empty($lang) ? $lang : $this->lang; + + // Determine path to language directory + $path = $this->extension_manager->get_extension_path($extension, true) . 'language/'; + + $this->load_file($path, $component, $locale, $lang); + } + + /** + * Prepares language file loading + * + * @param string $path Path to search for file in + * @param string $component Name of the language component + * @param array $locale Array containing language fallback options + * @param array $lang Array reference of language strings + */ + protected function load_file($path, $component, $locale, &$lang) + { + // This is BC stuff and not the best idea as it makes language fallback + // implementation quite hard like below. + if (strpos($this->phpbb_root_path . $component, $path) === 0) + { + // Filter out the path + $path_diff = str_replace($path, '', dirname($this->phpbb_root_path . $component)); + $language_file = basename($component, '.' . $this->php_ext); + $component = ''; + + // This step is needed to resolve language/en/subdir style $component + // $path already points to the language base directory so we need to eliminate + // the first directory from the path (that should be the language directory) + $path_diff_parts = explode('/', $path_diff); + + if (count($path_diff_parts) > 1) + { + array_shift($path_diff_parts); + $component = implode('/', $path_diff_parts) . '/'; + } + + $component .= $language_file; + } + + // Determine filename + $filename = $component . '.' . $this->php_ext; + + // Determine path to file + $file_path = $this->get_language_file_path($path, $filename, $locale); + + // Load language array + $this->load_language_file($file_path, $lang); + } + + /** + * This function implements language fallback logic + * + * @param string $path Path to language directory + * @param string $filename Filename to load language strings from + * + * @return string Relative path to language file + * + * @throws language_file_not_found When the path to the file cannot be resolved + */ + protected function get_language_file_path($path, $filename, $locales) + { + $language_file_path = $filename; + + // Language fallback logic + foreach ($locales as $locale) + { + $language_file_path = $path . $locale . '/' . $filename; + + // If we are in install, try to use the updated version, when available + if (defined('IN_INSTALL')) + { + $install_language_path = str_replace('language/', 'install/update/new/language/', $language_file_path); + if (file_exists($install_language_path)) + { + return $install_language_path; + } + } + + if (file_exists($language_file_path)) + { + return $language_file_path; + } + } + + // The language file is not exist throw new language_file_not_found( + print_r('Language file ' . $language_file_path . ' couldn\'t be opened.'); + } + + /** + * Loads language file + * + * @param string $path Path to language file to load + * @param array $lang Reference of the array of language strings + */ + protected function load_language_file($path, &$lang) + { + // Do not suppress error if in DEBUG mode + if (defined('DEBUG')) + { + include $path; + } + else + { + @include $path; + } + } +} +/** + * + */ +interface IException +{ + /* Protected methods inherited from Exception class */ + public function getMessage(); // Exception message + public function getCode(); // User-defined Exception code + public function getFile(); // Source filename + public function getLine(); // Source line + public function getTrace(); // An array of the backtrace() + public function getTraceAsString(); // Formated string of trace + + /* Overrideable methods inherited from Exception class */ + public function __toString(); // formated string for display + public function __construct($message = null, $code = 0); +} +/** + * Class runtime_exception + * + * Define an exception which support a language var as message. + */ +abstract class runtime_exception extends Exception implements IException +{ + /** + * Parameters to use with the language var. + * + * @var array + */ + protected $message = 'Unknown exception'; // Exception message + private $string; // Unknown + protected $code = 0; // User-defined exception code + protected $file; // Source filename of exception + protected $line; // Source line of exception + private $trace; // Unknown + + /** + * Constructor + * + * @param string $message The Exception message to throw (must be a language variable). + * @param integer $code The Exception code. + */ + public function __construct($message = "", $code = 0) + { + if (!empty($message)) + { + //throw new $this('Unknown '. get_class($this)); + print_r($message); + } + //parent::__construct($message, $code); + } + /** + * {@inheritdoc} + */ + public function __toString() + { + return get_class($this) . " '{$this->message}' in {$this->file}({$this->line})\n" . "{$this->getTraceAsString()}"; + } + /** + */ +} +/** + * + */ +/** + * Wrapper class for loading translations + */ +class mx_language extends mx_language_file_loader +{ + /** + * Global fallback language + * + * ISO code of the language to fallback to when the specified language entries + * cannot be found. + * + * @var string + */ + const FALLBACK_LANGUAGE = 'en'; + + /** + * @var array List of common language files + */ + protected $common_language_files; + + /** + * @var bool + */ + protected $common_language_files_loaded; + + /** + * @var string ISO code of the default board language + */ + protected $default_language; + + /** + * @var string ISO code of the User's language + */ + protected $user_language; + + /** + * @var array Language fallback array (the order is important) + */ + protected $language_fallback; + + /** + * @var array Array of language variables + */ + protected $lang; + + /** + * @var array Loaded language sets + */ + protected $loaded_language_sets; + + /** + * @var \phpbb\language\language_file_loader Language file loader + */ + protected $loader; + + /** + * Constructor + * + * @param \phpbb\language\language_file_loader $loader Language file loader + * @param array|null $common_modules Array of common language modules to load (optional) + */ + public function __construct($common_modules = null) + { + $this->loader = $this; + + global $board_config, $mx_user; + global $mx_root_path, $phpbb_root_path, $module_root_path; + + $this->mx_root_path = $mx_root_path; + $this->phpbb_root_path = $phpbb_root_path; + $this->module_root_path = $module_root_path; + + $this->user = $mx_user; + $this->config = $board_config; + $this->backend = PORTAL_BACKEND; + $this->php_ext = substr(strrchr(__FILE__, '.'), 1); + // Set up default information + $this->user_language = false; + $this->default_language = false; + $this->lang = array(); + $this->loaded_language_sets = array( + 'MXP' => array(), //mxp_core + 'MODS' => array(), //mxp_modules + 'PHPBB' => array(), //phpbb_core + 'phpbb_ext' => array(), //phpbb_ext + ); + // Common language files + if (is_array($common_modules)) + { + $this->common_language_files = $common_modules; + } + else + { + $this->common_language_files = array( + 'common', + ); + } + $this->common_language_files_loaded = false; + $this->language_fallback = array(self::FALLBACK_LANGUAGE); + } + /** + * encode_lang + * + * $default_lang = $language->encode_lang($config['default_lang']); + * + * @param unknown_type $lang + * @return unknown + */ + function encode_lang($lang) + { + if ($this->backend == 'phpbb2') + { + return $lang; + } + else + { + $lang = str_replace('lang_', '', $lang); + } + + switch($lang) + { + case 'afar': + $lang_name = 'aa'; + break; + case 'abkhazian': + $lang_name = 'ab'; + break; + case 'avestan': + $lang_name = 'ae'; + break; + case 'afrikaans': + $lang_name = 'af'; + break; + case 'akan': + $lang_name = 'ak'; + break; + case 'amharic': + $lang_name = 'am'; + break; + case 'aragonese': + $lang_name = 'an'; + break; + case 'arabic': + $lang_name = 'ar'; + break; + case 'assamese': + $lang_name = 'as'; + break; + case 'avaric': + $lang_name = 'av'; + break; + case 'aymara': + $lang_name = 'ay'; + break; + case 'azerbaijani': + $lang_name = 'az'; + break; + case 'bashkir': + $lang_name = 'ba'; + break; + case 'belarusian': + $lang_name = 'be'; + break; + case 'bulgarian': + $lang_name = 'bg'; + break; + case 'bihari': + $lang_name = 'bh'; + break; + case 'bislama': + $lang_name = 'bi'; + break; + case 'bambara': + $lang_name = 'bm'; + break; + case 'bengali': + $lang_name = 'bn'; + break; + case 'tibetan': + $lang_name = 'bo'; + break; + case 'breton': + $lang_name = 'br'; + break; + case 'bosnian': + $lang_name = 'bs'; + break; + case 'catalan': + $lang_name = 'ca'; + break; + case 'chechen': + $lang_name = 'ce'; + break; + case 'chamorro': + $lang_name = 'ch'; + break; + case 'corsican': + $lang_name = 'co'; + break; + case 'cree': + $lang_name = 'cr'; + break; + case 'czech': + $lang_name = 'cs'; + break; + case 'slavonic': + $lang_name = 'cu'; + break; + case 'chuvash': + $lang_name = 'cv'; + break; + case 'welsh_cymraeg': + $lang_name = 'cy'; + break; + case 'danish': + $lang_name = 'da'; + break; + case 'german': + $lang_name = 'de'; + break; + case 'divehi': + $lang_name = 'dv'; + break; + case 'dzongkha': + $lang_name = 'dz'; + break; + case 'ewe': + $lang_name = 'ee'; + break; + case 'greek': + $lang_name = 'el'; + break; + case 'hebrew': + $lang_name = 'he'; + break; + case 'english': + $lang_name = 'en'; + break; + case 'english_us': + $lang_name = 'en_us'; + break; + case 'esperanto': + $lang_name = 'eo'; + break; + case 'spanish': + $lang_name = 'es'; + break; + case 'estonian': + $lang_name = 'et'; + break; + case 'basque': + $lang_name = 'eu'; + break; + case 'persian': + $lang_name = 'fa'; + break; + case 'fulah': + $lang_name = 'ff'; + break; + case 'finnish': + $lang_name = 'fi'; + break; + case 'fijian': + $lang_name = 'fj'; + break; + case 'faroese': + $lang_name = 'fo'; + break; + case 'french': + $lang_name = 'fr'; + break; + case 'frisian': + $lang_name = 'fy'; + break; + case 'irish': + $lang_name = 'ga'; + break; + case 'scottish': + $lang_name = 'gd'; + break; + case 'galician': + $lang_name = 'gl'; + break; + case 'guaraní': + $lang_name = 'gn'; + break; + case 'gujarati': + $lang_name = 'gu'; + break; + case 'manx': + $lang_name = 'gv'; + break; + case 'hausa': + $lang_name = 'ha'; + break; + case 'hebrew': + $lang_name = 'he'; + break; + case 'hindi': + $lang_name = 'hi'; + break; + case 'hiri_motu': + $lang_name = 'ho'; + break; + case 'croatian': + $lang_name = 'hr'; + break; + case 'haitian': + $lang_name = 'ht'; + break; + case 'hungarian': + $lang_name = 'hu'; + break; + case 'armenian': + $lang_name = 'hy'; + break; + case 'herero': + $lang_name = 'hz'; + break; + case 'interlingua': + $lang_name = 'ia'; + break; + case 'indonesian': + $lang_name = 'id'; + break; + case 'interlingue': + $lang_name = 'ie'; + break; + case 'igbo': + $lang_name = 'ig'; + break; + case 'sichuan_yi': + $lang_name = 'ii'; + break; + case 'inupiaq': + $lang_name = 'ik'; + break; + case 'ido': + $lang_name = 'io'; + break; + case 'icelandic': + $lang_name = 'is'; + break; + case 'italian': + $lang_name = 'it'; + break; + case 'inuktitut': + $lang_name = 'iu'; + break; + case 'japanese': + $lang_name = 'ja'; + break; + case 'javanese': + $lang_name = 'jv'; + break; + case 'georgian': + $lang_name = 'ka'; + break; + case 'kongo': + $lang_name = 'kg'; + break; + case 'kikuyu': + $lang_name = 'ki'; + break; + case 'kwanyama': + $lang_name = 'kj'; + break; + case 'kazakh': + $lang_name = 'kk'; + break; + case 'kalaallisut': + $lang_name = 'kl'; + break; + case 'khmer': + $lang_name = 'km'; + break; + case 'kannada': + $lang_name = 'kn'; + break; + case 'korean': + $lang_name = 'ko'; + break; + case 'kanuri': + $lang_name = 'kr'; + break; + case 'kashmiri': + $lang_name = 'ks'; + break; + case 'kurdish': + $lang_name = 'ku'; + break; + case 'kv': + $lang_name = 'komi'; + break; + case 'cornish_kernewek': + $lang_name = 'kw'; + break; + case 'kirghiz': + $lang_name = 'ky'; + break; + case 'latin': + $lang_name = 'la'; + break; + case 'luxembourgish': + $lang_name = 'lb'; + break; + case 'ganda': + $lang_name = 'lg'; + break; + case 'limburgish': + $lang_name = 'li'; + break; + case 'lingala': + $lang_name = 'ln'; + break; + case 'lao': + $lang_name = 'lo'; + break; + case 'lithuanian': + $lang_name = 'lt'; + break; + case 'luba-katanga': + $lang_name = 'lu'; + break; + case 'latvian': + $lang_name = 'lv'; + break; + case 'malagasy': + $lang_name = 'mg'; + break; + case 'marshallese': + $lang_name = 'mh'; + break; + case 'maori': + $lang_name = 'mi'; + break; + case 'macedonian': + $lang_name = 'mk'; + break; + case 'malayalam': + $lang_name = 'ml'; + break; + case 'mongolian': + $lang_name = 'mn'; + break; + case 'moldavian': + $lang_name = 'mo'; + break; + case 'marathi': + $lang_name = 'mr'; + break; + case 'malay': + $lang_name = 'ms'; + break; + case 'maltese': + $lang_name = 'mt'; + break; + case 'burmese': + $lang_name = 'my'; + break; + case 'nauruan': + $lang_name = 'na'; + break; + case 'norwegian': + $lang_name = 'nb'; + break; + case 'ndebele': + $lang_name = 'nd'; + break; + case 'nepali': + $lang_name = 'ne'; + break; + case 'ndonga': + $lang_name = 'ng'; + break; + case 'dutch': + $lang_name = 'nl'; + break; + case 'norwegian_nynorsk': + $lang_name = 'nn'; + break; + case 'norwegian': + $lang_name = 'no'; + break; + case 'southern_ndebele': + $lang_name = 'nr'; + break; + case 'navajo': + $lang_name = 'nv'; + break; + case 'chichewa': + $lang_name = 'ny'; + break; + case 'occitan': + $lang_name = 'oc'; + break; + case 'ojibwa': + $lang_name = 'oj'; + break; + case 'oromo': + $lang_name = 'om'; + break; + case 'oriya': + $lang_name = 'or'; + break; + case 'ossetian': + $lang_name = 'os'; + break; + case 'panjabi': + $lang_name = 'pa'; + break; + case 'pali': + $lang_name = 'pi'; + break; + case 'polish': + $lang_name = 'pl'; + break; + case 'pashto': + $lang_name = 'ps'; + break; + case 'portuguese': + $lang_name = 'pt'; + break; + case 'portuguese_brasil': + $lang_name = 'pt_br'; + break; + case 'quechua': + $lang_name = 'qu'; + break; + case 'romansh': + $lang_name = 'rm'; + break; + case 'kirundi': + $lang_name = 'rn'; + break; + case 'romanian': + $lang_name = 'ro'; + break; + case 'russian': + $lang_name = 'ru'; + break; + case 'kinyarwanda': + $lang_name = 'rw'; + break; + case 'sanskrit': + $lang_name = 'sa'; + break; + case 'sardinian': + $lang_name = 'sc'; + break; + case 'sindhi': + $lang_name = 'sd'; + break; + case 'northern_sami': + $lang_name = 'se'; + break; + case 'sango': + $lang_name = 'sg'; + break; + case 'serbo-croatian': + $lang_name = 'sh'; + break; + case 'sinhala': + $lang_name = 'si'; + break; + case 'slovak': + $lang_name = 'sk'; + break; + case 'slovenian': + $lang_name = 'sl'; + break; + case 'samoan': + $lang_name = 'sm'; + break; + case 'shona': + $lang_name = 'sn'; + break; + case 'somali': + $lang_name = 'so'; + break; + case 'albanian': + $lang_name = 'sq'; + break; + case 'serbian': + $lang_name = 'sr'; + break; + case 'swati': + $lang_name = 'ss'; + break; + case 'sotho': + $lang_name = 'st'; + break; + case 'sundanese': + $lang_name = 'su'; + break; + case 'swedish': + $lang_name = 'sv'; + break; + case 'swahili': + $lang_name = 'sw'; + break; + case 'tamil': + $lang_name = 'ta'; + break; + case 'telugu': + $lang_name = 'te'; + break; + case 'tajik': + $lang_name = 'tg'; + break; + case 'thai': + $lang_name = 'th'; + break; + case 'tigrinya': + $lang_name = 'ti'; + break; + case 'turkmen': + $lang_name = 'tk'; + break; + case 'tagalog': + $lang_name = 'tl'; + break; + case 'tswana': + $lang_name = 'tn'; + break; + case 'tonga': + $lang_name = 'to'; + break; + case 'turkish': + $lang_name = 'tr'; + break; + case 'tsonga': + $lang_name = 'ts'; + break; + case 'tatar': + $lang_name = 'tt'; + break; + case 'twi': + $lang_name = 'tw'; + break; + case 'tahitian': + $lang_name = 'ty'; + break; + case 'uighur': + $lang_name = 'ug'; + break; + case 'ukrainian': + $lang_name = 'uk'; + break; + case 'urdu': + $lang_name = 'ur'; + break; + case 'uzbek': + $lang_name = 'uz'; + break; + case 'venda': + $lang_name = 've'; + break; + case 'vietnamese': + $lang_name = 'vi'; + break; + case 'volapuk': + $lang_name = 'vo'; + break; + case 'walloon': + $lang_name = 'wa'; + break; + case 'wolof': + $lang_name = 'wo'; + break; + case 'xhosa': + $lang_name = 'xh'; + break; + case 'yiddish': + $lang_name = 'yi'; + break; + case 'yoruba': + $lang_name = 'yo'; + break; + case 'zhuang': + $lang_name = 'za'; + break; + case 'chinese': + $lang_name = 'zh'; + break; + case 'chinese_simplified': + $lang_name = 'zh_cmn_hans'; + break; + case 'chinese_traditional': + $lang_name = 'zh_cmn_hant'; + break; + case 'zulu': + $lang_name = 'zu'; + break; + default: + $lang_name = (strlen($lang) > 2) ? substr($lang, 0, 2) : $lang; + break; + } + return $lang_name; + } + + function ucstrreplace($pattern = '%{$regex}%i', $matches = '', $string) + { + /* return with no uppercase if patern not in string */ + if (strpos($string, $pattern) === false) + { + /* known languages */ + switch($string) + { + case 'aa': + $lang_name = 'afar'; + break; + case 'ab': + $lang_name = 'abkhazian'; + break; + case 'ae': + $lang_name = 'avestan'; + break; + case 'af': + $lang_name = 'afrikaans'; + break; + case 'ak': + $lang_name = 'akan'; + break; + case 'am': + $lang_name = 'amharic'; + break; + case 'an': + $lang_name = 'aragonese'; + break; + case 'ar': + $lang_name = 'arabic'; + break; + case 'as': + $lang_name = 'assamese'; + break; + case 'av': + $lang_name = 'avaric'; + break; + case 'ay': + $lang_name = 'aymara'; + break; + case 'az': + $lang_name = 'azerbaijani'; + break; + case 'ba': + $lang_name = 'bashkir'; + break; + case 'be': + $lang_name = 'belarusian'; + break; + case 'bg': + $lang_name = 'bulgarian'; + break; + case 'bh': + $lang_name = 'bihari'; + break; + case 'bi': + $lang_name = 'bislama'; + break; + case 'bm': + $lang_name = 'bambara'; + break; + case 'bn': + $lang_name = 'bengali'; + break; + case 'bo': + $lang_name = 'tibetan'; + break; + case 'br': + $lang_name = 'breton'; + break; + case 'bs': + $lang_name = 'bosnian'; + break; + case 'ca': + $lang_name = 'catalan'; + break; + case 'ce': + $lang_name = 'chechen'; + break; + case 'ch': + $lang_name = 'chamorro'; + break; + case 'co': + $lang_name = 'corsican'; + break; + case 'cr': + $lang_name = 'cree'; + break; + case 'cs': + $lang_name = 'czech'; + break; + case 'cu': + $lang_name = 'slavonic'; + break; + case 'cv': + $lang_name = 'chuvash'; + break; + case 'cy': + $lang_name = 'welsh_cymraeg'; + break; + case 'da': + $lang_name = 'danish'; + break; + case 'de': + $lang_name = 'german'; + break; + case 'dv': + $lang_name = 'divehi'; + break; + case 'dz': + $lang_name = 'dzongkha'; + break; + case 'ee': + $lang_name = 'ewe'; + break; + case 'el': + $lang_name = 'greek'; + break; + case 'he': + $lang_name = 'hebrew'; + break; + case 'en': + $lang_name = 'english'; + break; + case 'en_us': + $lang_name = 'english'; + break; + case 'eo': + $lang_name = 'esperanto'; + break; + case 'es': + $lang_name = 'spanish'; + break; + case 'et': + $lang_name = 'estonian'; + break; + case 'eu': + $lang_name = 'basque'; + break; + case 'fa': + $lang_name = 'persian'; + break; + case 'ff': + $lang_name = 'fulah'; + break; + case 'fi': + $lang_name = 'finnish'; + break; + case 'fj': + $lang_name = 'fijian'; + break; + case 'fo': + $lang_name = 'faroese'; + break; + case 'fr': + $lang_name = 'french'; + break; + case 'fy': + $lang_name = 'frisian'; + break; + case 'ga': + $lang_name = 'irish'; + break; + case 'gd': + $lang_name = 'scottish'; + break; + case 'gl': + $lang_name = 'galician'; + break; + case 'gn': + $lang_name = 'guaraní'; + break; + case 'gu': + $lang_name = 'gujarati'; + break; + case 'gv': + $lang_name = 'manx'; + break; + case 'ha': + $lang_name = 'hausa'; + break; + case 'he': + $lang_name = 'hebrew'; + break; + case 'hi': + $lang_name = 'hindi'; + break; + case 'ho': + $lang_name = 'hiri_motu'; + break; + case 'hr': + $lang_name = 'croatian'; + break; + case 'ht': + $lang_name = 'haitian'; + break; + case 'hu': + $lang_name = 'hungarian'; + break; + case 'hy': + $lang_name = 'armenian'; + break; + case 'hz': + $lang_name = 'herero'; + break; + case 'ia': + $lang_name = 'interlingua'; + break; + case 'id': + $lang_name = 'indonesian'; + break; + case 'ie': + $lang_name = 'interlingue'; + break; + case 'ig': + $lang_name = 'igbo'; + break; + case 'ii': + $lang_name = 'sichuan_yi'; + break; + case 'ik': + $lang_name = 'inupiaq'; + break; + case 'io': + $lang_name = 'ido'; + break; + case 'is': + $lang_name = 'icelandic'; + break; + case 'it': + $lang_name = 'italian'; + break; + case 'iu': + $lang_name = 'inuktitut'; + break; + case 'ja': + $lang_name = 'japanese'; + break; + case 'jv': + $lang_name = 'javanese'; + break; + case 'ka': + $lang_name = 'georgian'; + break; + case 'kg': + $lang_name = 'kongo'; + break; + case 'ki': + $lang_name = 'kikuyu'; + break; + case 'kj': + $lang_name = 'kwanyama'; + break; + case 'kk': + $lang_name = 'kazakh'; + break; + case 'kl': + $lang_name = 'kalaallisut'; + break; + case 'km': + $lang_name = 'khmer'; + break; + case 'kn': + $lang_name = 'kannada'; + break; + case 'ko': + $lang_name = 'korean'; + break; + case 'kr': + $lang_name = 'kanuri'; + break; + case 'ks': + $lang_name = 'kashmiri'; + break; + case 'ku': + $lang_name = 'kurdish'; + break; + case 'kv': + $lang_name = 'komi'; + break; + case 'kw': + $lang_name = 'cornish_kernewek'; + break; + case 'ky': + $lang_name = 'kirghiz'; + break; + case 'la': + $lang_name = 'latin'; + break; + case 'lb': + $lang_name = 'luxembourgish'; + break; + case 'lg': + $lang_name = 'ganda'; + break; + case 'li': + $lang_name = 'limburgish'; + break; + case 'ln': + $lang_name = 'lingala'; + break; + case 'lo': + $lang_name = 'lao'; + break; + case 'lt': + $lang_name = 'lithuanian'; + break; + case 'lu': + $lang_name = 'luba-katanga'; + break; + case 'lv': + $lang_name = 'latvian'; + break; + case 'mg': + $lang_name = 'malagasy'; + break; + case 'mh': + $lang_name = 'marshallese'; + break; + case 'mi': + $lang_name = 'maori'; + break; + case 'mk': + $lang_name = 'macedonian'; + break; + case 'ml': + $lang_name = 'malayalam'; + break; + case 'mn': + $lang_name = 'mongolian'; + break; + case 'mo': + $lang_name = 'moldavian'; + break; + case 'mr': + $lang_name = 'marathi'; + break; + case 'ms': + $lang_name = 'malay'; + break; + case 'mt': + $lang_name = 'maltese'; + break; + case 'my': + $lang_name = 'burmese'; + break; + case 'na': + $lang_name = 'nauruan'; + break; + case 'nb': + $lang_name = 'norwegian'; + break; + case 'nd': + $lang_name = 'ndebele'; + break; + case 'ne': + $lang_name = 'nepali'; + break; + case 'ng': + $lang_name = 'ndonga'; + break; + case 'nl': + $lang_name = 'dutch'; + break; + case 'nn': + $lang_name = 'norwegian_nynorsk'; + break; + case 'no': + $lang_name = 'norwegian'; + break; + case 'nr': + $lang_name = 'southern_ndebele'; + break; + case 'nv': + $lang_name = 'navajo'; + break; + case 'ny': + $lang_name = 'chichewa'; + break; + case 'oc': + $lang_name = 'occitan'; + break; + case 'oj': + $lang_name = 'ojibwa'; + break; + case 'om': + $lang_name = 'oromo'; + break; + case 'or': + $lang_name = 'oriya'; + break; + case 'os': + $lang_name = 'ossetian'; + break; + case 'pa': + $lang_name = 'panjabi'; + break; + case 'pi': + $lang_name = 'pali'; + break; + case 'pl': + $lang_name = 'polish'; + break; + case 'ps': + $lang_name = 'pashto'; + break; + case 'pt': + $lang_name = 'portuguese'; + break; + case 'pt_br': + $lang_name = 'portuguese_brasil'; + break; + case 'qu': + $lang_name = 'quechua'; + break; + case 'rm': + $lang_name = 'romansh'; + break; + case 'rn': + $lang_name = 'kirundi'; + break; + case 'ro': + $lang_name = 'romanian'; + break; + case 'ru': + $lang_name = 'russian'; + break; + case 'rw': + $lang_name = 'kinyarwanda'; + break; + case 'sa': + $lang_name = 'sanskrit'; + break; + case 'sc': + $lang_name = 'sardinian'; + break; + case 'sd': + $lang_name = 'sindhi'; + break; + case 'se': + $lang_name = 'northern_sami'; + break; + case 'sg': + $lang_name = 'sango'; + break; + case 'sh': + $lang_name = 'serbo-croatian'; + break; + case 'si': + $lang_name = 'sinhala'; + break; + case 'sk': + $lang_name = 'slovak'; + break; + case 'sl': + $lang_name = 'slovenian'; + break; + case 'sm': + $lang_name = 'samoan'; + break; + case 'sn': + $lang_name = 'shona'; + break; + case 'so': + $lang_name = 'somali'; + break; + case 'sq': + $lang_name = 'albanian'; + break; + case 'sr': + $lang_name = 'serbian'; + break; + case 'ss': + $lang_name = 'swati'; + break; + case 'st': + $lang_name = 'sotho'; + break; + case 'su': + $lang_name = 'sundanese'; + break; + case 'sv': + $lang_name = 'swedish'; + break; + case 'sw': + $lang_name = 'swahili'; + break; + case 'ta': + $lang_name = 'tamil'; + break; + case 'te': + $lang_name = 'telugu'; + break; + case 'tg': + $lang_name = 'tajik'; + break; + case 'th': + $lang_name = 'thai'; + break; + case 'ti': + $lang_name = 'tigrinya'; + break; + case 'tk': + $lang_name = 'turkmen'; + break; + case 'tl': + $lang_name = 'tagalog'; + break; + case 'tn': + $lang_name = 'tswana'; + break; + case 'to': + $lang_name = 'tonga'; + break; + case 'tr': + $lang_name = 'turkish'; + break; + case 'ts': + $lang_name = 'tsonga'; + break; + case 'tt': + $lang_name = 'tatar'; + break; + case 'tw': + $lang_name = 'twi'; + break; + case 'ty': + $lang_name = 'tahitian'; + break; + case 'ug': + $lang_name = 'uighur'; + break; + case 'uk': + $lang_name = 'ukrainian'; + break; + case 'ur': + $lang_name = 'urdu'; + break; + case 'uz': + $lang_name = 'uzbek'; + break; + case 've': + $lang_name = 'venda'; + break; + case 'vi': + $lang_name = 'vietnamese'; + break; + case 'vo': + $lang_name = 'volapuk'; + break; + case 'wa': + $lang_name = 'walloon'; + break; + case 'wo': + $lang_name = 'wolof'; + break; + case 'xh': + $lang_name = 'xhosa'; + break; + case 'yi': + $lang_name = 'yiddish'; + break; + case 'yo': + $lang_name = 'yoruba'; + break; + case 'za': + $lang_name = 'zhuang'; + break; + case 'zh': + $lang_name = 'chinese'; + break; + case 'zh_cmn_hans': + $lang_name = 'chinese_simplified'; + break; + case 'zh_cmn_hant': + $lang_name = 'chinese_traditional'; + break; + case 'zu': + $lang_name = 'zulu'; + break; + default: + $lang_name = (strlen($string) > 2) ? ucfirst(str_replace($pattern, '', $string)) : $string; + break; + } + return ucwords(str_replace(array(" ","-","_"), ' ', $lang_name)); + } + return ucwords(str_replace(array(" ","-","_"), ' ', str_replace($pattern, '', $string))); + } + + /* replacement for eregi($pattern, $string); outputs 0 or 1*/ + function trisstr($pattern = '%{$regex}%i', $string, $matches = '') + { + return preg_match('/' . $pattern . '/i', $string, $matches); + } + + /** + * Enter description here... + * + * @access private + * @param unknown_type $lang_mode + */ + function _load_lang($path, $filename, $require = true, $user_lang = '') + { + $board_config = $this->config; + $php_ext = $this->php_ext; + + // Now only the root for mxp blocks + $board_path = $path . 'language/lang_' . $board_config['default_lang'] . '/' . $filename . '.' . $php_ext; + $default_path = $path . 'language/lang_english/' . $filename . '.' . $php_ext; + $user_path = !empty($user_lang) ? $path . 'language/lang_' . $user_lang . '/' . $filename . '.' . $php_ext : $board_path; + + $phpbb_board_path = $path . 'language/' . $board_config['default_lang'] . '/' . $filename . '.' . $php_ext; + $phpbb_default_path = $path . 'language/en/' . $filename . '.' . $php_ext; + $phpbb_user_path = !empty($user_lang) ? $path . 'language/' . $user_lang . '/' . $filename . '.' . $php_ext : $board_path; + + $lang = array(); + if (file_exists($user_path)) + { + include_once($user_path); + } + else if ($require) + { + if (file_exists($board_path)) + { + include_once($board_path); + } + else if (file_exists($default_path)) + { + include_once($default_path); + } + } + else if (file_exists($phpbb_user_path)) + { + include_once($phpbb_user_path); + } + else if ($require) + { + if (file_exists($phpbb_board_path)) + { + include_once($phpbb_board_path); + } + else if (file_exists($phpbb_default_path)) + { + include_once($phpbb_default_path); + } + } + $this->lang = array_merge($this->lang, $lang); + } + + /** + * Loads common language files + */ + protected function load_common_language_files() + { + if (!$this->common_language_files_loaded) + { + /* + * Load MXP lang keys + * Load vanilla phpBB2 lang files for old modules if is possible + */ + switch (PORTAL_BACKEND) + { + case 'internal': + case 'smf2': + case 'mybb': + + //Load shared phpBB2 language files for old modules + $shared_lang_path = $this->mx_root_path . 'includes/shared/phpbb2/language/'; + + // AdminCP + if (defined('IN_ADMIN')) + { + // Shared phpBB2 AdminCP keys + $this->_load_lang($this->mx_root_path . 'includes/shared/phpbb2/', 'lang_admin'); + // Core MXP AdminCP + $this->_load_lang($this->mx_root_path, 'lang_admin'); + //Load Shared phpBB3 common language file + $this->_load_lang($this->mx_root_path . 'includes/shared/phpbb3/', 'acp/common'); + } + // Shared phpBB keys + $this->_load_lang($this->mx_root_path . 'includes/shared/phpbb2/', 'lang_main'); + // Core Main Translation after shared phpBB keys so we can overwrite some settings + $this->_load_lang($this->mx_root_path, 'lang_main'); + //Load Shared phpBB3 common language file + $this->_load_lang($this->mx_root_path . 'includes/shared/phpbb3/', 'common'); + break; + + case 'phpbb2': + + //Load vanilla phpBB2 language files for old modules if is possible + $shared_lang_path = $this->mx_root_path . 'includes/shared/phpbb2/language/'; + + // AdminCP + if (defined('IN_ADMIN')) + { + // Load vanilla phpBB2 AdminCP keys + $this->_load_lang($this->phpbb_root_path, 'lang_admin'); + // Core MXP AdminCP + $this->_load_lang($this->mx_root_path, 'lang_admin'); + //Load Shared phpBB3 AdminCP common language file + $this->_load_lang($this->mx_root_path . 'includes/shared/phpbb3/', 'acp/common'); + } + // Load vanilla phpBB2 keys + $this->_load_lang($this->phpbb_root_path, 'lang_main'); + // Core Main Translation after shared phpBB keys so we can overwrite some settings + $this->_load_lang($this->mx_root_path, 'lang_main'); + //Load Shared phpBB3 common language file + $this->_load_lang($this->mx_root_path . 'includes/shared/phpbb3/', 'common'); + break; + case 'phpbb3': + case 'olympus': + case 'ascraeus': + case 'rhea': + case 'proteus': + + //Load vanilla phpBB3 common language files for new modules if is possible + $shared_lang_path = $this->mx_root_path . 'includes/shared/phpbb2/language/'; + + // AdminCP + if (defined('IN_ADMIN')) + { + // Shared phpBB2 AdminCP keys + $this->_load_lang($this->mx_root_path . 'includes/shared/phpbb2/', 'lang_admin'); + // Core MXP AdminCP + $this->_load_lang($this->mx_root_path, 'lang_admin'); + //Load vanilla phpBB3 AdminCP common language file + $this->_load_lang($this->phpbb_root_path, 'acp/common'); + } + // Shared phpBB keys + $this->_load_lang($this->mx_root_path . 'includes/shared/phpbb2/', 'lang_main'); + // Core Main Translation after shared phpBB keys so we can overwrite some settings + $this->_load_lang($this->mx_root_path, 'lang_main'); + //Load vanilla phpBB3 common language file + $this->_load_lang($this->phpbb_root_path, 'common'); + break; + } + + // + // Load backend specific lang defs. + // + //$this->user->setup(); + $this->common_language_files_loaded = true; + } + } + + /** + * Returns the raw value associated to a language key or the language key no translation is available. + * No parameter substitution is performed, can be a string or an array. + * + * @param string|array $key Language key + * + * @return array|string + */ + public function lang_raw($key) + { + // Load common language files if they not loaded yet + if (!$this->common_language_files_loaded) + { + $this->load_common_language_files(); + } + + if (is_array($key)) + { + $lang = &$this->lang[array_shift($key)]; + foreach ($key as $_key) + { + $lang = &$lang[$_key]; + } + } + else + { + $lang = &$this->lang[$key]; + } + + // Return if language string does not exist + if (!isset($lang) || (!is_string($lang) && !is_array($lang))) + { + return $key; + } + return $lang; + } + + /** + * Act like lang() but takes a key and an array of parameters instead of using variadic + * + * @param string|array $key Language key + * @param array $args Parameters + * + * @return string + */ + public function lang_array($key, $args = array()) + { + $lang = $this->lang_raw($key); + + if ($lang === $key) + { + return $key; + } + + // If the language entry is a string, we simply mimic sprintf() behaviour + if (is_string($lang)) + { + if (count($args) === 0) + { + return $lang; + } + // Replace key with language entry and simply pass along... + return vsprintf($lang, $args); + } + else if (count($lang) == 0) + { + // If the language entry is an empty array, we just return the language key + return $key; + } + + // It is an array... now handle different nullar/singular/plural forms + $key_found = false; + + // We now get the first number passed and will select the key based upon this number + for ($i = 0, $num_args = count($args); $i < $num_args; $i++) + { + if (is_int($args[$i]) || is_float($args[$i])) + { + if ($args[$i] == 0 && isset($lang[0])) + { + // We allow each translation using plural forms to specify a version for the case of 0 things, + // so that "0 users" may be displayed as "No users". + $key_found = 0; + break; + } + else + { + $use_plural_form = $this->get_plural_form($args[$i]); + if (isset($lang[$use_plural_form])) + { + // The key we should use exists, so we use it. + $key_found = $use_plural_form; + } + else + { + // If the key we need to use does not exist, we fall back to the previous one. + $numbers = array_keys($lang); + + foreach ($numbers as $num) + { + if ($num > $use_plural_form) + { + break; + } + $key_found = $num; + } + } + break; + } + } + } + + // Ok, let's check if the key was found, else use the last entry (because it is mostly the plural form) + if ($key_found === false) + { + $numbers = array_keys($lang); + $key_found = end($numbers); + } + // Use the language string we determined and pass it to sprintf() + return vsprintf($lang[$key_found], $args); + } + /** + * Determine which plural form we should use. + * + * For some languages this is not as simple as for English. + * + * @param int|float $number The number we want to get the plural case for. Float numbers are floored. + * @param int|bool $force_rule False to use the plural rule of the language package + * or an integer to force a certain plural rule + * + * @return int The plural-case we need to use for the number plural-rule combination + * + * @throws \phpbb\language\exception\invalid_plural_rule_exception When $force_rule has an invalid value + */ + public function get_plural_form($number, $force_rule = false) + { + $number = (int) $number; + $plural_rule = ($force_rule !== false) ? $force_rule : ((isset($this->lang['PLURAL_RULE'])) ? $this->lang['PLURAL_RULE'] : 1); + + if ($plural_rule > 15 || $plural_rule < 0) + { + throw new invalid_plural_rule_exception('INVALID_PLURAL_RULE', array( + 'plural_rule' => $plural_rule, + )); + } + + /** + * The following plural rules are based on a list published by the Mozilla Developer Network + * https://developer.mozilla.org/en/Localization_and_Plurals + */ + switch ($plural_rule) + { + case 0: + /** + * Families: Asian (Chinese, Japanese, Korean, Vietnamese), Persian, Turkic/Altaic (Turkish), Thai, Lao + * 1 - everything: 0, 1, 2, ... + */ + return 1; + case 1: + /** + * Families: Germanic (Danish, Dutch, English, Faroese, Frisian, German, Norwegian, Swedish), Finno-Ugric (Estonian, Finnish, Hungarian), Language isolate (Basque), Latin/Greek (Greek), Semitic (Hebrew), Romanic (Italian, Portuguese, Spanish, Catalan) + * 1 - 1 + * 2 - everything else: 0, 2, 3, ... + */ + return ($number === 1) ? 1 : 2; + case 2: + /** + * Families: Romanic (French, Brazilian Portuguese) + * 1 - 0, 1 + * 2 - everything else: 2, 3, ... + */ + return (($number === 0) || ($number === 1)) ? 1 : 2; + case 3: + /** + * Families: Baltic (Latvian) + * 1 - 0 + * 2 - ends in 1, not 11: 1, 21, ... 101, 121, ... + * 3 - everything else: 2, 3, ... 10, 11, 12, ... 20, 22, ... + */ + return ($number === 0) ? 1 : ((($number % 10 === 1) && ($number % 100 != 11)) ? 2 : 3); + case 4: + /** + * Families: Celtic (Scottish Gaelic) + * 1 - is 1 or 11: 1, 11 + * 2 - is 2 or 12: 2, 12 + * 3 - others between 3 and 19: 3, 4, ... 10, 13, ... 18, 19 + * 4 - everything else: 0, 20, 21, ... + */ + return ($number === 1 || $number === 11) ? 1 : (($number === 2 || $number === 12) ? 2 : (($number >= 3 && $number <= 19) ? 3 : 4)); + case 5: + /** + * Families: Romanic (Romanian) + * 1 - 1 + * 2 - is 0 or ends in 01-19: 0, 2, 3, ... 19, 101, 102, ... 119, 201, ... + * 3 - everything else: 20, 21, ... + */ + return ($number === 1) ? 1 : ((($number === 0) || (($number % 100 > 0) && ($number % 100 < 20))) ? 2 : 3); + case 6: + /** + * Families: Baltic (Lithuanian) + * 1 - ends in 1, not 11: 1, 21, 31, ... 101, 121, ... + * 2 - ends in 0 or ends in 10-20: 0, 10, 11, 12, ... 19, 20, 30, 40, ... + * 3 - everything else: 2, 3, ... 8, 9, 22, 23, ... 29, 32, 33, ... + */ + return (($number % 10 === 1) && ($number % 100 != 11)) ? 1 : ((($number % 10 < 2) || (($number % 100 >= 10) && ($number % 100 < 20))) ? 2 : 3); + case 7: + /** + * Families: Slavic (Croatian, Serbian, Russian, Ukrainian) + * 1 - ends in 1, not 11: 1, 21, 31, ... 101, 121, ... + * 2 - ends in 2-4, not 12-14: 2, 3, 4, 22, 23, 24, 32, ... + * 3 - everything else: 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 26, ... + */ + return (($number % 10 === 1) && ($number % 100 != 11)) ? 1 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 2 : 3); + case 8: + /** + * Families: Slavic (Slovak, Czech) + * 1 - 1 + * 2 - 2, 3, 4 + * 3 - everything else: 0, 5, 6, 7, ... + */ + return ($number === 1) ? 1 : ((($number >= 2) && ($number <= 4)) ? 2 : 3); + case 9: + /** + * Families: Slavic (Polish) + * 1 - 1 + * 2 - ends in 2-4, not 12-14: 2, 3, 4, 22, 23, 24, 32, ... 104, 122, ... + * 3 - everything else: 0, 5, 6, ... 11, 12, 13, 14, 15, ... 20, 21, 25, ... + */ + return ($number === 1) ? 1 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 12) || ($number % 100 > 14))) ? 2 : 3); + case 10: + /** + * Families: Slavic (Slovenian, Sorbian) + * 1 - ends in 01: 1, 101, 201, ... + * 2 - ends in 02: 2, 102, 202, ... + * 3 - ends in 03-04: 3, 4, 103, 104, 203, 204, ... + * 4 - everything else: 0, 5, 6, 7, 8, 9, 10, 11, ... + */ + return ($number % 100 === 1) ? 1 : (($number % 100 === 2) ? 2 : ((($number % 100 === 3) || ($number % 100 === 4)) ? 3 : 4)); + case 11: + /** + * Families: Celtic (Irish Gaeilge) + * 1 - 1 + * 2 - 2 + * 3 - is 3-6: 3, 4, 5, 6 + * 4 - is 7-10: 7, 8, 9, 10 + * 5 - everything else: 0, 11, 12, ... + */ + return ($number === 1) ? 1 : (($number === 2) ? 2 : (($number >= 3 && $number <= 6) ? 3 : (($number >= 7 && $number <= 10) ? 4 : 5))); + case 12: + /** + * Families: Semitic (Arabic) + * 1 - 1 + * 2 - 2 + * 3 - ends in 03-10: 3, 4, ... 10, 103, 104, ... 110, 203, 204, ... + * 4 - ends in 11-99: 11, ... 99, 111, 112, ... + * 5 - everything else: 100, 101, 102, 200, 201, 202, ... + * 6 - 0 + */ + return ($number === 1) ? 1 : (($number === 2) ? 2 : ((($number % 100 >= 3) && ($number % 100 <= 10)) ? 3 : ((($number % 100 >= 11) && ($number % 100 <= 99)) ? 4 : (($number != 0) ? 5 : 6)))); + case 13: + /** + * Families: Semitic (Maltese) + * 1 - 1 + * 2 - is 0 or ends in 01-10: 0, 2, 3, ... 9, 10, 101, 102, ... + * 3 - ends in 11-19: 11, 12, ... 18, 19, 111, 112, ... + * 4 - everything else: 20, 21, ... + */ + return ($number === 1) ? 1 : ((($number === 0) || (($number % 100 > 1) && ($number % 100 < 11))) ? 2 : ((($number % 100 > 10) && ($number % 100 < 20)) ? 3 : 4)); + case 14: + /** + * Families: Slavic (Macedonian) + * 1 - ends in 1: 1, 11, 21, ... + * 2 - ends in 2: 2, 12, 22, ... + * 3 - everything else: 0, 3, 4, ... 10, 13, 14, ... 20, 23, ... + */ + return ($number % 10 === 1) ? 1 : (($number % 10 === 2) ? 2 : 3); + case 15: + /** + * Families: Icelandic + * 1 - ends in 1, not 11: 1, 21, 31, ... 101, 121, 131, ... + * 2 - everything else: 0, 2, 3, ... 10, 11, 12, ... 20, 22, ... + */ + return (($number % 10 === 1) && ($number % 100 != 11)) ? 1 : 2; + } + } + /** + * Add Language Items + * + * Examples: + *
+ * $component = array('posting'); + * $component = array('posting', 'viewtopic') + * $component = 'posting' + *
+ * + * @param string|array $component The name of the language component to load + * @param string|null $extension_name Name of the extension to load component from, or null for core file + */ + public function add_lang($component, $extension_name = null) + { + // Load common language files if they not loaded yet + // This needs to be here to correctly merge language arrays + if (!$this->common_language_files_loaded) + { + $this->load_common_language_files(); + } + + if (!is_array($component)) + { + if (!is_null($extension_name)) + { + $this->load_extension($extension_name, $component); + } + else + { + $this->load_core_file($component); + } + } + else + { + foreach ($component as $lang_file) + { + $this->add_lang($lang_file, $extension_name); + } + } + } + /** + * @param $key array|string The language key we want to know more about. Can be string or array. + * + * @return bool Returns whether the language key is set. + */ + public function is_set($key) + { + // Load common language files if they not loaded yet + if (!$this->common_language_files_loaded) + { + $this->load_common_language_files(); + } + + if (is_array($key)) + { + $lang = &$this->lang[array_shift($key)]; + + foreach ($key as $_key) + { + $lang = &$lang[$_key]; + } + } + else + { + $lang = &$this->lang[$key]; + } + + return isset($lang); + } + + /** + * Advanced language substitution + * + * Function to mimic sprintf() with the possibility of using phpBB's language system to substitute nullar/singular/plural forms. + * Params are the language key and the parameters to be substituted. + * This function/functionality is inspired by SHS` and Ashe. + * + * Example call: $user->lang('NUM_POSTS_IN_QUEUE', 1); + * + * If the first parameter is an array, the elements are used as keys and subkeys to get the language entry: + * Example: $user->lang(array('datetime', 'AGO'), 1) uses $user->lang['datetime']['AGO'] as language entry. + * + * @return string Return localized string or the language key if the translation is not available + */ + public function lang() + { + $args = func_get_args(); + $key = array_shift($args); + + return $this->lang_array($key, $args); + } + /** + * BC function for loading language files + * + * @deprecated 3.2.0-dev (To be removed: 4.0.0) + */ + private function set_lang($lang_set, $use_help, $ext_name) + { + if (empty($ext_name)) + { + $ext_name = null; + } + + if ($use_help && strpos($lang_set, '/') !== false) + { + $component = dirname($lang_set) . '/help_' . basename($lang_set); + if ($component[0] === '/') + { + $component = substr($component, 1); + } + } + else + { + $component = (($use_help) ? 'help_' : '') . $lang_set; + } + + $this->add_lang($component, $ext_name); + + } + + /** + * Add Language Items from an extension - use_db and use_help are assigned where needed (only use them to force inclusion) + * + * @param string $ext_name The extension to load language from, or empty for core files + * @param mixed $lang_set specifies the language entries to include + * @param bool $use_db internal variable for recursion, do not use + * @param bool $use_help internal variable for recursion, do not use + * + * Note: $use_db and $use_help should be removed. Kept for BC purposes. + * + * @deprecated: 3.2.0-dev (To be removed: 4.0.0) + */ + function add_lang_ext($ext_name, $lang_set, $use_db = false, $use_help = false) + { + if ($ext_name === '/') + { + $ext_name = ''; + } + $this->add_lang($lang_set, $use_db, $use_help, $ext_name); + } +} +/** + * Base exception class for language exceptions + */ +class language_exception extends runtime_exception +{ + +} +/** + * This exception is thrown when the language file is not found + */ +class language_file_not_found extends language_exception +{ + +} +/** + * class language + */ ?> \ No newline at end of file diff --git a/includes/mx_functions_tools.php b/includes/mx_functions_tools.php index 330ff620..84dae2e3 100644 --- a/includes/mx_functions_tools.php +++ b/includes/mx_functions_tools.php @@ -2,7 +2,7 @@ /** * * @package Tools -* @version $Id: mx_functions_tools.php,v 1.69 2014/09/24 05:51:47 orynider Exp $ +* @version $Id: mx_functions_tools.php,v 1.67 2014/05/09 07:51:42 orynider Exp $ * @copyright (c) 2002-2008 MX-Publisher Project Team * @license http://opensource.org/licenses/gpl-license.php GNU General Public License v2 * @link http://mxpcms.sourceforge.net/ @@ -1080,26 +1080,26 @@ function drawForm() case "text": // text form $item_label = $item[1]; $item_field = ''; - break; + break; case "textarea": // textarea $item_label = $item[1]; $item_field = ''; - break; + break; case "password": // password $item_label = $item[1]; $item_field = ''; - break; + break; case "checkbox": // checkbox button $item_label = $item[1]; if ( isset( $item[3] ) ) $item_field = ''; else $item_field = ''; @@ -1109,7 +1109,7 @@ function drawForm() case "hidden": // hidden fields $item_label = ''; $item_field = ''; - break; + break; case "submit": // defining the label for submit button $submit = $item[1]; $submitname = $item[2]; @@ -1117,14 +1117,14 @@ function drawForm() case "delete": // delete button $item_label = $item[1]; $item_field = $item[2]; - break; + break; } if ( ! empty( $item_field ) ) { $template->assign_block_vars( "rows", array( 'LABEL' => $item_label, 'FIELD' => $item_field, - )); + )); } } $template->pparse( "body" ); @@ -1711,7 +1711,7 @@ function truncate_string($string, $max_length = 60, $max_store_length = 255, $al /* * Includes -*/ +/* if(!function_exists('prepare_message')) { //include_once($mx_root_path . 'includes/shared/phpbb2/includes/functions_post.' . $phpEx); @@ -1723,7 +1723,7 @@ function truncate_string($string, $max_length = 60, $max_store_length = 255, $al //include_once($mx_root_path . 'includes/shared/phpbb2/includes/functions_search.' . $phpEx); mx_cache::load_file('functions_search', 'phpbb2'); } -/*/ +*/ /** * Class: mx_notification. @@ -1946,20 +1946,17 @@ function _insert_pm() $error_msg .= ( ( !empty($error_msg) ) ? '
' : '' ) . $lang['Empty_subject']; } - if (!empty($this->message)) + if ( !empty($this->message) ) { - if (!$error) + if ( !$error ) { - if ($this->bbcode_on) + if ( $this->bbcode_on ) { $bbcode_uid = $mx_bbcode->make_bbcode_uid(); } - - if (method_exists($this, 'lookup')) - { - $privmsg_message = $this->prepare_message(addslashes($this->message), $this->html_on, $this->bbcode_on, $this->smilies_on, $bbcode_uid); - $privmsg_message = str_replace('\\\n', '\n', $privmsg_message); - } + + $privmsg_message = $this->prepare_message(addslashes($this->message), $this->html_on, $this->bbcode_on, $this->smilies_on, $bbcode_uid); + $privmsg_message = str_replace('\\\n', '\n', $privmsg_message); } } else @@ -3344,22 +3341,22 @@ function display_edit( $file_id = false ) { case INPUT: $this->display_edit_input( $file_id, $field_id, $field_data ); - break; + break; case TEXTAREA: $this->display_edit_textarea( $file_id, $field_id, $field_data ); - break; + break; case RADIO: $this->display_edit_radio( $file_id, $field_id, $field_data ); - break; + break; case SELECT: $this->display_edit_select( $file_id, $field_id, $field_data ); - break; + break; case SELECT_MULTIPLE: $this->display_edit_select_multiple( $file_id, $field_id, $field_data ); - break; + break; case CHECKBOX: $this->display_edit_checkbox( $file_id, $field_id, $field_data ); - break; + break; } $return = true; @@ -5757,13 +5754,13 @@ function display_internal_comments() { case USER_AVATAR_UPLOAD: $poster_avatar = ( $board_config['allow_avatar_upload'] ) ? '' : ''; - break; + break; case USER_AVATAR_REMOTE: $poster_avatar = ( $board_config['allow_avatar_remote'] ) ? '
' : ''; - break; + break; case USER_AVATAR_GALLERY: $poster_avatar = ( $board_config['allow_avatar_local'] ) ? '
' : ''; - break; + break; } } @@ -6026,13 +6023,13 @@ function display_phpbb_comments( ) { case USER_AVATAR_UPLOAD: $poster_avatar = ( $board_config['allow_avatar_upload'] ) ? '
' : ''; - break; + break; case USER_AVATAR_REMOTE: $poster_avatar = ( $board_config['allow_avatar_remote'] ) ? '
' : ''; - break; + break; case USER_AVATAR_GALLERY: $poster_avatar = ( $board_config['allow_avatar_local'] ) ? '
' : ''; - break; + break; } } diff --git a/includes/page_header.php b/includes/page_header.php index d7ce1f97..da6dbc7a 100644 --- a/includes/page_header.php +++ b/includes/page_header.php @@ -22,7 +22,9 @@ The following code related to GZIP initialization has been moved to the new mx_session_start() function, declared in mx_functions.php +// // gzip_compression +// $do_gzip_compress = FALSE; if ( $board_config['gzip_compress'] ) { @@ -59,8 +61,31 @@ if (!is_object($layouttemplate)) { // Initialize template - $layouttemplate = new mx_Template($mx_root_path . 'templates/'. $mx_user->theme['template_name'], $board_config, $db); + // + $layouttemplate = new mx_Template( $mx_root_path . 'templates/'. $theme['template_name'], $board_config, $db ); } + +// +// Obtain number of new private messages +// if user is logged in +if(!isset($mx_user) || !is_object($mx_user)) +{ + $mx_user = new mx_user(); +} + +// +// Obtain number of new private messages +// if cache is logged in +if(!isset($mx_cache) || !is_object($mx_cache)) +{ + $cache = new mx_cache(); +} + +// +// Load common language file from phpBB3 +//$mx_user->set_lang($mx_user->lang, $mx_user->help, 'common'); +$lang = &$mx_user->lang; + // If MX-Publisher page is not set, instantiate it if (!isset($mx_page->page_navigation_block)) { @@ -77,10 +102,609 @@ 'overall_header' => empty($mx_page->page_ov_header) || ( !file_exists($mx_root_path . TEMPLATE_ROOT_PATH . $mx_page->page_ov_header) && !file_exists($mx_root_path . TEMPLATE_ROOT_PATH . $page_ov_header2) ) ? ( empty($gen_simple_header) ? 'overall_header.' . $tplEx : 'simple_header.' . $tplEx ) : $mx_page->page_ov_header )); +// +// Generate logged in/logged out status +// +if ( $mx_user->data['session_logged_in'] ) +{ + $u_login_logout = 'login.'.$phpEx.'?logout=true&sid=' . $mx_user->data['session_id']; + $l_login_logout = $lang['Logout'] . ' [ ' . $mx_user->data['username'] . ' ]'; +} +else +{ + $u_login_logout = 'login.'.$phpEx; + $l_login_logout = $lang['Login']; +} + +$s_last_visit = ( $mx_user->data['session_logged_in'] ) ? mx_create_date($board_config['default_dateformat'], $mx_user->data['user_lastvisit'], $board_config['board_timezone']) : ''; + // Generate logged in/logged out status +if( !is_object($mx_backend)) +{ + $mx_backend = new mx_backend(); +} + $mx_backend->page_header('generate_login_logout_stats'); + +// ================================================================================ +// The following code is backported from includes/page_header.php (phpBB 2.0.13) +// ================================================================================ + +// +// Get basic (usernames + totals) online +// situation +// +$logged_visible_online = 0; +$logged_hidden_online = 0; +$guests_online = 0; + +// Get users online list ... if required +$l_online_users = $online_userlist = $l_online_record = $l_online_time = ''; + +$l_online_record = $mx_user->lang('RECORD_ONLINE_USERS', (int) $board_config['record_online_users'], $mx_user->format_date($board_config['record_online_date'], false, true)); + +/** +* Load online data: +*/ +if (defined('SHOW_ONLINE')) +{ + switch (PORTAL_BACKEND) + { + case 'internal': + $sql = "SELECT u.username, u.user_id, u.user_level, s.session_logged_in, s.session_ip + FROM ".USERS_TABLE." u, ".SESSIONS_TABLE." s + WHERE u.user_id = s.session_user_id + AND s.session_time >= ".(time() - 300) . " + ORDER BY u.username ASC, s.session_ip ASC"; + break; + case 'smf2': + //To do: + /** a query or we can use a session method + $sql = "SELECT u.id_member as u.user_id, u.member_name as u.username, u.id_group as u.user_level, s.session_id, s.data, + FROM ".USERS_TABLE." u, ".SESSIONS_TABLE." s + WHERE u.id_member > -1 + AND s.last_update >= ".(time() - 300) . " + ORDER BY u.member_name ASC, s.session_id ASC"; + **/ + break; + case 'phpbb2': + $sql = "SELECT u.username, u.user_id, u.user_allow_viewonline, u.user_level, s.session_logged_in, s.session_ip + FROM ".USERS_TABLE." u, ".SESSIONS_TABLE." s + WHERE u.user_id = s.session_user_id + AND s.session_time >= ".(time() - 300) . " + ORDER BY u.username ASC, s.session_ip ASC"; + break; + case 'phpbb3': + default: + $sql = "SELECT u.user_id, u.username, u.user_regdate, u.user_birthday, u.user_allow_viewonline, u.user_type, u.user_colour, s.session_autologin, s.session_ip + FROM ".USERS_TABLE." u, ".SESSIONS_TABLE." s + WHERE u.user_id = s.session_user_id + AND s.session_time >= ".(time() - 300) . " + ORDER BY u.username ASC, s.session_ip ASC"; + break; + } + + if( !($result = $db->sql_query($sql)) ) + { + mx_message_die(GENERAL_ERROR, 'Could not obtain user/online information', '', __LINE__, __FILE__, $sql); + } + + $mx_userlist_ary = array(); + $mx_userlist_visible = array(); + + $prev_user_id = 0; + $prev_user_ip = $prev_session_ip = ''; + + while($row = $db->sql_fetchrow($result)) + { + // User is logged in and therefor not a guest + if ($mx_user->data['user_id'] != ANONYMOUS) + { + // Skip multiple sessions for one user + if ( $row['user_id'] != $prev_user_id ) + { + $style_color = ''; + //switch only supported phpBB backends here + switch (PORTAL_BACKEND) + { + case 'internal': + case 'smf2': + case 'phpbb2': + if ( $row['user_level'] == ADMIN ) + { + $row['username'] = '' . $row['username'] . ''; + $style_color = 'style="color:#' . $theme['fontcolor3'] . '"'; + } + else if ( $row['user_level'] == MOD ) + { + $row['username'] = '' . $row['username'] . ''; + $style_color = 'style="color:#' . $theme['fontcolor2'] . '"'; + } + break; + + case 'phpbb3': + case 'olympus': + default: + $style_color = ($row['user_colour']) ? ' style="color:#' . $row['user_colour'] . '" class="username-coloured"' : ''; + break; + } + + switch (PORTAL_BACKEND) + { + case 'internal': + case 'smf2': + $mx_user_online_link = '' . $row['username'] . ''; + $logged_hidden_online++; + break; + case 'phpbb2': + $mx_user_online_link = '' . $row['username'] . ''; + $logged_hidden_online++; + break; + + case 'phpbb3': + case 'olympus': + default: + if ($row['user_allow_viewonline']) + { + $mx_user_online_link = $mx_backend->get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']); + $logged_visible_online++; + } + else + { + $mx_user_online_link = ($row['user_type'] != USER_IGNORE) ? mx_get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']) : '' . $row['username'] . ''; + $logged_hidden_online++; + } + break; + } + + if ( $row['user_allow_viewonline'] || $mx_user->data['user_level'] == ADMIN ) + { + $online_userlist .= ( $online_userlist != '' ) ? ', ' . $mx_user_online_link : $mx_user_online_link; + } + } + $prev_user_id = $row['user_id']; + } + else + { + // Skip multiple sessions for one user + if ( $row['session_ip'] != $prev_session_ip ) + { + $guests_online++; + } + } + $prev_session_ip = $row['session_ip']; + } + $db->sql_freeresult($result); + + if ( empty($online_userlist) ) + { + $online_userlist = $lang['None']; + } + + $online_userlist = ((isset($forum_id)) ? $lang['Browsing_forum'] : $lang['Registered_users']) . ' ' . $online_userlist; + $total_online_users = $logged_visible_online + $logged_hidden_online + $guests_online; + + if ($total_online_users > $board_config['record_online_users']) + { + $board_config['record_online_users'] = $total_online_users; + $board_config['record_online_date'] = time(); + + switch (PORTAL_BACKEND) + { + case 'internal': + $sql = "UPDATE " . PORTAL_TABLE . " + SET record_online_users = '$total_online_users', + record_online_date = '" . $board_config['record_online_date'] . "' + WHERE portal_id = 1"; + if (!$db->sql_query($sql)) + { + mx_message_die(GENERAL_ERROR, 'Could not update online user record (nr of users)', '', __LINE__, __FILE__, $sql); + } + + $portal_config['record_online_users'] = $total_online_users; + $portal_config['record_online_date'] = $board_config['record_online_date']; + $mx_cache->put('mxbb_config', $portal_config); + break; + + case 'phpbb2': + case 'phpbb3': + default: + $sql = "UPDATE " . CONFIG_TABLE . " + SET config_value = '$total_online_users' + WHERE config_name = 'record_online_users'"; + if (!$db->sql_query($sql)) + { + mx_message_die(GENERAL_ERROR, 'Could not update online user record (nr of users)', '', __LINE__, __FILE__, $sql); + } + $sql = "UPDATE " . CONFIG_TABLE . " + SET config_value = '" . $board_config['record_online_date'] . "' + WHERE config_name = 'record_online_date'"; + + if (!$db->sql_query($sql, 300)) + { + mx_message_die(GENERAL_ERROR, 'Could not update online user record (date)', '', __LINE__, __FILE__, $sql); + } + $board_config['record_online_users'] = $total_online_users; + $board_config['record_online_date'] = $board_config['record_online_date']; + $mx_cache->put('phpbb_config', $board_config); + break; + } + } + + if ( $total_online_users == 0 ) + { + $l_t_user_s = $lang['Online_users_zero_total']; + } + else if ( $total_online_users == 1 ) + { + $l_t_user_s = $lang['Online_user_total']; + } + else + { + $l_t_user_s = $lang['Online_users_total']; + } + + if ( $logged_visible_online == 0 ) + { + $l_r_user_s = $lang['Reg_users_zero_total']; + } + else if ( $logged_visible_online == 1 ) + { + $l_r_user_s = $lang['Reg_user_total']; + } + else + { + $l_r_user_s = $lang['Reg_users_total']; + } + + if ( $logged_hidden_online == 0 ) + { + $l_h_user_s = $lang['Hidden_users_zero_total']; + } + else if ( $logged_hidden_online == 1 ) + { + $l_h_user_s = $lang['Hidden_user_total']; + } + else + { + $l_h_user_s = $lang['Hidden_users_total']; + } + + if ( $guests_online == 0 ) + { + $l_g_user_s = $lang['Guest_users_zero_total']; + } + else if ( $guests_online == 1 ) + { + $l_g_user_s = $lang['Guest_user_total']; + } + else + { + $l_g_user_s = $lang['Guest_users_total']; + } + + $l_online_users = sprintf($l_t_user_s, $total_online_users); + $l_online_users .= sprintf($l_r_user_s, $logged_visible_online); + $l_online_users .= sprintf($l_h_user_s, $logged_hidden_online); + $l_online_users .= sprintf($l_g_user_s, $guests_online); +} + +// +// Obtain number of new private messages +// if user is logged in +// +switch (PORTAL_BACKEND) +{ + case 'internal': + case 'smf2': + case 'mybb': + + break; + + case 'phpbb2': + case 'phpbb3': + case 'olympus': + case 'ascraeus': + case 'rhea': + + global $phpbb_auth; + + if(!isset($phpbb_auth) || !is_object($phpbb_auth)) + { + $phpbb_auth = new phpbb_auth(); + } + $phpbb_auth->acl($mx_user->data); + + break; +} + +if( class_exists('phpBB2')) +{ + $phpBB2 = new phpBB2(); +} + +// Output the notifications +$total_msgs = $notifications = false; +$mx_priv_msg = $lang['Private_Messages']; +if ( ($mx_user->data['session_logged_in']) && (PORTAL_BACKEND !== 'internal') && (empty($gen_simple_header)) ) +{ + if ( $mx_user->data['user_new_privmsg'] ) + { + $l_message_new = ( $mx_user->data['user_new_privmsg'] == 1 ) ? $lang['New_pm'] : $lang['New_pms']; + $l_privmsgs_text = sprintf($l_message_new, $mx_user->data['user_new_privmsg']); + + if ( $mx_user->data['user_last_privmsg'] > $mx_user->data['user_lastvisit'] ) + { + $sql = "UPDATE " . USERS_TABLE . " + SET user_last_privmsg = " . $mx_user->data['user_lastvisit'] . " + WHERE user_id = " . $mx_user->data['user_id']; + if ( !$db->sql_query($sql) ) + { + mx_message_die(GENERAL_ERROR, 'Could not update private message new/read time for user', '', __LINE__, __FILE__, $sql); + } + + $s_privmsg_new = 1; + $icon_pm = $images['pm_new_msg']; + } + else + { + $s_privmsg_new = 0; + $icon_pm = $images['pm_no_new_msg']; + } + $mx_priv_msg = $lang['Private_Messages'] . ' (' . $mx_user->data['user_new_privmsg'] . ')'; + } + else + { + $l_privmsgs_text = $lang['No_new_pm']; + + $s_privmsg_new = 0; + $icon_pm = $images['pm_no_new_msg']; + $mx_priv_msg = $lang['Private_Messages']; + } + + if ( $mx_user->data['user_unread_privmsg'] ) + { + $l_message_unread = ( $mx_user->data['user_unread_privmsg'] == 1 ) ? $lang['Unread_pm'] : $lang['Unread_pms']; + $l_privmsgs_text_unread = sprintf($l_message_unread, $mx_user->data['user_unread_privmsg']); + } + else + { + $l_privmsgs_text_unread = $lang['No_unread_pm']; + } + + // + // SQL to pull appropriate message, prevents nosey people + // reading other peoples messages ... hopefully! + // + $privmsgs_id = $phpBB2->request_var(POST_POST_URL, $s_privmsg_new); + $l_box_name = $lang['Inbox']; + + // + // Did the query return any data? + // + $notifications = array(); + + switch (PORTAL_BACKEND) + { + case 'internal': + case 'smf2': + case 'mybb': + + + break; + + case 'phpbb2': + case 'phpbb3': + case 'olympus': + case 'ascraeus': + case 'rhea': + + $pm_sql_user = "AND pm.privmsgs_to_userid = " . $mx_user->data['user_id'] . " + AND ( pm.privmsgs_type = " . PRIVMSGS_READ_MAIL . " + OR pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . " + OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )"; + // + // Major query obtains the message ... + // + $sql = "SELECT u.username AS username_1, u.user_id AS user_id_1, u2.username AS username_2, u2.user_id AS user_id_2, u.user_sig_bbcode_uid, u.user_regdate AS user_regdate1,u.user_posts AS user_posts1, u.user_from AS user_from1, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_msnm, u.user_viewemail, u.user_rank AS user_rank1, u.user_sig, u.user_avatar AS user_avatar1,u.user_avatar_type AS user_avatar_type1, pm.*, pmt.privmsgs_bbcode_uid, pmt.privmsgs_text + FROM " . PRIVMSGS_TABLE . " pm, " . PRIVMSGS_TEXT_TABLE . " pmt, " . USERS_TABLE . " u, " . USERS_TABLE . " u2 + WHERE pm.privmsgs_id = pmt.privmsgs_text_id + $pm_sql_user + AND u.user_id = pm.privmsgs_from_userid + AND u2.user_id = pm.privmsgs_to_userid"; + if ( !($result = $db->sql_query($sql)) ) + { + mx_message_die(GENERAL_ERROR, 'Could not query private message post information', '', __LINE__, __FILE__, $sql); + } + if ( $privmsg = $db->sql_fetchrow($result) ) + { + $notifications[] = $privmsg; + $privmsg_id = $privmsg['privmsgs_id']; + } + else + { + $privmsg_id = request_var(POST_POST_URL, $s_privmsg_new); + } + $db->sql_freeresult($result); + break; + } + + if ( !($total_msgs = count($notifications)) ) + { + $total_msgs = 0; + + // Merge default options + $notifications = array_merge(array( + 'notification_id' => 0, + 'notification_time' => time(), + 'user_id' => $mx_user->data['user_id'], + 'order_by' => 'notification_time', + 'older_unread' => 1, + 'order_dir' => 'DESC', + 'all_unread' => 0, + 'unread_count' => 0, + 'limit' => 5, + 'start' => 0, + 'REASON' => 'Could not query private message post information', + 'count_unread' => 0, + 'count_total' => $total_msgs, + ), $notifications); + } + + // Merge default options + $notifications = array_merge(array( + 'notification_id' => $privmsg_id, + 'notification_time' => !empty($privmsg['privmsgs_date']) ? $privmsg['privmsgs_date'] : time(), + 'user_id' => $mx_user->data['user_id'], + 'order_by' => 'notification_time', + 'older_unread' => $s_privmsg_new, + 'order_dir' => 'DESC', + 'all_unread' => $s_privmsg_new, + 'unread_count' => $s_privmsg_new, + 'limit' => 5, + 'start' => 0, + 'REASON' => $privmsg['privmsgs_text'], + 'count_unread' => $s_privmsg_new, + 'count_total' => $total_msgs, + ), $notifications); +} +else +{ + $icon_pm = !empty($images['pm_no_new_msg']) ? $images['pm_no_new_msg'] : 'no_new_msg'; + $l_privmsgs_text = $lang['Login_check_pm']; + $l_privmsgs_text_unread = ''; + $s_privmsg_new = 0; + $privmsg_id = 0; + + $notifications = array( + 'all_unread' => $s_privmsg_new, + 'unread_count' => $s_privmsg_new, + 'limit' => 5, + ); + // Merge default options + $notifications = array_merge(array( + 'notification_id' => false, + 'notification_time' => time(), + 'user_id' => $mx_user->data['user_id'], + 'order_by' => 'notification_time', + 'order_dir' => 'DESC', + 'limit' => 5, + 'start' => 0, + 'all_unread' => $s_privmsg_new, + 'count_unread' => $s_privmsg_new, + 'count_total' => false, + 'S_ROW_COUNT' => 0, + 'S_NUM_ROWS' => 0, + 'UNREAD' => 0, + 'STYLING' => 0, + 'URL' => 0, + 'U_MARK_READ' => 0, + 'AVATAR' => 0, + 'T_THEME_PATH' => 0, + 'FORMATTED_TITLE' => 0, + 'REFERENCE' => 0, + 'FORUM' => 0, + 'REASON' => 0, + 'TIME' => 0, + 'U_MARK_READ' => 0, + ), $notifications); +} +$notification_mark_hash = mx_generate_link_hash('mark_all_notifications_read'); +$mark_hash = mx_generate_link_hash('mark_notification_read'); +$u_mark_read = mx_append_sid($phpbb_root_path . 'privmsg.' . $phpEx . '?mark_notification=' . $notifications['notification_id'] . '&folder=inbox&hash=' . $mark_hash); + +// Login box? +// +if ( !$mx_user->data['session_logged_in'] ) +{ + $template->assign_block_vars('switch_user_logged_out', array()); + // + // Allow autologin? + // + if (!isset($board_config['allow_autologin']) || $board_config['allow_autologin'] ) + { + $template->assign_block_vars('switch_allow_autologin', array()); + $template->assign_block_vars('switch_user_logged_out.switch_allow_autologin', array()); + } + $template->assign_block_vars('notifications', array()); +} +else +{ + $template->assign_block_vars('switch_user_logged_in', array()); + + //if ( !empty($mx_userdata['user_popup_pm']) ) + //{ + $template->assign_block_vars('switch_enable_pm_popup', array()); + + $template->assign_block_vars('notifications', array( + 'NOTIFICATION_ID' => $notifications['notification_id'], + + 'USER_ID' => $notifications['user_id'], + 'ORDER_BY' => $notifications['order_by'], + 'ORDER_DIR' => $notifications['order_dir'], + 'ALL_UNREAD' => $notifications['all_unread'], + 'UNREAD_COUNT' => $notifications['unread_count'], + 'LIMIT' => $notifications['limit'], + 'START' => $notifications['start'], + 'COUNT_UNREAD' => $notifications['count_unread'], + 'COUNT_TOTAL' => $notifications['count_total'], + + 'STYLING' => 'notification-reported', + 'AVATAR' => mx_get_user_avatar($mx_user->data), + 'FORMATTED_TITLE' => $mx_user->lang('NOTIFICATION', $mx_user->data['username'], false), + + 'REFERENCE' => $mx_user->lang('NOTIFICATION_REFERENCE', mx_censor_text($l_privmsgs_text)), + 'FORUM' => mx_append_sid('privmsg.'.$phpEx.'?folder=inbox'), //$this->get_forum(), + 'REASON' => $notifications['REASON'], //$this->get_reason(), + 'URL' => mx_append_sid('privmsg.'.$phpEx.'?folder=inbox'), //$this->get_url(), + + 'TIME' => $mx_user->format_date($notifications['notification_time']), + + 'UNREAD' => $l_privmsgs_text_unread, + 'U_MARK_READ' => (!$mx_user->data['user_unread_privmsg']) ? $u_mark_read : '', + )); + //} +} + +switch (PORTAL_BACKEND) +{ + case 'internal': + case 'smf2': + case 'mybb': + + if ( !defined('PHPBB_VERSION') ) + { + define('PHPBB_VERSION', $board_config['portal_version']); + } + + break; + + case 'phpbb2': + + if ( !defined('PHPBB_VERSION') ) + { + define('PHPBB_VERSION', '2'.$board_config['version']); + } + + break; + + case 'phpbb3': + case 'olympus': + case 'ascraeus': + case 'rhea': + + if ( !defined('PHPBB_VERSION') ) + { + define('PHPBB_VERSION', $board_config['version']); + } + + break; +} + +// // Generate HTML required for Mozilla Navigation bar +// if ( !isset( $nav_links ) ) { $nav_links = array(); @@ -104,7 +728,14 @@ } } +$forum_id = $phpBB2->request_var('f', (isset($forum_id) ? $forum_id : 0)); +$topic_id = $phpBB2->request_var('t', (isset($topic_id) ? $topic_id : 0)); + +$s_feed_news = isset($s_feed_news) ? $s_feed_news : false; + +// // Format Timezone. We are unable to use array_pop here, because of PHP3 compatibility +// $l_timezone = explode( '.', $board_config['board_timezone'] ); $l_timezone = ( count( $l_timezone ) > 1 && $l_timezone[count( $l_timezone )-1] != 0 ) ? $lang[sprintf( '%.1f', $board_config['board_timezone'] )] : $lang[number_format( $board_config['board_timezone'] )]; @@ -118,17 +749,21 @@ } // Search box -$search_page_id_pafiledb = get_page_id('dload.' . $phpEx, true); -$search_page_id_kb = get_page_id('kb.' . $phpEx, true); $search_page_id_site = get_page_id('mx_search.' . $phpEx, true); - $option_search_site = !empty($search_page_id_site) ? '' : ''; + $option_search_forum = ''; +$option_search_google = ''; + +$search_page_id_kb = get_page_id('kb.' . $phpEx, true); $option_search_kb = !empty($search_page_id_kb) ? '' : ''; + +$search_page_id_pafiledb = get_page_id('dload.' . $phpEx, true); $option_search_pafiledb = !empty($search_page_id_pafiledb) ? '' : ''; -$option_search_google = ''; +// // Generate list of additional css files to include (defined by modules) +// $mx_addional_css_files = ''; if (isset($mx_page->mxbb_css_addup) && (count($mx_page->mxbb_css_addup) > 0)) { @@ -138,7 +773,9 @@ } } +// // Generate list of additional js files to include (defined by modules) +// $mx_addional_js_files = ''; if (isset($mx_page->mxbb_js_addup) && (count($mx_page->mxbb_js_addup) > 0)) { @@ -148,7 +785,9 @@ } } +// // Generate additional header code (defined by modules) +// $mx_addional_header_text = ''; if (isset($mx_page->mxbb_header_addup) && (count($mx_page->mxbb_header_addup) > 0)) { @@ -158,15 +797,52 @@ } } +// Send a proper content-language to the output +$user_lang = isset($mx_user->lang['USER_LANG']) ? $mx_user->lang['USER_LANG'] : $mx_user->encode_lang($mx_user->lang_name); +if (strpos($user_lang, '-x-') !== false) +{ + $user_lang = substr($user_lang, 0, strpos($user_lang, '-x-')); +} + +$phpbb_version_parts = explode('.', PHPBB_VERSION, 3); +$phpbb_major = $phpbb_version_parts[0] . '.' . $phpbb_version_parts[1]; + +@define('USER_ACTIVATION_NONE', 0); +@define('USER_ACTIVATION_SELF', 1); +@define('USER_ACTIVATION_ADMIN', 2); +@define('USER_ACTIVATION_DISABLE', 3); + +// +// Show the overall footer. +// +$admin_link = ($mx_user->data['user_level'] == ADMIN) ? '' . $lang['Admin_panel'] . '
' : ''; + +// Forum rules and subscription info +$s_watching_forum = array( + 'link' => '', + 'link_toggle' => '', + 'title' => '', + 'title_toggle' => '', + 'is_watching' => false, +); + +$default_lang = ($mx_user->data['user_lang']) ? $mx_user->data['user_lang'] : $portal_config['default_lang']; +if (empty($default_lang)) +{ + // - populate $default_lang + $default_lang= 'english'; +} + $useragent = (isset($_SERVER['HTTP_USER_AGENT'])) ? $_SERVER['HTTP_USER_AGENT'] : getenv('HTTP_USER_AGENT'); + switch (PORTAL_BACKEND) { case 'internal': case 'smf2': case 'mybb': case 'phpbb2': - $admin = ($userdata['session_logged_in'] && $userdata['user_level'] == ADMIN) ? true : false; + $admin = ($mx_user->data['session_logged_in'] && $mx_user->data['user_level'] == ADMIN) ? true : false; break; case 'phpbb3': @@ -178,22 +854,88 @@ break; } +// +// Grab MXP global variables, re-cache if necessary +// - optional parameter to enable/disable cache for config data. If enabled, remember to refresh the MX-Publisher cache whenever updating MXP config settings +// - true: enable cache, false: disable cache +if (empty($portal_config['portal_status'])) +{ + $portal_config = $mx_cache->obtain_mxbb_config(false); +} + +$web_path = (!empty($portal_config['portal_url'])) ? PORTAL_URL : BOARD_URL; +$https_path = str_replace("http://", "https://", $web_path); +$web_path = str_replace("https://", "http://", $web_path); + +// +// The following assigns all _common_ variables that may be used at any point +// in a template. +// $layouttemplate->assign_vars(array( - 'SITENAME' => $board_config['sitename'], - 'SITE_DESCRIPTION' => $board_config['site_desc'], - 'PAGE_TITLE' => $mx_page->page_title, - 'CURRENT_TIME' => sprintf($lang['Current_time'], phpBB2::create_date($board_config['default_dateformat'], time(), $board_config['board_timezone'])), - 'RECORD_USERS' => sprintf($lang['Record_online_users'], $board_config['record_online_users'], phpBB2::create_date($board_config['default_dateformat'], $board_config['record_online_date'], $board_config['board_timezone'])), + 'SITENAME' => $board_config['sitename'], + 'SITE_DESCRIPTION' => $board_config['site_desc'], + 'PAGE_TITLE' => $mx_page->page_title, + 'LANG' => $mx_user->img_lang, + 'SCRIPT_NAME' => str_replace('.' . $phpEx, '', basename(__FILE__)), + 'LAST_VISIT_DATE' => sprintf($lang['You_last_visit'], $s_last_visit), + 'LAST_VISIT_YOU' => $s_last_visit, + 'CURRENT_TIME' => sprintf($lang['Current_time'], mx_create_date($board_config['default_dateformat'], time(), $board_config['board_timezone'])), + 'TOTAL_USERS_ONLINE' => $l_online_users, + 'RECORD_USERS' => $l_online_record, + 'LOGGED_IN_USER_LIST' => $online_userlist, + 'RECORD_USERS' => sprintf($lang['Record_online_users'], $board_config['record_online_users'], mx_create_date($board_config['default_dateformat'], $board_config['record_online_date'], $board_config['board_timezone'])), + + 'CURRENT_USER_AVATAR' => mx_get_user_avatar($mx_user->data), + 'CURRENT_USERNAME_SIMPLE' => mx_get_username_string('no_profile', $mx_user->data['user_id'], $mx_user->data['username'], $mx_user->data['user_colour']), + 'CURRENT_USERNAME_FULL' => mx_get_username_string('full', $mx_user->data['user_id'], $mx_user->data['username'], $mx_user->data['user_colour']), + + 'S_NOTIFICATIONS_DISPLAY' => true, + 'S_SHOW_COPPA' => false, + 'S_REGISTRATION' => true, + + 'UNREAD_NOTIFICATIONS_COUNT' => ($notifications !== false) ? $notifications['unread_count'] : '', + 'NOTIFICATIONS_COUNT' => ($notifications !== false) ? $notifications['unread_count'] : '', + 'U_VIEW_ALL_NOTIFICATIONS' => mx_append_sid("{$phpbb_root_path}profile.$phpEx?i=ucp_notifications"), + 'U_MARK_ALL_NOTIFICATIONS' => mx_append_sid("{$phpbb_root_path}profile.$phpEx?i=ucp_notifications&mode=notification_list&mark=all&token=" . $notification_mark_hash), + 'U_NOTIFICATION_SETTINGS' => mx_append_sid("{$phpbb_root_path}profile.$phpEx?i=ucp_notifications&mode=notification_options"), + 'S_NOTIFICATIONS_DISPLAY' => $mx_user->data['user_active'], + + 'loops' => '', // To get loops + + // 'L_CHANGE_FONT_SIZE' => '', + 'FONT_SIZE_CHANGE' => '- -- -', + + 'S_PLUPLOAD' => false, + 'S_IN_SEARCH' => false, + 'S_DISPLAY_QUICK_LINKS' => true, + + 'S_USER_NEW_PRIVMSG' => $mx_user->data['user_new_privmsg'], + 'S_USER_UNREAD_PRIVMSG' => $mx_user->data['user_unread_privmsg'], + 'S_USER_NEW' => ($mx_user->data['user_active'] == 0) ? true : false, + + 'RECORD_USERS' => sprintf($lang['Record_online_users'], $board_config['record_online_users'], mx_create_date($board_config['default_dateformat'], $board_config['record_online_date'], $board_config['board_timezone'])), + + 'PRIVATE_MESSAGE_COUNT' => (!empty($mx_user->data['user_unread_privmsg'])) ? $mx_user->data['user_unread_privmsg'] : 0, + 'PRIVATE_MESSAGE_INFO' => $l_privmsgs_text, + 'PRIVATE_MESSAGE_INFO_UNREAD' => $l_privmsgs_text_unread, + 'PRIVATE_MESSAGE_NEW_FLAG' => $s_privmsg_new, + + 'PRIVMSG_IMG' => $icon_pm, 'L_USERNAME' => $lang['Username'], 'L_PASSWORD' => $lang['Password'], + 'L_LOGIN_LOGOUT' => $l_login_logout, 'L_LOGIN' => $lang['Login'], 'L_LOG_ME_IN' => $lang['Log_me_in'], 'L_AUTO_LOGIN' => $lang['Log_me_in'], + 'L_HOME' => $lang['MX_home'], + 'L_FORUM' => $lang['MX_forum'], 'L_INDEX' => $board_config['sitename'], + 'L_SITE_HOME' => ($board_config['sitename'] !== '') ? $board_config['sitename'] : $mx_user->lang['HOME'], 'L_REGISTER' => $lang['Register'], 'L_PROFILE' => $lang['Profile'], 'L_SEARCH' => $lang['Search'], + 'L_PRIVATEMSGS' => $mx_priv_msg, 'L_WHO_IS_ONLINE' => $lang['Who_is_Online'], 'L_MEMBERLIST' => $lang['Memberlist'], 'L_FAQ' => $lang['FAQ'], @@ -223,29 +965,153 @@ 'NAV_IMAGES_LOGIN_LOGOUT' => $images['mx_nav_login'], 'NAV_IMAGES_REGISTER' => $images['mx_nav_register'], + 'L_POST_BY_AUTHOR' => $lang['Post_by_author'], + 'L_POSTED_ON_DATE' => $lang['Posted_on_date'], + 'L_IN' => $lang['In'], + + //navbar_footer + 'U_WATCH_FORUM_LINK' => $s_watching_forum['link'], + 'U_WATCH_FORUM_TOGGLE' => $s_watching_forum['link_toggle'], + 'S_WATCH_FORUM_TITLE' => $s_watching_forum['title'], + 'S_WATCH_FORUM_TOGGLE' => $s_watching_forum['title_toggle'], + 'S_WATCHING_FORUM' => $s_watching_forum['is_watching'], + + 'U_SEARCH_SELF' => mx_append_sid("{$phpbb_root_path}search.$phpEx?search_id=egosearch"), + 'U_SEARCH_NEW' => mx_append_sid("{$phpbb_root_path}search.$phpEx?search_id=newposts"), + 'U_SEARCH_UNANSWERED' => mx_append_sid("{$phpbb_root_path}search.$phpEx?search_id=unanswered"), + 'U_SEARCH_UNREAD' => mx_append_sid("{$phpbb_root_path}search.$phpEx?search_id=unreadposts"), + 'U_SEARCH_ACTIVE_TOPICS'=> mx_append_sid("{$phpbb_root_path}search.$phpEx?search_id=active_topics"), + + 'U_INDEX' => mx_append_sid("{$phpbb_root_path}index.$phpEx"), + 'U_CANONICAL' => mx_append_sid(PORTAL_URL . "index.$phpEx"), + 'U_SITE_HOME' => (!empty($board_config['site_home_url'])) ? $board_config['site_home_url'] : mx_append_sid('./../index.'.$phpEx), + 'U_REGISTER' => mx_append_sid('profile.'.$phpEx.'?mode=register'), + 'U_PROFILE' => mx_append_sid('profile.'.$phpEx.'?mode=editprofile'), + 'U_RESTORE_PERMISSIONS' => mx_append_sid("{$phpbb_root_path}memberlist.$phpEx?mode=restore_perm"), + 'U_USER_PROFILE' => mx_get_username_string('profile_url', $mx_user->data['user_id'], $mx_user->data['username'], false), + 'U_PRIVATEMSGS' => mx_append_sid('privmsg.'.$phpEx.'?folder=inbox'), + 'U_PRIVATEMSGS_POPUP' => mx_append_sid('privmsg.'.$phpEx.'?mode=newpm'), + 'U_SEARCH' => mx_append_sid('search.'.$phpEx), + 'U_MEMBERLIST' => mx_append_sid('memberlist.'.$phpEx), + 'U_MODCP' => mx_append_sid('modcp.'.$phpEx), + 'U_MCP' => (((PORTAL_BACKEND !== 'internal') && ($phpbb_auth->acl_get('m_') || $phpbb_auth->acl_getf_global('m_'))) ? mx_append_sid("{$phpbb_root_path}modcp.$phpEx?i=main&mode=front" . $mx_user->session_id) : ''), + 'U_FAQ' => mx_append_sid('faq.'.$phpEx), + 'U_VIEWONLINE' => mx_append_sid('viewonline.'.$phpEx), + 'U_LOGIN_LOGOUT' => mx_append_sid($u_login_logout), + 'U_GROUP_CP' => mx_append_sid('groupcp.'.$phpEx), + + 'U_SEND_PASSWORD' => ($mx_user->data['user_email']) ? mx_append_sid("{$phpbb_root_path}profile.$phpEx?mode=sendpassword") : '', + + 'S_VIEWTOPIC' => mx_append_sid("viewtopic.$phpEx?" . "f=" . $forum_id . "&t=" . $topic_id), + 'S_VIEWFORUM' => mx_append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"), + 'S_IN_MCP' => defined('IN_MCP') ? true : false, + 'S_IN_PROFILE' => defined('IN_PROFILE') ? true : false, + 'S_IN_UCP' => defined('IN_UCP') ? true : false, + + 'U_CONTACT_US' => ($mx_user->data['user_last_privmsg']) ? mx_append_sid("{$phpbb_root_path}memberlist.$phpEx?mode=contactadmin") : '', + 'U_TEAM' => ($mx_user->data['user_id'] != ANONYMOUS && (PORTAL_BACKEND !== 'internal') && $phpbb_auth->acl_get('u_viewprofile')) ? mx_append_sid("{$phpbb_root_path}memberlist.$phpEx?mode=team") : '', + 'U_TERMS_USE' => mx_append_sid("{$phpbb_root_path}profile.$phpEx?mode=terms"), + 'U_PRIVACY' => mx_append_sid("{$phpbb_root_path}profile.$phpEx?mode=privacy"), + 'U_RESTORE_PERMISSIONS' => ($mx_user->data['user_perm_from'] && (PORTAL_BACKEND !== 'internal') && $phpbb_auth->acl_get('a_switchperm')) ? mx_append_sid("{$phpbb_root_path}profile.$phpEx?mode=restore_perm") : '', + 'U_FEED' => '', + 'S_CONTENT_DIRECTION' => $lang['DIRECTION'] ? $lang['DIRECTION'] : $mx_user->lang['DIRECTION'], - 'S_CONTENT_DIR_LEFT' => $lang['LEFT'], - 'S_CONTENT_DIR_RIGHT' => $lang['RIGHT'], 'S_CONTENT_FLOW_BEGIN' => ($lang['DIRECTION'] == 'ltr') ? 'left' : 'right', 'S_CONTENT_FLOW_END' => ($lang['DIRECTION'] == 'ltr') ? 'right' : 'left', 'S_CONTENT_ENCODING' => $lang['ENCODING'] ? $lang['ENCODING'] : 'UTF-8', - - 'S_USER_LANG' => isset($lang['USER_LANG']) ? $lang['USER_LANG'] : $mx_user->encode_lang($board_config['default_lang']), - 'S_TIMEZONE' => sprintf($lang['All_times'], $l_timezone), - 'S_LOGIN_ACTION' => mx_append_sid(PORTAL_URL . 'login.'.$phpEx), - 'S_ADMIN_AUTH' => $admin, + 'S_CONTENT_DIR_LEFT' => $lang['LEFT'], + 'S_CONTENT_DIR_RIGHT' => $lang['RIGHT'], + + 'S_LOGIN_ACTION' => mx_append_sid('login.'.$phpEx), + 'S_LOGIN_REDIRECT' => $phpBB2->build_url(), + 'S_ADMIN_AUTH' => $admin, //Login page or box constants + 'S_USER_LOGGED_IN' => ($mx_user->data['user_id'] != ANONYMOUS) ? true : false, 'S_AUTOLOGIN_ENABLED' => ($board_config['allow_autologin']) ? true : false, - 'S_BOARD_DISABLED' => ($board_config['portal_status']) ? true : false, + 'S_BOARD_DISABLED' => ($portal_config['portal_status']) ? false : true, + 'S_USERNAME' => !empty($mx_user->data['username']) ? $mx_user->data['username'] : 'Anonymous', + 'S_REGISTERED_USER' => (!empty($mx_user->data['user_active'])) ? true : false, + 'S_IS_BOT' => (!empty($mx_user->data['is_bot'])) ? true : false, + 'S_USER_LANG' => $user_lang, + 'S_USER_BROWSER' => (isset($mx_user->data['session_browser'])) ? $mx_user->data['session_browser'] : $mx_user->lang('UNKNOWN_BROWSER'), + + 'S_LOAD_UNREADS' => ($mx_user->data['user_id'] != ANONYMOUS) ? true : false, + 'S_TIMEZONE' => sprintf($lang['All_times'], $l_timezone), + 'S_DISPLAY_ONLINE_LIST' => ($l_online_time) ? 1 : 0, + 'S_DISPLAY_SEARCH' => (isset($auth) ? ($mx_user->data['user_id'] != ANONYMOUS) : 1), + 'S_DISPLAY_PM' => ($mx_user->data['user_id'] != ANONYMOUS) ? true : false, + 'S_DISPLAY_MEMBERLIST' => (isset($auth)) ? ($mx_user->data['user_id'] != ANONYMOUS) : 0, + 'S_NEW_PM' => ($s_privmsg_new) ? 1 : 0, + 'S_REGISTER_ENABLED' => ($board_config['require_activation'] != USER_ACTIVATION_DISABLE) ? true : false, + 'S_FORUM_ID' => $forum_id, + 'S_TOPIC_ID ' => $topic_id, + + 'S_SIMPLE_MESSAGE' => false, + + //+ MX-Publisher + 'U_PORTAL_ROOT_PATH' => PORTAL_URL, + 'U_PHPBB_ROOT_PATH' => PHPBB_URL, + 'TEMPLATE_ROOT_PATH' => TEMPLATE_ROOT_PATH, + + 'SID' => !empty($SID) ? $SID : $mx_user->session_id, + '_SID' => !empty($_GET['sid']) ? $_GET['sid'] : $mx_user->session_id, + 'SESSION_ID' => !empty($mx_user->data['session_id']) ? $mx_user->data['session_id'] : (isset($_COOKIE[$board_config['cookie_name'] . '_sid'] ) ? $_COOKIE[$board_config['cookie_name'] . '_sid'] : ''), + 'ROOT_PATH' => $web_path, + 'FULL_SITE_PATH' => $web_path, + 'CMS_PAGE_HOME' => PORTAL_URL, + 'BOARD_URL' => PORTAL_URL, + 'PHPBB_VERSION' => PHPBB_VERSION, + 'PHPBB_MAJOR' => $phpbb_major, + 'S_COOKIE_NOTICE' => !empty($board_config['cookie_name']), + + 'T_ASSETS_VERSION' => $phpbb_major, + 'T_ASSETS_PATH' => "{$web_path}assets", + 'T_THEME_PATH' => "{$web_path}templates/" . rawurlencode($theme['template_name'] ? $theme['template_name'] : str_replace('.css', '', $theme['head_stylesheet'])) . '/theme', + 'T_TEMPLATE_PATH' => "{$web_path}templates/" . rawurlencode($theme['template_name']) . '', + 'T_SUPER_TEMPLATE_PATH' => "{$web_path}templates/" . rawurlencode($theme['template_name']) . '/template', + + 'T_IMAGES_PATH' => "{$web_path}images/", + 'T_SMILIES_PATH' => "{$web_path}{$board_config['smilies_path']}/", + 'T_AVATAR_GALLERY_PATH' => "{$web_path}{$board_config['avatar_gallery_path']}/", + + 'T_ICONS_PATH' => !empty($board_config['icons_path']) ? "{$web_path}{$board_config['icons_path']}/" : $web_path.'/images/icons/', + 'T_RANKS_PATH' => !empty($board_config['ranks_path']) ? "{$web_path}{$board_config['ranks_path']}/" : $web_path.'/images/ranks/', + 'T_UPLOAD_PATH' => !empty($board_config['upload_path']) ? "{$web_path}{$board_config['upload_path']}/" : $web_path.'/cache/', + + 'T_STYLESHEET_LINK' => "{$web_path}templates/" . rawurlencode($theme['template_name'] ? $theme['template_name'] : str_replace('.css', '', $theme['head_stylesheet'])) . '/theme/stylesheet.css', + 'T_STYLESHEET_LANG_LINK'=> "{$web_path}templates/" . rawurlencode($theme['template_name'] ? $theme['template_name'] : str_replace('.css', '', $theme['head_stylesheet'])) . '/theme/images/lang_' . $default_lang . '/stylesheet.css', + 'T_FONT_AWESOME_LINK' => "{$web_path}assets/css/font-awesome.min.css", + + 'T_JQUERY_LINK' => !empty($board_config['allow_cdn']) && !empty($board_config['load_jquery_url']) ? $board_config['load_jquery_url'] : "{$web_path}assets/javascript/jquery.min.js?assets_version=" . $phpbb_major, + 'S_ALLOW_CDN' => !empty($board_config['allow_cdn']), + + + 'T_THEME_NAME' => rawurlencode($theme['template_name']), + 'T_THEME_LANG_NAME' => $mx_user->data['user_lang'], + 'T_TEMPLATE_NAME' => $theme['template_name'], + 'T_SUPER_TEMPLATE_NAME' => rawurlencode($theme['template_name']), + 'T_IMAGES' => 'images', + 'T_SMILIES' => $board_config['smilies_path'], + 'T_AVATAR_GALLERY' => $board_config['avatar_gallery_path'], + + 'T_ICONS_PATH' => !empty($board_config['icons_path']) ? $board_config['icons_path'] : '/images/icons/', + 'T_RANKS_PATH' => !empty($board_config['ranks_path']) ? $board_config['ranks_path'] : '/images/ranks/', + 'T_UPLOAD_PATH' => !empty($board_config['upload_path']) ? $board_config['upload_path'] : '/cache/', + + 'SITE_LOGO_IMG' => ($theme['template_name'] == 'subSilver') ? 'logo_phpBB.gif' : 'site_logo.gif', + //To Do - configurable in AdminCP //Display full login box with autologin option 'S_DISPLAY_FULL_LOGIN' => true, //Old phpBB2 Backend Contant - 'IS_ADMIN' => $admin, - + 'IS_ADMIN' => $admin, + + //phpBB3 Backend Contant + 'S_ADMIN_AUTH' => $admin, + // These theme variables are not used for MX-Publisher, since MX-Publisher require a theme.css file 'T_HEAD_STYLESHEET' => isset($mx_user->theme['head_stylesheet']) ? $mx_user->theme['head_stylesheet'] : 'stylesheet.css', 'T_BODY_BACKGROUND' => isset($mx_user->theme['body_background']) ? $mx_user->theme['body_background'] : '', @@ -286,17 +1152,15 @@ 'T_SPAN_CLASS2' => isset($mx_user->theme['span_class2']) ? $mx_user->theme['span_class2'] : '', 'T_SPAN_CLASS3' => isset($mx_user->theme['span_class3']) ? $mx_user->theme['span_class3'] : '', - //+ MX-Publisher - 'U_PORTAL_ROOT_PATH' => PORTAL_URL, - 'U_PHPBB_ROOT_PATH' => PHPBB_URL, - 'TEMPLATE_ROOT_PATH' => TEMPLATE_ROOT_PATH, - 'L_HOME' => $lang['MX_home'], + //'L_HOME' => $lang['Home Page'], + //'L_FORUM' => $lang['Forum'], 'L_FORUM' => $lang['MX_forum'], 'U_INDEX_FORUM' => mx_append_sid(PORTAL_URL . 'index.' . $phpEx . '?page=2'), 'U_INDEX' => mx_append_sid(PORTAL_URL . 'index.' . $phpEx), 'U_SEARCH_SITE' => mx_append_sid(PORTAL_URL . 'index.' . $phpEx . '?page=' . $search_page_id_site . '&mode=results&search_terms=all'), + 'U_SEARCH_KB' => mx_append_sid(PORTAL_URL . 'index.' . $phpEx . '?page=' . $search_page_id_kb . '&mode=search&search_terms=all'), 'U_SEARCH_PAFILEDB' => mx_append_sid(PORTAL_URL . 'index.' . $phpEx . '?page=' . $search_page_id_pafiledb . '&action=search&search_terms=all'), @@ -307,23 +1171,32 @@ 'L_SEARCH_PAFILEDB' => $option_search_pafiledb, 'L_SEARCH_GOOGLE' => $option_search_google, - 'T_PHPBB_STYLESHEET' => $mx_user->theme['head_stylesheet'], - 'T_STYLESHEET_LINK' => (!isset($mx_user->theme['theme_storedb'])) ? "{$phpbb_root_path}styles/" . $mx_user->template_name . '/theme/stylesheet.css' : "{$phpbb_root_path}style.$phpEx?sid=$mx_user->session_id&id=" . $mx_user->theme['style_id'] . '&lang=' . $mx_user->encode_lang($board_config['default_lang']), - 'T_MXBB_STYLESHEET' => isset($mx_user->theme['head_stylesheet']) ? $mx_user->theme['head_stylesheet'] : $mx_user->template_name.'.css', + 'T_PHPBB_STYLESHEET' => (isset($mx_user->theme['head_stylesheet']) ? $mx_user->theme['head_stylesheet'] : $mx_user->template_name . ".css"), + 'T_STYLESHEET_LINK' => (!file_exists($mx_root_path . "templates/" . $mx_user->template_name . "/theme/stylesheet.css") ? "{$web_path}templates/" . $mx_user->template_name . '/'.$mx_user->template_name.'.css' : "{$web_path}templates/" . $mx_user->template_name . '/theme/stylesheet.css'), //: "{$phpbb_root_path}style.$phpEx?sid=$mx_user->session_id&id=" . $mx_user->theme['style_id'] . '&lang=' . $mx_user->encode_lang($board_config['default_lang']), + 'T_MXBB_STYLESHEET' => isset($mx_user->theme['head_stylesheet']) ? (strpos($mx_user->theme['head_stylesheet'], '.') ? $mx_user->theme['head_stylesheet'] : $mx_user->theme['head_stylesheet'].'.css') : $mx_user->template_name.'.css', 'T_GECKO_STYLESHEET' => 'gecko.css', - + + //+ MX-Publisher 'MX_ADDITIONAL_CSS_FILES' => $mx_addional_css_files, 'MX_ADDITIONAL_JS_FILES' => $mx_addional_js_files, 'MX_ADDITIONAL_HEADER_TEXT' => $mx_addional_header_text, 'MX_ICON_CSS' => isset($images['mx_graphics']['icon_style']) ? $images['mx_graphics']['icon_style'] : '', //- MX-Publisher - + + 'U_MX_SHARED_FILES_PATH' => "{$web_path}modules/mx_shared/", + + 'T_STYLESWITCHER_JS' => (!file_exists($mx_root_path . "modules/mx_shared/phpbb/styleswitcher.js") ? "{$web_path}templates/" . $mx_user->template_name . '/styleswitcher.js' : "{$web_path}modules/mx_shared/phpbb/styleswitcher.js"), + 'T_FORUM_FN_JS' => (!file_exists($mx_root_path . "modules/mx_shared/phpbb/forum_fn.js") ? "{$web_path}templates/" . $mx_user->template_name . '/forum_fn.js' : "{$web_path}modules/mx_shared/phpbb/forum_fn.js"), + 'T_EDITOR_JS' => (!file_exists($mx_root_path . "modules/mx_shared/phpbb/editor.js") ? "{$web_path}templates/" . $mx_user->template_name . '/editor.js' : "{$web_path}modules/mx_shared/phpbb/editor.js"), + 'T_AJAX_JS' => (!file_exists($mx_root_path . "modules/mx_shared/phpbb/ajax.js") ? "{$web_path}templates/" . $mx_user->template_name . '/ajax.js' : "{$web_path}modules/mx_shared/phpbb/ajax.js"), + 'T_TIMEZONE_JS' => (!file_exists($mx_root_path . "modules/mx_shared/phpbb/timezone.js") ? "{$web_path}templates/" . $mx_user->template_name . '/timezone.js' : "{$web_path}modules/mx_shared/phpbb/timezone.js"), + 'NAV_LINKS' => $nav_links_html, // swithes for logged in users? - 'USERNAME' => ($admin) ? $userdata['username'] : '', - 'USER_LOGGED_IN' => $userdata['session_logged_in'], - 'USER_LOGGED_OUT' => !$userdata['session_logged_in'], + 'USERNAME' => ($admin) ? $mx_user->data['username'] : '', + 'USER_LOGGED_IN' => $mx_user->data['session_logged_in'], + 'USER_LOGGED_OUT' => !$mx_user->data['session_logged_in'], //This phpBB3 features are disbled for Admins in MXP3 for now and default vaues used //To make use of this features Admins can login direct in forums @@ -338,40 +1211,58 @@ // Additional css for gecko browsers 'GECKO' => strstr($useragent, 'Gecko'), + + 'S_ENABLE_FEEDS' => false, + 'S_ENABLE_FEFILES_OVERALL' => false, + 'S_ENABLE_FEFILES_FORUMS' => false, + 'S_ENABLE_FEFILES_TOPICS' => false, + 'S_ENABLE_FEFILES_TOPICS_ACTIVE' => false, + 'S_ENABLE_FEFILES_NEWS' => false, + + 'L_ACP' => $lang['Admin_panel'], + 'U_ACP' => ($mx_user->data['user_level'] == ADMIN) ? "{$mx_root_path}admin/index.$phpEx?sid=" . $mx_user->session_id : $admin_link )); // Definitions of main navigation links $mx_backend->page_header('generate_nav_links'); +// // Navigation Menu in overall_header +// if ($mx_page->auth_view || $mx_page->auth_mod) { if (!is_object($mx_block)) { $mx_block = new mx_block(); } - + $block_id = $mx_page->page_navigation_block; if(!empty($block_id) ) { define('MX_OVERALL_NAVIGATION', true); - $mx_block->init( $block_id ); + $mx_block->init($block_id); + + // // Define $module_root_path, to be used within blocks $mx_module_path = $module_root_path; $module_root_path = $mx_root_path . $mx_block->module_root_path; - - $template = new mx_Template($mx_root_path . 'templates/'. $mx_user->theme['template_name']); - + + $template = new mx_Template($mx_root_path . 'templates/'. $theme['template_name']); + + // // Include block file and cache output + // ob_start(); @include($module_root_path . $mx_block->block_file); $overall_navigation_menu = ob_get_contents(); ob_end_clean(); - + + // // Output Block contents + // $layouttemplate->assign_vars(array( 'OVERALL_NAVIGATION' => $overall_navigation_menu) ); diff --git a/includes/page_tail.php b/includes/page_tail.php index 5a7fffaa..3981baec 100644 --- a/includes/page_tail.php +++ b/includes/page_tail.php @@ -40,6 +40,11 @@ )); } +if( !is_object($phpBB2)) +{ + $phpBB2 = new phpBB2(); +} + // // Page last updated (by) // @@ -47,11 +52,11 @@ { $editor_name_tmp = mx_get_userdata($mx_page->last_updated_by); $editor_name = $editor_name_tmp['username']; - $edit_time = phpBB2::create_date( $board_config['default_dateformat'], $mx_page->last_updated, $board_config['board_timezone'] ); + $edit_time = $phpBB2->create_date( $board_config['default_dateformat'], $mx_page->last_updated, $board_config['board_timezone'] ); $template->assign_block_vars('page_last_updated', array( 'L_PAGE_UPDATED' => isset($lang['Page_updated_date']) ? $lang['Page_updated_date'] : 'Page Updated', - 'NAME' => $userdata['user_level'] == ADMIN ? $lang['Page_updated_by'] . $editor_name : '', + 'NAME' => $mx_user->data['user_level'] == ADMIN ? $lang['Page_updated_by'] . ' ' . $editor_name : '', 'TIME' => $edit_time, )); } @@ -102,10 +107,16 @@ } } +if( !is_object($mx_backend)) +{ + $mx_backend = new mx_backend(); +} + $mx_backend->page_tail('generate_backend_version'); $template->assign_vars(array( 'U_PORTAL_ROOT_PATH' => PORTAL_URL, + 'U_PHPBB_ROOT_PATH' => PHPBB_URL, 'TEMPLATE_ROOT_PATH' => TEMPLATE_ROOT_PATH, 'MXBB_EXTRA' => $mxbb_footer_text, 'MXBB_EXTRA_URL' => $mxbb_footer_text_url, @@ -115,6 +126,12 @@ 'ADMIN_LINK' => ($userdata['user_level'] == ADMIN && $userdata['user_id'] != ANONYMOUS) ? '' . $l_acp . '
' : '', 'L_ACP' => ($userdata['user_level'] == ADMIN && $userdata['user_id'] != ANONYMOUS) ? $l_acp : '', 'U_ACP' => ($userdata['user_level'] == ADMIN && $userdata['user_id'] != ANONYMOUS) ? $u_acp : '', + 'U_CONTACT_US' => ($mx_user->data['user_last_privmsg']) ? mx_append_sid("{$phpbb_root_path}memberlist.$phpEx?mode=contactadmin") : '', + + 'U_TEAM' => ($mx_user->data['user_id'] != ANONYMOUS && (PORTAL_BACKEND !== 'internal') && $phpbb_auth->acl_get('u_viewprofile')) ? mx_append_sid("{$phpbb_root_path}memberlist.$phpEx?mode=team") : '', + 'U_TERMS_USE' => mx_append_sid("{$phpbb_root_path}profile.$phpEx?mode=terms"), + 'U_PRIVACY' => mx_append_sid("{$phpbb_root_path}profile.$phpEx?mode=privacy"), + 'MX_ADDITIONAL_FOOTER_TEXT' => $mx_addional_footer_text, 'EXECUTION_STATS' => (defined('DEBUG')) ? $debug_output : '' )); diff --git a/includes/sessions/ascraeus/core.php b/includes/sessions/ascraeus/core.php index 3ea67176..9cc9be15 100644 --- a/includes/sessions/ascraeus/core.php +++ b/includes/sessions/ascraeus/core.php @@ -194,7 +194,7 @@ function validate_backend() global $table_prefix, $phpEx, $tplEx; $table_prefix = false; - + $tplEx = 'html'; // Define relative path to phpBB, and validate $phpbb_root_path = $mx_root_path . $portal_config['portal_backend_path']; str_replace("//", "/", $phpbb_root_path); @@ -206,9 +206,6 @@ function validate_backend() die('Configuration file (config) ' . $phpbb_root_path . "config.$phpEx" . ' couldn\'t be opened.'); } - // Define backend template extension - $tplEx = 'html'; - // Validate db connection for backend $_result = $db->sql_query("SELECT config_value from " . $table_prefix . "config WHERE config_name = 'cookie_domain'"); $portal_backend_valid_db = $db->sql_numrows($_result) != 0; @@ -246,7 +243,10 @@ function setup_backend() $server_url_phpbb = $server_protocol . $server_name . $server_port . $script_name_phpbb; define('PHPBB_URL', $server_url_phpbb); - + + // Define backend template extension + $tplEx = 'html'; + if (!defined('TPL_EXT')) define('TPL_EXT', $tplEx); // // Now sync Configs // In phpBB mode, we rely on native phpBB configs, thus we need to sync mxp and phpbb settings @@ -707,34 +707,32 @@ function page_tail($mode = false) } } + /** - * Enter description here... + * obtain_phpbb_config * * @access public * @param boolean $use_cache * @return unknown */ - function obtain_phpbb_config($use_cache = true) + public function obtain_forum_config() { - global $db, $phpbb_root_path, $table_prefix, $mx_cache, $phpEx; - - if (($config = $mx_cache->get('phpbb_config')) && ($use_cache) ) + global $db, $mx_cache, $phpEx; + + if (!defined('CONFIG_TABLE')) { - return $config; - } - else - { - if (!defined('CONFIG_TABLE')) - { - global $table_prefix, $mx_root_path; + global $table_prefix, $mx_root_path; - require $mx_root_path. "includes/sessions/phpbb3/constants.$phpEx"; - } - - $sql = "SELECT * - FROM " . CONFIG_TABLE; - - if ( !( $result = $db->sql_query( $sql ) ) ) + require $mx_root_path. "includes/sessions/phpbb2/constants.$phpEx"; + } + + if (($mx_cache->get('phpbb_config')) === false) + { + $config = $cached_config = array(); + + $sql = 'SELECT config_name, config_value, is_dynamic + FROM ' . CONFIG_TABLE; + if (!($result = $db->sql_query($sql))) { if (!function_exists('mx_message_die')) { @@ -745,26 +743,250 @@ function obtain_phpbb_config($use_cache = true) mx_message_die( GENERAL_ERROR, 'Couldnt query config information', '', __LINE__, __FILE__, $sql ); } } + + while ($row = $db->sql_fetchrow($result)) + { + if (!$row['is_dynamic']) + { + $cached_config[$row['config_name']] = $row['config_value']; + } + + $config[$row['config_name']] = $row['config_value']; + } + $db->sql_freeresult($result); + + $mx_cache->put('phpbb_config', $cached_config); + } + else + { + $sql = 'SELECT config_name, config_value + FROM ' . CONFIG_TABLE . ' + WHERE is_dynamic = 1'; + $result = $db->sql_query($sql); - while ( $row = $db->sql_fetchrow($result) ) + while ($row = $db->sql_fetchrow($result)) { $config[$row['config_name']] = $row['config_value']; } $db->sql_freeresult($result); + } + + return $config; + } + + /** + * Set phpbb config values + * + * @param unknown_type $config_name + * @param unknown_type $config_value + */ + public function set_forum_config($key, $new_value, $use_cache = false) + { + global $db, $mx_cache, $phpEx; + + if (!defined('CONFIG_TABLE')) + { + global $table_prefix, $mx_root_path; + + require $mx_root_path. "includes/sessions/phpbb2/constants.$phpEx"; + } + + // Read out config values + $config = $this->obtain_phpbb_config(); + $old_value = !isset($config[$key]) ? $config[$key] : false; + $use_cache = (($key == 'comments_pagination') || ($key == 'pagination')) ? true : false; + + $sql = 'UPDATE ' . CONFIG_TABLE . " + SET config_value = '" . $db->sql_escape($new_value) . "' + WHERE config_name = '" . $db->sql_escape($key) . "'"; + + if ($old_value !== false) + { + $sql .= " AND config_value = '" . $db->sql_escape($old_value) . "'"; + } + + $db->sql_query($sql); + + if (!$db->sql_affectedrows() && isset($config[$key])) + { + return false; + } + + if (!isset($config[$key])) + { + $sql = 'INSERT INTO ' . CONFIG_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'config_name' => $key, + 'config_value' => $new_value)), + 'is_dynamic' => ($use_cache) ? 0 : 1)); + $db->sql_query($sql); + } + + $config[$key] = $new_value; + + + if ($use_cache) + { + $mx_cache->destroy('config'); + $mx_cache->put('config', $config); + } + + return true; + } + + /** + * Get MX-Publisher config data + * + * @access public + * @return unknown + */ + public function obtain_portal_config($use_cache = true) + { + global $db, $mx_cache; + + if ( ($portal_config = $mx_cache->get('mx_config')) && ($use_cache) ) + { + return $portal_config; + } + else + { + $sql = "SELECT * + FROM " . PORTAL_TABLE . " + WHERE portal_id = '1'"; - if ($use_cache) + if ( !($result = $db->sql_query($sql)) ) + { + if (!function_exists('mx_message_die')) + { + die("Couldnt query portal configuration, Allso this hosting or server is using a cache optimizer not compatible with MX-Publisher or just lost connection to database wile query."); + } + else + { + mx_message_die( GENERAL_ERROR, 'Couldnt query portal configuration', '', __LINE__, __FILE__, $sql ); + } + } + $row = $db->sql_fetchrow($result); + foreach ($row as $config_name => $config_value) { - $mx_cache->put('phpbb_config', $config); + $portal_config[$config_name] = trim($config_value); } + $db->sql_freeresult($result); + $mx_cache->put('mx_config', $portal_config); - return ( $config ); + return ($portal_config); } } + + /** + * Set config value. Creates missing config entry. + * + */ + function set_portal_config($key, $new_value) + { + global $db, $mx_cache, $portal_config; + + // Read out config values + $portal_config = $this->obtain_portal_config(); + + $new[$key] = $new_value; + + $sql = "UPDATE " . PORTAL_TABLE . " SET " . $db->sql_build_array('UPDATE', utf8_normalize_nfc($new)); + + if( !($db->sql_query($sql)) ) + { + mx_message_die(GENERAL_ERROR, "Failed to update portal configuration ", "", __LINE__, __FILE__, $sql); + } + + if (!$db->sql_affectedrows() && !isset($portal_config[$key])) + { + $sql = 'INSERT INTO ' . PORTAL_TABLE . ' ' . $db->sql_build_array('INSERT', array( + $db->sql_escape($key) => $db->sql_escape($new_value))); + $db->sql_query($sql); + } + $portal_config[$key] = $new_value; + + $mx_cache->destroy('mx_config'); + } + + /** + * Get userdata + * + * Get Userdata, $mx_user can be username or user_id. If force_str is true, the username will be forced. + * Cached sql, since this function is used for every block. + * + * @param unknown_type $mx_user id or name + * @param boolean $force_str force clean_username + * @return array + */ + function get_userdata($mxuser, $force_str = false) + { + global $db, $phpBB2; + + if (!is_numeric($mxuser) || $force_str) + { + $mx_user = $phpBB2->phpbb_clean_username($mxuser); + } + else + { + $mx_user = intval($mxuser); + } + + $sql = "SELECT * + FROM " . USERS_TABLE . " + WHERE "; + $sql .= ((is_integer($mxuser)) ? "user_id = $mxuser" : "username = '" . str_replace("\'", "''", $mxuser) . "'" ) . " AND user_id <> " . ANONYMOUS; + if (!($result = $db->sql_query($sql, 120))) + { + if (!function_exists('mx_message_die')) + { + die("Tried obtaining data for a non-existent user. Function mx_backend->get_userdata()"); + } + else + { + mx_message_die(GENERAL_ERROR, 'Tried obtaining data for a non-existent user', '', __LINE__, __FILE__, $sql); + } + } + $return = ($row = $db->sql_fetchrow($result)) ? $row : false; + /* + foreach ($row as $user_key => $user_value) + { + $userdata[$user_key] = trim($user_value); + } + */ + $db->sql_freeresult($result); + //return ($userdata); + return $return; + } + + /** + * Set user data value. + * + */ + function set_userdata($key, $new_value) + { + global $db, $mx_user; + + $new[$key] = $new_value; + + $sql = "UPDATE " . USERS_TABLE . " + SET " . $db->sql_build_array('UPDATE', utf8_normalize_nfc($new)) . " + WHERE user_id = '" . $mx_user->data['user_id'] . "'"; + if (!($db->sql_query($sql))) + { + mx_message_die(GENERAL_ERROR, "Failed to update portal configuration ", "", __LINE__, __FILE__, $sql); + } + + if (!$db->sql_affectedrows() && !isset($mx_user->data[$key])) + { + mx_message_die(GENERAL_ERROR, "Wrong Backend? Adding missing entry key to update MXP configuration is not supported ATM.", "", __LINE__, __FILE__, $sql); + } + $mx_user->data[$key] = $new_value; + } + /** * Obtain ranks */ - function obtain_ranks() + public function obtain_ranks() { global $mx_cache; @@ -803,7 +1025,7 @@ function obtain_ranks() return $ranks; } - + /** * Obtain allowed extensions * diff --git a/includes/sessions/ascraeus/functions.php b/includes/sessions/ascraeus/functions.php index 62fe4a4e..ef8c96cb 100644 --- a/includes/sessions/ascraeus/functions.php +++ b/includes/sessions/ascraeus/functions.php @@ -237,6 +237,7 @@ function mx_get_username_string($mode, $user_id, $username, $username_colour = ' switch ($mode) { + case 'profile_url': case 'profile': return $profile_url; break; diff --git a/includes/sessions/internal/bbcode.php b/includes/sessions/internal/bbcode.php index 34511311..0caa6c60 100644 --- a/includes/sessions/internal/bbcode.php +++ b/includes/sessions/internal/bbcode.php @@ -2,7 +2,7 @@ /** * * @package Functions_phpBB -* @version $Id: bbcode.php,v 1.4 2014/05/09 07:52:03 orynider Exp $ +* @version $Id: bbcode.php,v 1.5 2013/09/04 04:32:35 orynider Exp $ * @copyright (c) 2002-2008 MX-Publisher Project Team * @license http://opensource.org/licenses/gpl-license.php GNU General Public License v2 * @link http://mxpcms.sourceforge.net/ @@ -20,7 +20,9 @@ */ // Now load some bbcodes, to be extended for this backend (see below) -require($mx_root_path . 'includes/mx_functions_bbcode.' . $phpEx); // BBCode associated functions +// +include_once($mx_root_path . 'includes/mx_functions_bbcode.' . $phpEx); // BBCode associated functions + /** * MXP BBcodes @@ -58,7 +60,7 @@ class mx_bbcode extends bbcode_base */ function mx_bbcode($bitfield = '') { - global $board_config, $phpbb_root_path; + global $board_config, $mx_root_path, $phpbb_root_path; if ($bitfield) { @@ -66,9 +68,9 @@ function mx_bbcode($bitfield = '') $this->bbcode_cache_init(); } - $this->smiley_path_url = PHPBB_URL; //change this to PORTAL_URL when shared folder will be removed - $this->smiley_root_path = $phpbb_root_path; //same here - $board_config['smilies_path'] = str_replace("smiles", "smilies", $board_config['smilies_path']); //Added by OryNider + $this->smiley_path_url = PORTAL_URL . 'includes/shared/phpbb2/'; //change this to PORTAL_URL when shared folder will be removed + $this->smiley_root_path = $mx_root_path . 'includes/shared/phpbb2/'; //same here + $board_config['smilies_path'] = str_replace("smilies", "smiles", $board_config['smilies_path']); //Added by OryNider $this->smilies_path = str_replace("//", "/", $board_config['smilies_path']); } @@ -82,21 +84,47 @@ function mx_bbcode($bitfield = '') * @param boolean $smilies_on * @return string */ - function decode($bbtext, $bbcode_uid, $smilies_on = true) + function decode($mytext, $bbcode_uid, $smilies_on = true, $bbcode_bitfield = false) { global $mx_root_path, $phpbb_root_path, $phpEx, $mx_page; - - $mytext = stripslashes($bbtext); + + if (!$mytext) + { + return ''; + } + + $mytext = mx_censor_text($mytext); + + //Do some checks + $phpbb3_text = $bbcode_bitfield ? true : false; + $bbcode_bitfield = ($bbcode_bitfield && (strlen($bbcode_bitfield) < 2)) ? false : $bbcode_bitfield; + if (!empty($bbcode_uid)) { - $mytext = $this->bbencode_second_pass($mytext, $bbcode_uid); + $mytext = $this->bbencode_second_pass($mytext, $bbcode_uid, $bbcode_bitfield); + } + + $mytext = str_replace(array("\n", "\r"), array('
', "\n"), $mytext); + $mytext = $this->bbcode_nl2br($mytext); + + //$mytext = smiley_text($mytext, !($flags & OPTION_FLAG_SMILIES)); + if ($smilies_on && $phpbb3_text) + { + $mytext = $this->smilies3_pass($mytext); } - if ($smilies_on) + else if ($smilies_on) { $mytext = $this->smilies_pass($mytext); } - $mytext = str_replace("\n", "\n
\n", $mytext); - return $this->make_clickable($mytext); + + //$mytext = str_replace("\n", "\n
\n", $mytext); + + if ($mytext != '') + { + $mytext = $this->make_clickable($mytext); + } + + return $mytext; } // @@ -105,8 +133,15 @@ function decode($bbtext, $bbcode_uid, $smilies_on = true) // function prepare_message($message, $html_on, $bbcode_on, $smile_on, $bbcode_uid = 0) { - global $board_config, $html_entities_match, $html_entities_replace; + global $board_config, $mx_bbcode, $mx_root_path, $phpEx, $html_entities_match, $html_entities_replace; + // + // Instantiate the mx_text class + // + include_once($mx_root_path . 'includes/mx_functions_tools.'.$phpEx); + $mx_text = new mx_text(); + $mx_text->init($html_on, $bbcode_on, $smile_on); + // // Clean up the message // @@ -129,7 +164,7 @@ function prepare_message($message, $html_on, $bbcode_on, $smile_on, $bbcode_uid foreach ($message_split as $part) { $tag = array(array_shift($matches[0]), array_shift($matches[1]), array_shift($matches[2])); - $message .= preg_replace($html_entities_match, $html_entities_replace, $part) . clean_html($tag); + $message .= preg_replace($html_entities_match, $html_entities_replace, $part) . $mx_text->clean_html($tag); } $message = addslashes($message); @@ -147,7 +182,703 @@ function prepare_message($message, $html_on, $bbcode_on, $smile_on, $bbcode_uid return $message; } + + /** + * Second pass bbcodes + */ + function bbcode_second_pass(&$message, $bbcode_uid = '', $bbcode_bitfield = false) + { + if ($bbcode_uid) + { + $this->bbcode_uid = $bbcode_uid; + } + + if ($bbcode_bitfield !== false) + { + //$this->bbcode_bitfield = $bbcode_bitfield; + + // Init those added with a new bbcode_bitfield (already stored codes will not get parsed again) + $this->bbcode_cache_init(); + } + + //We are called from a Core block or non phpBB3, this should never be riched only when function is called direct + if (!$this->bbcode_bitfield) + { + // Remove the uid from tags that have not been transformed into HTML + /** / + if ($this->bbcode_uid) + { + $message = str_replace(':' . $this->bbcode_uid, '', $message); + } + /**/ + return; + } + + $str = array('search' => array(), 'replace' => array()); + $preg = array('search' => array(), 'replace' => array()); + + $bitfield = new bitfield($this->bbcode_bitfield); + $bbcodes_set = $bitfield->get_all_set(); + + $undid_bbcode_specialchars = false; + foreach ($bbcodes_set as $bbcode_id) + { + if (!empty($this->bbcode_cache[$bbcode_id])) + { + foreach ($this->bbcode_cache[$bbcode_id] as $type => $array) + { + foreach ($array as $search => $replace) + { + ${$type}['search'][] = str_replace('$uid', $this->bbcode_uid, $search); + ${$type}['replace'][] = $replace; + } + + if (sizeof($str['search'])) + { + $message = str_replace($str['search'], $str['replace'], $message); + $str = array('search' => array(), 'replace' => array()); + } + + if (sizeof($preg['search'])) + { + // we need to turn the entities back into their original form to allow the + // search patterns to work properly + if (!$undid_bbcode_specialchars) + { + $message = str_replace(array(':', '.'), array(':', '.'), $message); + $undid_bbcode_specialchars = true; + } + + $message = preg_replace($preg['search'], $preg['replace'], $message); + $preg = array('search' => array(), 'replace' => array()); + } + } + } + } + + // Remove the uid from tags that have not been transformed into HTML + $message = str_replace(':' . $this->bbcode_uid, '', $message); + } + /** + * Return bbcode template + */ + function bbcode_tpl($tpl_name, $bbcode_id = -1, $skip_bitfield_check = false) + { + static $bbcode_hardtpl = array(); + if (empty($bbcode_hardtpl)) + { + global $mx_user; + + $bbcode_hardtpl = array( + 'b_open' => '', + 'b_close' => '', + 'i_open' => '', + 'i_close' => '', + 'ipaper_open' => '', + 'ipaper_close' => '', + 'u_open' => '', + 'u_close' => '', + 'img' => '', + 'size' => '$2', + 'color' => '$2', + 'email' => '$2' + ); + } + + if ($bbcode_id != -1 && !$skip_bitfield_check && !$this->template_bitfield->get($bbcode_id)) + { + return (isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false; + } + + if (empty($this->bbcode_template)) + { + if (($tpl = file_get_contents($this->template_filename)) === false) + { + trigger_error('Could not load bbcode template', E_USER_ERROR); + } + + // replace \ with \\ and then ' with \'. + $tpl = str_replace('\\', '\\\\', $tpl); + $tpl = str_replace("'", "\'", $tpl); + + // strip newlines and indent + $tpl = preg_replace("/\n[\n\r\s\t]*/", '', $tpl); + + // Turn template blocks into PHP assignment statements for the values of $bbcode_tpl.. + $this->bbcode_template = array(); + + $matches = preg_match_all('#(.*?)#', $tpl, $match); + + for ($i = 0; $i < $matches; $i++) + { + if (empty($match[1][$i])) + { + continue; + } + + $this->bbcode_template[$match[1][$i]] = $this->bbcode_tpl_replace($match[1][$i], $match[2][$i]); + } + } + + + return (isset($this->bbcode_template[$tpl_name])) ? $this->bbcode_template[$tpl_name] : ((isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false); + } + + /** + * Return bbcode template replacement + */ + function bbcode_tpl_replace($tpl_name, $tpl) + { + global $mx_user; + + static $replacements = array( + 'quote_username_open' => array('{USERNAME}' => '$1'), + 'color' => array('{COLOR}' => '$1', '{TEXT}' => '$2'), + 'size' => array('{SIZE}' => '$1', '{TEXT}' => '$2'), + 'img' => array('{URL}' => '$1'), + 'flash' => array('{WIDTH}' => '$1', '{HEIGHT}' => '$2', '{URL}' => '$3'), + 'scribd' => array('{WIDTH}' => '$1', '{HEIGHT}' => '$2', '{SCRIBDURL}' => '$3'), + 'youtube' => array('{YOUTUBEID}' => '$1', '{YOUTUBELINK}' => '$2', '{WIDTH}' => '$3', '{HEIGHT}' => '$4'), + 'ipaper' => array('{IPAPERID}' => '$1', '{IPAPERKEY}' => '$2', '{WIDTH}' => '$3', '{HEIGHT}' => '$4', '{IPAPERLINK}' => '$5'), + 'ipaper_open' => array('{IPAPERCODE}' => '$1'), + 'url' => array('{URL}' => '$1', '{DESCRIPTION}' => '$2'), + 'web' => array('{URL}' => '$1', '{DESCRIPTION}' => '$2'), + 'size' => array('{ID}' => '$1', '{TEXT}' => '$2'), + 'email' => array('{EMAIL}' => '$1', '{DESCRIPTION}' => '$2') + ); + + $tpl = preg_replace_callback('/{L_([A-Z0-9_]+)}/', function ($match) use ($mx_user) { + return (!empty($mx_user->lang[$match[1]])) ? $mx_user->lang($match[1]) : ucwords(strtolower(str_replace('_', ' ', $match[1]))); + }, $tpl); + + if (!empty($replacements[$tpl_name])) + { + $tpl = strtr($tpl, $replacements[$tpl_name]); + } + + return trim($tpl); + } + + + /** + * Init bbcode cache + * + * requires: $this->bbcode_bitfield + * sets: $this->bbcode_cache with bbcode templates needed for bbcode_bitfield + */ + function bbcode_cache_init() + { + global $mx_user, $mx_root_path; + + if (empty($this->template_filename)) + { + $this->template_bitfield = new bitfield(isset($mx_user->theme['bbcode_bitfield']) ? $mx_user->theme['bbcode_bitfield'] : 'kNg='); + + if (file_exists($mx_root_path . 'templates/' . $mx_user->template_name . '/template/bbcode.html')) + { + $this->template_filename = $mx_root_path . 'templates/' . $mx_user->template_name . '/template/bbcode.html'; + } + elseif (file_exists($mx_root_path . 'templates/' . $mx_user->template_name . '/template/bbcode.tpl')) + { + $this->template_filename = $mx_root_path . 'templates/' . $mx_user->template_name . '/template/bbcode.tpl'; + } + if (file_exists($mx_root_path . 'templates/' . $mx_user->template_name . '/bbcode.tpl')) + { + $this->template_filename = $mx_root_path . 'templates/' . $mx_user->template_name . '/bbcode.tpl'; + } + elseif (file_exists($mx_root_path . 'templates/' . $mx_user->template_name . '/bbcode.html')) + { + $this->template_filename = $mx_root_path . 'templates/' . $mx_user->template_name . '/bbcode.html'; + } + $this->template_filename2 = substr_count($this->template_filename, 'html') ? str_replace(".html", ".tpl", $this->template_filename) : str_replace(".tpl", ".html", $this->template_filename); + if (!@file_exists($this->template_filename)) + { + if (!@file_exists($this->template_filename2)) + { + global $template; + + $this->template_filename = $template->make_filename('bbcode.tpl', false); + $this->template_filename2 = $template->make_filename('bbcode.html', false); + //trigger_error('The file "' . $this->template_filename . '", and The file "' . $this->template_filename2 . '" are missing.', E_USER_ERROR); + } + else + { + $this->template_filename = $this->template_filename2; + } + } + } + + $bbcode_ids = $rowset = $sql = array(); + + $bitfield = new bitfield($this->bbcode_bitfield); + $bbcodes_set = $bitfield->get_all_set(); + + foreach ($bbcodes_set as $bbcode_id) + { + if (isset($this->bbcode_cache[$bbcode_id])) + { + // do not try to re-cache it if it's already in + continue; + } + $bbcode_ids[] = $bbcode_id; + + if ($bbcode_id > NUM_CORE_BBCODES) + { + $sql[] = $bbcode_id; + } + } + + if (sizeof($sql)) + { + global $db; + + $sql = 'SELECT * + FROM ' . BBCODES_TABLE . ' + WHERE ' . $db->sql_in_set('bbcode_id', $sql); + $result = $db->sql_query($sql, 3600); + + while ($row = $db->sql_fetchrow($result)) + { + // To circumvent replacing newlines with
for the generated html, + // we use carriage returns here. They are later changed back to newlines + $row['bbcode_tpl'] = str_replace("\n", "\r", $row['bbcode_tpl']); + $row['second_pass_replace'] = str_replace("\n", "\r", $row['second_pass_replace']); + + $rowset[$row['bbcode_id']] = $row; + } + $db->sql_freeresult($result); + } + + foreach ($bbcode_ids as $bbcode_id) + { + switch ($bbcode_id) + { + case 0: + $this->bbcode_cache[$bbcode_id] = array( + 'str' => array( + '[/quote:$uid]' => $this->bbcode_tpl('quote_close', $bbcode_id) + ), + 'preg' => array( + '#\[quote(?:="(.*?)")?:$uid\]((?!\[quote(?:=".*?")?:$uid\]).)?#ise' => "\$this->bbcode_second_pass_quote('\$1', '\$2')" + ) + ); + break; + + case 1: + $this->bbcode_cache[$bbcode_id] = array( + 'str' => array( + '[b:$uid]' => $this->bbcode_tpl('b_open', $bbcode_id), + '[/b:$uid]' => $this->bbcode_tpl('b_close', $bbcode_id), + ) + ); + break; + + case 2: + $this->bbcode_cache[$bbcode_id] = array( + 'str' => array( + '[i:$uid]' => $this->bbcode_tpl('i_open', $bbcode_id), + '[/i:$uid]' => $this->bbcode_tpl('i_close', $bbcode_id), + ) + ); + break; + + case 3: + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[url:$uid\]((.*?))\[/url:$uid\]#s' => $this->bbcode_tpl('url', $bbcode_id), + '#\[url=([^\[]+?):$uid\](.*?)\[/url:$uid\]#s' => $this->bbcode_tpl('url', $bbcode_id), + ) + ); + break; + + case 4: + if ($mx_user->optionget('viewimg')) + { + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[img:$uid\](.*?)\[/img:$uid\]#s' => $this->bbcode_tpl('img', $bbcode_id), + ) + ); + } + else + { + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[img:$uid\](.*?)\[/img:$uid\]#s' => str_replace('$2', '[ img ]', $this->bbcode_tpl('url', $bbcode_id, true)), + ) + ); + } + break; + + case 5: + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[size=([\-\+]?\d+):$uid\](.*?)\[/size:$uid\]#s' => $this->bbcode_tpl('size', $bbcode_id), + ) + ); + break; + + case 6: + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '!\[color=(#[0-9a-f]{6}|[a-z\-]+):$uid\](.*?)\[/color:$uid\]!is' => $this->bbcode_tpl('color', $bbcode_id), + ) + ); + break; + + case 7: + $this->bbcode_cache[$bbcode_id] = array( + 'str' => array( + '[u:$uid]' => $this->bbcode_tpl('u_open', $bbcode_id), + '[/u:$uid]' => $this->bbcode_tpl('u_close', $bbcode_id), + ) + ); + break; + + case 8: + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[code(?:=([a-z]+))?:$uid\](.*?)\[/code:$uid\]#ise' => "\$this->bbcode_second_pass_code('\$1', '\$2')", + ) + ); + break; + + case 9: + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#(\[\/?(list|\*):[mou]?:?$uid\])[\n]{1}#' => "\$1", + '#(\[list=([^\[]+):$uid\])[\n]{1}#' => "\$1", + '#\[list=([^\[]+):$uid\]#e' => "\$this->bbcode_list('\$1')", + ), + 'str' => array( + '[list:$uid]' => $this->bbcode_tpl('ulist_open_default', $bbcode_id), + '[/list:u:$uid]' => $this->bbcode_tpl('ulist_close', $bbcode_id), + '[/list:o:$uid]' => $this->bbcode_tpl('olist_close', $bbcode_id), + '[*:$uid]' => $this->bbcode_tpl('listitem', $bbcode_id), + '[/*:$uid]' => $this->bbcode_tpl('listitem_close', $bbcode_id), + '[/*:m:$uid]' => $this->bbcode_tpl('listitem_close', $bbcode_id) + ), + ); + break; + + case 10: + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[email:$uid\]((.*?))\[/email:$uid\]#is' => $this->bbcode_tpl('email', $bbcode_id), + '#\[email=([^\[]+):$uid\](.*?)\[/email:$uid\]#is' => $this->bbcode_tpl('email', $bbcode_id) + ) + ); + break; + + case 11: + if ($mx_user->optionget('viewflash')) + { + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#' => $this->bbcode_tpl('flash', $bbcode_id), + ) + ); + } + else + { + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#' => str_replace('$1', '$3', str_replace('$2', '[ flash ]', $this->bbcode_tpl('url', $bbcode_id, true))) + ) + ); + } + break; + + case 12: + $this->bbcode_cache[$bbcode_id] = array( + 'str' => array( + '[/attachment:$uid]' => $this->bbcode_tpl('inline_attachment_close', $bbcode_id) + ), + 'preg' => array( + '#\[attachment=([0-9]+):$uid\]#' => $this->bbcode_tpl('inline_attachment_open', $bbcode_id) + ) + ); + break; + + + default: + if (isset($rowset[$bbcode_id])) + { + if ($this->template_bitfield->get($bbcode_id)) + { + // The bbcode requires a custom template to be loaded + if (!$bbcode_tpl = $this->bbcode_tpl($rowset[$bbcode_id]['bbcode_tag'], $bbcode_id)) + { + // For some reason, the required template seems not to be available, use the default template + $bbcode_tpl = (!empty($rowset[$bbcode_id]['second_pass_replace'])) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl']; + } + else + { + // In order to use templates with custom bbcodes we need + // to replace all {VARS} to corresponding backreferences + // Note that backreferences are numbered from bbcode_match + if (preg_match_all('/\{(URL|LOCAL_URL|WEB|IPAPERLINK|EMAIL|TEXT|SIMPLETEXT|IDENTIFIER|COLOR|NUMBER)[0-9]*\}/', $rowset[$bbcode_id]['bbcode_match'], $m)) + { + foreach ($m[0] as $i => $tok) + { + $bbcode_tpl = str_replace($tok, '$' . ($i + 1), $bbcode_tpl); + } + } + } + } + else + { + // Default template + $bbcode_tpl = ($rowset[$bbcode_id]['second_pass_replace']) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl']; + } + + // Replace {L_*} lang strings + $bbcode_tpl = preg_replace('/{L_([A-Z_]+)}/e', "(!empty(\$mx_user->lang['\$1'])) ? \$mx_user->lang['\$1'] : ucwords(strtolower(str_replace('_', ' ', '\$1')))", $bbcode_tpl); + + if (!empty($rowset[$bbcode_id]['second_pass_replace'])) + { + // The custom BBCode requires second-pass pattern replacements + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl) + ); + } + else + { + $this->bbcode_cache[$bbcode_id] = array( + 'str' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl) + ); + } + } + else + { + $this->bbcode_cache[$bbcode_id] = false; + } + break; + } + } + } + + /** + * Does second-pass bbencoding. This should be used before displaying the message in + * a thread. Assumes the message is already first-pass encoded, and we are given the + * correct UID as used in first-pass encoding. + * This a temporary function + */ + function bbencode_second_pass($text, $uid = '', $bitfield = false) + { + global $lang, $bbcode_tpl; + + if ($uid) + { + $this->bbcode_uid = $uid; + } + + if ($bitfield !== false) + { + $this->bbcode_bitfield = $bitfield; + + // Init those added with a new bbcode_bitfield (already stored codes will not get parsed again) + $this->bbcode_cache_init(); + } + + //Check if it's a phpBB3 block + if ($bitfield) + { + $this->bbcode_second_pass($text, $uid, $bitfield); + } + + //$text = str_replace(array("\n", "\r"), array('
', "\n"), $text); + $text = str_replace(array("\n", "\r"), array('
', ""), $text); + $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text); + + // pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0). + // This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it. + $text = " " . $text; + + // First: If there isn't a "[" and a "]" in the message, don't bother. + if (! (strpos($text, "[") && strpos($text, "]")) ) + { + // Remove padding, return. + $text = substr($text, 1); + return $text; + } + + // Only load the templates ONCE.. + if (!defined("BBCODE_TPL_READY")) + { + // load templates from file into array. + $bbcode_tpl = $this->load_bbcode_template(); + + // prepare array for use in regexps. + $bbcode_tpl = $this->prepare_bbcode_template($bbcode_tpl); + } + + // [CODE] and [/CODE] for posting code (HTML, PHP, C etc etc) in your posts. + $text = $this->bbencode_second_pass_code($text, $uid, $bbcode_tpl); + + // [IPAPER] and [/IPAPER] for posting iPaper in your posts. + $text = $this->bbencode_ipaper_pass_render($text, $uid, $bbcode_tpl); + + // [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff. + $text = str_replace("[quote:$uid]", $bbcode_tpl['quote_open'], $text); + $text = str_replace("[/quote:$uid]", $bbcode_tpl['quote_close'], $text); + + // New one liner to deal with opening quotes with usernames... + // replaces the two line version that I had here before.. + $text = preg_replace("/\[quote:$uid=\"(.*?)\"\]/si", $bbcode_tpl['quote_username_open'], $text); + + // [list] and [list=x] for (un)ordered lists. + // unordered lists + $text = str_replace("[list:$uid]", $bbcode_tpl['ulist_open'], $text); + // li tags + $text = str_replace("[*:$uid]", $bbcode_tpl['listitem'], $text); + // ending tags + $text = str_replace("[/list:u:$uid]", $bbcode_tpl['ulist_close'], $text); + $text = str_replace("[/list:o:$uid]", $bbcode_tpl['olist_close'], $text); + // Ordered lists + $text = preg_replace("/\[list=([a1]):$uid\]/si", $bbcode_tpl['olist_open'], $text); + + // colours + $text = preg_replace("/\[color=(\#[0-9A-F]{6}|[a-z]+):$uid\]/si", $bbcode_tpl['color_open'], $text); + $text = str_replace("[/color:$uid]", $bbcode_tpl['color_close'], $text); + + // size + $text = preg_replace("/\[size=([1-2]?[0-9]):$uid\]/si", $bbcode_tpl['size_open'], $text); + $text = str_replace("[/size:$uid]", $bbcode_tpl['size_close'], $text); + + // [b] and [/b] for bolding text. + $text = str_replace("[b:$uid]", $bbcode_tpl['b_open'], $text); + $text = str_replace("[/b:$uid]", $bbcode_tpl['b_close'], $text); + + // [u] and [/u] for underlining text. + $text = str_replace("[u:$uid]", $bbcode_tpl['u_open'], $text); + $text = str_replace("[/u:$uid]", $bbcode_tpl['u_close'], $text); + + // [i] and [/i] for italicizing text. + $text = str_replace("[i:$uid]", $bbcode_tpl['i_open'], $text); + $text = str_replace("[/i:$uid]", $bbcode_tpl['i_close'], $text); + + //$text = str_replace('url:' . $uid, 'url', $text); + + // Patterns and replacements for URL and email tags.. + $patterns = array(); + $replacements = array(); + + // [img]image_url_here[/img] code.. + // This one gets first-passed.. + $patterns[] = "#\[img:$uid\]([^?](?:[^\[]+|\[(?!url))*?)\[/img:$uid\]#i"; + $replacements[] = $bbcode_tpl['img']; + // matches a [url]xxxx://www.phpbb.com[/url] code.. + $patterns[] = "#\[url\]([\w]+?://([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is"; + $replacements[] = $bbcode_tpl['url1']; + + // [url]www.phpbb.com[/url] code.. (no xxxx:// prefix). + $patterns[] = "#\[url\]((www|ftp)\.([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is"; + $replacements[] = $bbcode_tpl['url2']; + + // [url=xxxx://www.phpbb.com]phpBB[/url] code.. + $patterns[] = "#\[url=([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is"; + $replacements[] = $bbcode_tpl['url3']; + + // [url=www.phpbb.com]phpBB[/url] code.. (no xxxx:// prefix). + $patterns[] = "#\[url=((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is"; + $replacements[] = $bbcode_tpl['url4']; + + // [email]user@domain.tld[/email] code.. + $patterns[] = "#\[email\]([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si"; + $replacements[] = $bbcode_tpl['email']; + + //Strat more bbcode + $text = preg_replace($patterns, $replacements, $text); + // align + $text = preg_replace("/\[align=(left|right|center|justify):$uid\]/si", $bbcode_tpl['align_open'], $text); + $text = str_replace("[/align:$uid]", $bbcode_tpl['align_close'], $text); + // marquee + $text = preg_replace("/\[marq=(left|right|up|down):$uid\]/si", $bbcode_tpl['marq_open'], $text); + $text = str_replace("[/marq:$uid]", $bbcode_tpl['marq_close'], $text); + // table + $text = preg_replace("/\[table=(.*?):$uid\]/si", $bbcode_tpl['table_open'], $text); + $text = str_replace("[/table:$uid]", $bbcode_tpl['table_close'], $text); + // cell + $text = preg_replace("/\[cell=(.*?):$uid\]/si", $bbcode_tpl['cell_open'], $text); + $text = str_replace("[/cell:$uid]", $bbcode_tpl['cell_close'], $text); + // center + $text = preg_replace("/\[center:$uid\]/si", $bbcode_tpl['center_open'], $text); + $text = str_replace("[/center:$uid]", $bbcode_tpl['center_close'], $text); + // font + $text = preg_replace("/\[font=(.*?):$uid\]/si", $bbcode_tpl['font_open'], $text); + $text = str_replace("[/font:$uid]", $bbcode_tpl['font_close'], $text); + // poet + $text = preg_replace("/\[poet(.*?):$uid\]/si", $bbcode_tpl['poet_open'], $text); + $text = str_replace("[/poet:$uid]", $bbcode_tpl['poet_close'], $text); + //[hr] + $text = str_replace("[hr:$uid]", $bbcode_tpl['hr'], $text); + // bbcode_box Mod + // [fade] and [/fade] for faded text. + $text = str_replace("[fade:$uid]", $bbcode_tpl['fade_open'], $text); + $text = str_replace("[/fade:$uid]", $bbcode_tpl['fade_close'], $text); + // real + $patterns[] = "#\[ram:$uid\](.*?)\[/ram:$uid\]#si"; + $replacements[] = $bbcode_tpl['ram']; + // [stream]Sound URL[/stream] code.. + $patterns[] = "#\[stream:$uid\](.*?)\[/stream:$uid\]#si"; + $replacements[] = $bbcode_tpl['stream']; + //web + $patterns[] = "#\[web:$uid\](.*?)\[/web:$uid\]#si"; + $replacements[] = $bbcode_tpl['web']; + // [flash width= height= loop= ] and [/flash] code.. + $patterns[] = "#\[flash width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-9]?[0-9]):$uid\](.*?)\[/flash:$uid\]#si"; + $replacements[] = $bbcode_tpl['flash']; + // [flash width= height= loop= ] and [/flash] code.. + $patterns[10] = "#\[video width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-9]?[0-9]):$uid\](.*?)\[/video:$uid\]#si"; + $replacements[10] = $bbcode_tpl['video']; + + // [flash width=X height=X]Flash URL[/flash] code.. + $patterns[] = "#\[flash width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-9]?[0-9]):$uid\](.*?)\[/flash:$uid\]#si"; + $replacements[] = $bbcode_tpl['flash']; + + // [video width=X height=X]Video URL[/video] code.. + $patterns[] = "#\[video width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-9]?[0-9]):$uid\](.*?)\[/video:$uid\]#si"; + $replacements[] = $bbcode_tpl['video']; + + // [GVideo]GVideo URL[/GVideo] code.. + $patterns[] = "#\[GVideo\]http://video.google.[A-Za-z0-9.]{2,5}/videoplay\?docid=([0-9A-Za-z-_]*)[^[]*\[/GVideo\]#is"; + $replacements[] = $bbcode_tpl['GVideo']; + + // [youtube]www.youtube.com[/youtube] + $patterns[] = "#\[youtube\]http://(?:www\.)?youtube.com/watch\?v=([0-9A-Za-z-_]{11})[^[]*\[/youtube\]#is"; + $replacements[] = $bbcode_tpl['youtube']; + + // [youtube=xxxx://www.youtube.com]Youtube[/youtube] code.. + //$patterns[] = "#\[youtube=http://(?:www\.)?youtube.com/watch\?v=([0-9A-Za-z-_]{11})]([^?\n\r\t].*?)\[/youtube\]#is"; + //$replacements[] = $bbcode_tpl['youtube']; + + // [scribd]Scribd URL[/scribd] code.. + $patterns[] = "#\[scribd\]http://(?:d\.)?scribd.com/ScribdViewer.swf\?document_id=([0-9A-Za-z-_]*)[^[]*\[/scribd\]#is"; + $replacements[] = $bbcode_tpl['scribd']; + + // [scribd]Scribd URL[/scribd] code.. + $patterns[] = "#\[scribd id=([0-9A-Za-z-_]{8}) key=([0-9A-Za-z-_]{24})\](.*?)\[/scribd\]#is"; + $replacements[] = $bbcode_tpl['scribd']; + + // [ipaper]Scribd URL[/ipaper] code.. + $patterns[] = "#\[ipaper\]http://(?:d\.)?scribd.com/ScribdViewer.swf\?document_id=([0-9A-Za-z-_]*)\&access_key=([0-9A-Za-z-_]*)[^[]*\[/ipaper\]#is"; + $replacements[] = $bbcode_tpl['ipaper']; + + //Stop more bbcode + $text = preg_replace($patterns, $replacements, $text); + + // Remove the uid from tags that have not been transformed into HTML + $text = str_replace(':' . $uid, '', $text); + + // Remove our padding from the string.. + $text = substr($text, 1); + + return $text; + + } // bbencode_second_pass() + /** * phpBB Smilies pass. * @@ -175,19 +906,19 @@ function smilies_pass($message) $smilies = $db->sql_fetchrowset($result); - if (count($smilies)) + if ($count = count($smilies)) { @usort($smilies, 'smiley_sort'); } - for ($i = 0; $i < count($smilies); $i++) + for ($i = 0; $i < $count; $i++) { $orig[] = "/(?<=.\W|\W.|^\W)" . preg_quote($smilies[$i]['code'], "/") . "(?=.\W|\W.|\W$)/"; $repl[] = ''; } } - if (count($orig)) + if ($corig = count($orig)) { $message = preg_replace($orig, $repl, ' ' . $message . ' '); $message = substr($message, 1, -1); @@ -196,6 +927,27 @@ function smilies_pass($message) return $message; } + /** + * phpBB Smilies pass. + * + * Hacking smilies_pass from phpbb/includes/bbcode.php + * + * NOTE: This is only kept for reference - not used. + * + * @param string $message + * @return string + */ + function mx_smilies_pass_old($message) + { + global $mx_page, $board_config, $phpbb_root_path, $phpEx; + + $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; + } + /** * Generate smilies. * @@ -267,7 +1019,7 @@ function generate_smilies($mode, $forum_id) $template->assign_block_vars('smilies_row.smilies_col', array( 'SMILEY_CODE' => $data['code'], 'SMILEY_IMG' => $this->smiley_path_url . $board_config['smilies_path'] . '/' . $smile_url, - 'SMILEY_DESC' => $data['emoticon']) + 'SMILEY_DESC' => isset($data['emoticon']) ? $data['emoticon'] : $row['emoticon']) ); $s_colspan = max($s_colspan, $col + 1); diff --git a/includes/sessions/internal/constants.php b/includes/sessions/internal/constants.php index 4431f8f9..75eaf39d 100644 --- a/includes/sessions/internal/constants.php +++ b/includes/sessions/internal/constants.php @@ -26,6 +26,11 @@ @define('ADMIN', 1); @define('MOD', 2); +@define('USER_NORMAL', 0); +@define('USER_INACTIVE', 1); +@define('USER_IGNORE', 2); +@define('USER_FOUNDER', 3); + // User related @define('USER_ACTIVATION_NONE', 0); @define('USER_ACTIVATION_SELF', 1); diff --git a/includes/sessions/internal/core.php b/includes/sessions/internal/core.php index f0733449..a5954746 100644 --- a/includes/sessions/internal/core.php +++ b/includes/sessions/internal/core.php @@ -2,7 +2,7 @@ /** * * @package Auth -* @version $Id: core.php,v 1.20 2014/07/07 20:36:53 orynider Exp $ +* @version $Id: core.php,v 1.29 2014/05/16 18:02:23 orynider Exp $ * @copyright (c) 2002-2008 MX-Publisher Project Team * @license http://opensource.org/licenses/gpl-license.php GNU General Public License v2 * @link http://mxpcms.sourceforge.net/ @@ -19,13 +19,26 @@ // Note: These functions will later be accessible wrapped as phpBBX::orig_functionname() // include_once($mx_root_path . 'includes/shared/phpbb2/includes/functions.' . $phpEx); -include_once($mx_root_path . 'includes/shared/phpbb3/includes/functions.' . $phpEx); + + +// +// Finally, load some backend specific functions // -// Instantiate Dummy phpBB Classes +include_once($mx_root_path . 'includes/sessions/internal/functions.' . $phpEx); + +// +// Load here Backend Permissions if this is required // -$phpBB2 = new phpBB2(); -$phpBB3 = new phpBB3(); + +// +// Init the auth class if this is required +// + +// +// Instantiate Dummy Forum Specific Shared Classes +// Moved in common.php + /** * Backend specific tasks @@ -34,14 +47,34 @@ */ class mx_backend { + // // XS Template - use backend db settings + // var $edit_db = false; - + var $page_id = 1; + var $user_ip = 'ffffff'; + + /***/ + function mx_backend() + { + // Obtain and encode users IP + // from MXP 2.7.x common + // I'm removing HTTP_X_FORWARDED_FOR ... this may well cause other problems such as + // private range IP's appearing instead of the guilty routable IP, tough, don't + // even bother complaining ... go scream and shout at the idiots out there who feel + // "clever" is doing harm rather than good ... karma is a great thing ... :) + // + $this->client_ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ( ( !empty($_ENV['REMOTE_ADDR']) ) ? $_ENV['REMOTE_ADDR'] : getenv('REMOTE_ADDR') ); + $ip_sep = explode('.', $this->client_ip); + $this->user_ip = sprintf('%02x%02x%02x%02x', $ip_sep[0], $ip_sep[1], $ip_sep[2], $ip_sep[3]); + } + /***/ + /** * Validate backend * * Define Users/Group/Sessions backend, and validate - * Set $phpbb_root_path, $tplEx, $table_prefix + * Set i.e. $phpbb_root_path, $tplEx, $table_prefix * */ function validate_backend() @@ -49,19 +82,23 @@ function validate_backend() global $db, $portal_config, $phpbb_root_path, $mx_root_path; global $table_prefix, $phpEx, $tplEx; - // Define relative path to "phpBB", and validate + // + // Define backend template extension + // + $tplEx = 'tpl'; + + // + // Define relative path to phpBB, and validate + // $phpbb_root_path = $mx_root_path . 'includes/shared/phpbb2/'; str_replace("//", "/", $phpbb_root_path); $portal_backend_valid_file = @file_exists($phpbb_root_path . "includes/functions.$phpEx"); - - // Define backend template extension - $tplEx = 'tpl'; - + return $portal_backend_valid_file; } /** - * setup_backend + * $mx_backend->setup_backend() * * Define some general backend definitions * PORTAL_URL, PHPBB_URL, PORTAL_VERSION & $board_config @@ -69,29 +106,107 @@ function validate_backend() */ function setup_backend() { - global $portal_config, $board_config, $phpbb_root_path, $phpEx; - + global $mx_cache, $portal_config, $board_config, $mx_root_path, $phpbb_root_path, $phpEx, $db; + $script_name = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($portal_config['script_path'])); $server_name = trim($portal_config['server_name']); - $server_protocol = ( $portal_config['cookie_secure'] ) ? 'https://' : 'http://'; + $server_protocol = ( $portal_config['cookie_secure'] ) ? 'http://' : 'http://'; $server_port = (($portal_config['server_port']) && ($portal_config['server_port'] <> 80)) ? ':' . trim($portal_config['server_port']) . '/' : '/'; - + $portal_config['portal_phpbb_url'] = str_replace("//", "/", $server_name . $server_port . $script_name . '/'); $server_url = $server_protocol . str_replace("//", "/", $server_name . $server_port . $script_name . '/'); //On some server the slash is not added and this trick will fix it - define('PORTAL_URL', $server_url); + // + // Grab phpBB global variables, re-cache if necessary + // - optional parameter to enable/disable cache for config data. If enabled, remember to refresh the MX-Publisher cache whenever updating phpBB config settings + // - true: enable cache, false: disable cache + if (empty($board_config['script_path'])) + { + $board_config = $mx_cache->obtain_mxbb_config(false); + } + + if (empty($portal_config['portal_version'])) + { + $portal_config = $mx_cache->obtain_mxbb_config(false); + } + /** + $this->data = !empty($this->data['user_id']) ? $this->data : $mx_user->session_pagestart($user_ip, $page_id); + + $this->cache = is_object($mx_cache) ? $mx_cache : new base(); + */ + if (preg_match('/bot|crawl|curl|dataprovider|search|get|spider|find|java|majesticsEO|google|yahoo|teoma|contaxe|yandex|libwww-perl|facebookexternalhit/i', $_SERVER['HTTP_USER_AGENT'])) + { + $this->data['is_bot'] = true; + } + else + { + $this->data['is_bot'] = false; + } + + // + // Populate session_id + // + //$this->session_id = $this->data['session_id']; + $this->lang_path = $phpbb_root_path . 'language/'; + + $script_name = !empty($board_config['server_name']) ? preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($board_config['server_name'])) : 'localhost'; + $server_protocol = ( $board_config['cookie_secure'] ) ? 'http://' : 'http://'; + $server_port = (($board_config['server_port']) && ($board_config['server_port'] <> 80)) ? ':' . trim($portal_config['server_port']) . '/' : '/'; + $script_name_phpbb = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($board_config['script_path'])) . '/'; + + if (!empty($portal_config['portal_url'])) + { + $corrected_url = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($portal_config['portal_url'])) . '/'; + } + else + { + $corrected_url = str_replace(array('phpBB/', $script_name_phpbb, str_replace('./../', '', $phpbb_root_path)), '', $portal_config['portal_phpbb_url'] . '/'); + $corrected_url = (empty($portal_config['portal_phpbb_url']) || preg_match('@^(?:phpbb.com)?([^/]+)@i', $portal_config['portal_phpbb_url'])) ? $server_protocol . str_replace("//", "/", $server_name . $server_port . $script_name . '/') : str_replace(array('http://', 'http://'), $server_protocol, $server_url) ; //On some server the slash is not added and this trick will fix it + } + + $board_url = $server_url; + define('PORTAL_VERSION', $portal_config['portal_version']); - - $board_config = array(); - $script_name_phpbb = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim('includes/shared/phpbb2/')) . '/'; - - $server_url_phpbb = $server_protocol . $server_name . $server_port . $script_name_phpbb; + + $server_url_phpbb = $server_protocol . (isset($server_name) ? $server_name : $script_name) . $server_port . $script_name_phpbb; + + if (empty($portal_config['portal_phpbb_url']) || preg_match('@^(?:phpbb.com)?([^/]+)@i', $portal_config['portal_phpbb_url'])) + { + $portal_config['portal_phpbb_url'] = !empty($portal_config['portal_url']) ? $server_url . $script_name_phpbb : $server_url_phpbb; + } + + $server_url_phpbb = !empty($portal_config['portal_phpbb_url']) ? $server_url . $script_name_phpbb : $server_url_phpbb; + $server_url_phpbb = (empty($portal_config['portal_phpbb_url']) || preg_match('@^(?:phpbb.com)?([^/]+)@i', $portal_config['portal_phpbb_url'])) ? $server_url_phpbb : $portal_config['portal_phpbb_url']; + define('PHPBB_URL', $server_url_phpbb); - - /* - * Now sync Configs - * In phpBB mode, we rely on native phpBB configs, thus we need to sync mxp and phpbb settings - */ + define('PORTAL_URL', $board_url); + define('BOARD_URL', $server_url); + + $web_path = (isset($portal_config['portal_url'])) ? $board_url : $corrected_url; + + // + // Define backend template extension + // + $tplEx = 'tpl'; + if (!defined('TPL_EXT')) define('TPL_EXT', $tplEx); + + // + // Now sync Configs + // In phpBB mode, we rely on native phpBB configs, thus we need to sync mxp and phpbb settings + // $this->sync_configs(); + + // + // Dummy include, to make all original phpBB functions available + // In case we need old functions... + include_once($mx_root_path . 'includes/shared/phpbb2/includes/functions.' . $phpEx); + include_once($mx_root_path . 'includes/shared/phpbb3/includes/functions.' . $phpEx); + // + // Is phpBB File Attachment MOD present? + // + if( file_exists($phpbb_root_path . 'attach_mod') ) + { + include_once($phpbb_root_path . 'attach_mod/attachment_mod.' . $phpEx); + } } /** @@ -120,12 +235,18 @@ function sync_configs() case 'max_login_attempts': case 'login_reset_time': + $do = false; + break; + // // Keep phpBB stats // case 'record_online_users': case 'record_online_date': + $do = false; + break; + // // Keep portal settings // @@ -214,25 +335,286 @@ function load_file($force_shared) { global $mx_root_path, $phpbb_root_path, $phpEx; - $backend = in_array($force_shared, array('internal', 'phpbb2', 'smf2', 'mybb', 'phpbb3', 'olympus', 'ascraeus', 'rhea')) ? $force_shared : PORTAL_BACKEND; + if ($force_shared) + { + $shared = in_array($force_shared, array('internal', 'phpbb2', 'phpbb3')) ? $force_shared : PORTAL_BACKEND; + + switch ($shared) + { + case 'internal': + case 'phpbb2': + $path = $mx_root_path . 'includes/shared/phpbb2/includes/'; + break; + case 'phpbb3': + default: + $path = $mx_root_path . 'includes/shared/phpbb3/includes/'; + break; + } + } + else + { + $path = $phpbb_root_path . 'includes/'; + } + + return $path; + } + + /** + * get_phpbb_info + * + * @param unknown_type $root_path + * @access private + */ + function get_mxp_info($root_path, $backend = 'internal', $phpbbversion = '2.0.24') + { + $phpEx = substr(strrchr(__FILE__, '.'), 1); + + if (strpos($root_path, '.') !== false) + { + // Nested file + $filename_ext = substr(strrchr($root_path, '.'), 1); + $filename = basename($root_path, '.' . $filename_ext); + $current_dir = dirname(realpath($root_path)); + $root_path = dirname($root_path); + } + else + { + $filename_ext = substr(strrchr(__FILE__, '.'), 1); + $filename = "config"; + $current_dir = $root_path; + $root_path = dirname($root_path); + } + + $config = $root_path . "/config.$phpEx"; + + // + if ((@include $config) === false) + { + die('Configuration file ' . $config . ' couldn\'t be opened.'); + } + // + + // Check the prefix length to ensure that index names are not too long and does not contain invalid characters switch ($backend) { case 'internal': + // no break; case 'phpbb2': - case 'smf2': - case 'mybb': - $path = $mx_root_path . 'includes/shared/phpbb2/includes/'; + $phpbb_adm_relative_path = 'admin'; break; + case 'phpbb3': - case 'olympus': + case 'olympus': + $phpbb_adm_relative_path = 'adm'; + break; + case 'ascraeus': case 'rhea': - $path = $mx_root_path . 'includes/shared/phpbb3/includes/'; - break; + case 'proteus': + $phpbb_adm_relative_path = (isset($phpbb_adm_relative_path)) ? $phpbb_adm_relative_path : 'adm/'; + $dbms = get_keys_sufix($dbms); + $acm_type = get_keys_sufix($acm_type); + break; } - return $path; + + // If we are on PHP < 5.0.0 we need to force include or we get a blank page + if (version_compare(PHP_VERSION, '5.0.0', '<')) + { + $dbms = str_replace('mysqli', 'mysql4', $dbms); //this version of php does not have mysqli extension and my crash the installer if finds a forum using this + } + + return array( + 'dbms' => $dbms, + 'dbhost' => $dbhost, + 'dbname' => $dbname, + 'dbuser' => $dbuser, + 'dbpasswd' => $dbpasswd, + 'mx_table_prefix' => $mx_table_prefix, + 'table_prefix' => $table_prefix, + 'backend' => $backend, + 'version' => $phpbbversion, + 'acm_type' => isset($acm_type) ? $acm_type : '', + 'phpbb_root_path' => $phpbb_root_path, + 'status' => defined('MX_INSTALLED') ? true : false, + ); + } + + /** + * get_phpbb_info + * + * @param unknown_type $root_path + * @access private + */ + function get_phpbb_info($root_path, $backend = 'phpbb2', $phpbbversion = '2.0.24') + { + $phpEx = substr(strrchr(__FILE__, '.'), 1); + + if (strpos($root_path, '.') !== false) + { + // Nested file + $filename_ext = substr(strrchr($root_path, '.'), 1); + $filename = basename($root_path, '.' . $filename_ext); + $current_dir = dirname(realpath($root_path)); + $root_path = dirname($root_path); + } + else + { + $filename_ext = substr(strrchr(__FILE__, '.'), 1); + $filename = "config"; + $current_dir = $root_path; + $root_path = dirname($root_path); + } + + $config = $root_path . "/config.$phpEx"; + + // + if ((@include $config) === false) + { + die('Configuration file ' . $config . ' couldn\'t be opened.'); + } + // + + if ((@include $root_path . "language/en/install.$phpEx") !== false) + { + $left_piece1 = explode('. You', $lang['CONVERT_COMPLETE_EXPLAIN']); + $left_piece2 = explode('phpBB', $left_piece1[0]); + $phpbbversion = strrchr($left_piece2[1], ' '); + + switch (true) + { + case (preg_match('/3.0/i', $phpbbversion)): + $backend = 'olympus'; + break; + case (preg_match('/3.1/i', $phpbbversion)): + $backend = 'ascraeus'; + break; + case (preg_match('/3.2/i', $phpbbversion)): + $backend = 'rhea'; + break; + case (preg_match('/3.3/i', $phpbbversion)): + $backend = 'proteus'; + break; + case (preg_match('/4./i', $phpbbversion)): + $backend = 'phpbb4'; + break; + } + } + + // Check the prefix length to ensure that index names are not too long and does not contain invalid characters + switch ($backend) + { + case 'internal': + // no break; + case 'phpbb2': + $phpbb_adm_relative_path = 'admin'; + break; + + case 'phpbb3': + case 'olympus': + $phpbb_adm_relative_path = 'adm'; + break; + + case 'ascraeus': + case 'rhea': + case 'proteus': + $phpbb_adm_relative_path = (isset($phpbb_adm_relative_path)) ? $phpbb_adm_relative_path : 'adm/'; + $dbms = get_keys_sufix($dbms); + $acm_type = get_keys_sufix($acm_type); + break; + } + + // If we are on PHP < 5.0.0 we need to force include or we get a blank page + if (version_compare(PHP_VERSION, '5.0.0', '<')) + { + $dbms = str_replace('mysqli', 'mysql4', $dbms); //this version of php does not have mysqli extension and my crash the installer if finds a forum using this + } + + return array( + 'dbms' => $dbms, + 'dbhost' => $dbhost, + 'dbname' => $dbname, + 'dbuser' => $dbuser, + 'dbpasswd' => $dbpasswd, + 'table_prefix' => $table_prefix, + 'backend' => $backend, + 'version' => $phpbbversion, + 'acm_type' => isset($acm_type) ? $acm_type : '', + 'status' => defined('PHPBB_INSTALLED') ? true : false, + ); } - + + /** + * get_smf_info + * + * @param unknown_type $settings + * @access private + * / + function get_smf_info($settings) + { + if ((@include $settings) === false) + { + install_die(GENERAL_ERROR, 'Configuration file ' . $settings . ' couldn\'t be opened.'); + } + // If we are on PHP < 5.0.0 we need to force include or we get a blank page + if (version_compare(PHP_VERSION, '5.0.0', '<')) + { + $db_type = str_replace('mysqli', 'mysql4', $db_type); //this version of php does not have mysqli extension and my crash the installer if finds a forum using this + } + // If the UTF-8 setting was enabled, add it to the table definitions. + if ($db_character_set == 'utf8') + { + $db_type = str_replace('mysql', 'mysql4', $db_type); + } + return array( + 'dbms' => $db_type, // 'mysql' + 'dbhost' => $db_server, // 'localhost'; + 'dbname' => $db_name, // 'smf'; + 'dbuser' => $db_user, // 'root'; + 'dbpasswd' => $db_passwd, // ''; + 'ssi_dbuser' => $ssi_db_user, // ''; + 'ssi_dbpasswd' => $ssi_db_passwd, // ''; + 'table_prefix' => $db_prefix, // 'smf_'; + 'dbpersist' => $db_persist, // 0; + 'dberror_send' => $db_error_send, // 1; + 'dbcharacter_set' => $db_character_set, + 'acm_type' => '', + 'mtitle' => $mtitle, //# Title for the Maintenance Mode message. + 'status' => ($maintenance != 2) ? true : false, # Set to 1 to enable Maintenance Mode, 2 to make the forum untouchable. (you'll have to make it 0 again manually!) + 'mbname' => $mbname, # The name of your forum. + 'language' => $language, // 'english'; # The default language file set for the forum. + 'boardurl' => $boardurl, // 'http://127.0.0.1/smf'; # URL to your forum's folder. (without the trailing /!) + 'webmaster_email' => $webmaster_email, // 'noreply@myserver.com'; # Email address to send emails from. (like noreply@yourdomain.com.) + 'cookiename' => $cookiename, + ); + } + + /** + * get_mybb_info + * + * @param unknown_type $mybb_config + * @access private + * / + function get_mybb_info($mybb_config) + { + $config = array(); + if ((@include $mybb_config) === false) + { + install_die(GENERAL_ERROR, 'Configuration file ' . $mybb_config . ' couldn\'t be opened.'); + } + return array( + 'dbms' => $config['database']['type'], // 'mysqli'; + 'dbname' => $config['database']['database'], // 'mybb'; + 'table_prefix' => $config['database']['table_prefix'], // 'mybb_'; + + 'dbhost' => $config['database']['hostname'], // 'localhost'; + 'dbname' => $config['database']['username'], // 'Admin'; + 'dbpasswd' => $config['database']['password'], + + 'admin_dir' => $config['admin_dir'], + 'dbcharacter_set' => $config['database']['encoding'], + ); + } + /** * dss_rand * @@ -241,31 +623,135 @@ function load_file($force_shared) */ function dss_rand() { - global $db, $portal_config, $board_config, $lang, $dss_seeded; - + global $db, $portal_config, $board_config, $dss_seeded; + $val = $portal_config['rand_seed'] . microtime(); $val = md5($val); $portal_config['rand_seed'] = md5($portal_config['rand_seed'] . $val . 'a'); + if($dss_seeded !== true) { $sql = "UPDATE " . PORTAL_TABLE . " SET rand_seed = '" . $portal_config['rand_seed'] . "' WHERE portal_id = '1'"; - //display an error debuging message only if the portal is installed/upgraded - if(!@$db->sql_query($sql) && @!file_exists('install')) + + if( !$db->sql_query($sql) ) { mx_message_die(GENERAL_ERROR, "Unable to reseed PRNG", "", __LINE__, __FILE__, $sql); } - elseif(!@$db->sql_query($sql) && @file_exists('install')) - { - mx_message_die(GENERAL_ERROR, "Unable to reseed PRNG"."
Please finish upgrading and
". t(isset($lang['Please_remove_install_contrib'])), "", __LINE__, __FILE__, $sql); - } - + $dss_seeded = true; } + return substr($val, 4, 16); } + function make_jumpbox($action, $match_forum_id = 0) + { + global $template, $userdata, $lang, $db, $nav_links, $phpEx, $SID; + + // $is_auth = auth(AUTH_VIEW, AUTH_LIST_ALL, $userdata); + + $sql = "SELECT c.cat_id, c.cat_title, c.cat_order + FROM " . CATEGORIES_TABLE . " c, " . FORUMS_TABLE . " f + WHERE f.cat_id = c.cat_id + GROUP BY c.cat_id, c.cat_title, c.cat_order + ORDER BY c.cat_order"; + if ( !($result = $db->sql_query($sql)) ) + { + mx_message_die(GENERAL_ERROR, "Couldn't obtain category list.", "", __LINE__, __FILE__, $sql); + } + + $category_rows = array(); + while ( $row = $db->sql_fetchrow($result) ) + { + $category_rows[] = $row; + } + + if ( $total_categories = count($category_rows) ) + { + $sql = "SELECT * + FROM " . FORUMS_TABLE . " + ORDER BY cat_id, forum_order"; + if ( !($result = $db->sql_query($sql)) ) + { + mx_message_die(GENERAL_ERROR, 'Could not obtain forums information', '', __LINE__, __FILE__, $sql); + } + + $boxstring = ''; + } + else + { + $boxstring .= ''; + } + + // Let the jumpbox work again in sites having additional session id checks. + // if ( !empty($SID) ) + // { + $boxstring .= ''; + // } + + $template->set_filenames(array( + 'jumpbox' => 'jumpbox.tpl') + ); + $template->assign_vars(array( + 'L_GO' => $lang['Go'], + 'L_JUMP_TO' => $lang['Jump_to'], + 'L_SELECT_FORUM' => $lang['Select_forum'], + + 'S_JUMPBOX_SELECT' => $boxstring, + 'S_JUMPBOX_ACTION' => mx_append_sid($action)) + ); + $template->assign_var_from_handle('JUMPBOX', 'jumpbox'); + + return; + } + /** * Backend specific Page Header data * @@ -274,8 +760,19 @@ function dss_rand() function page_header($mode = false) { global $db, $mx_root_path, $phpbb_root_path, $userdata, $mx_user, $lang, $images, $phpEx; - global $board_config, $gen_simple_header, $layouttemplate, $mx_page; - + global $board_config, $gen_simple_header, $layouttemplate, $mx_page, $phpBB2; + + /**********/ + $layouttemplate = isset($layouttemplate) ? $layouttemplate : ""; + // If MX-Publisher frame template is not set, instantiate it + if (!is_object($layouttemplate)) + { + // + // Initialize template + // + $layouttemplate = new mx_Template( $mx_root_path . 'templates/'. $theme['template_name'], $board_config, $db ); + } + switch ($mode) { case 'generate_login_logout_stats': @@ -293,13 +790,15 @@ function page_header($mode = false) $l_login_logout = $lang['Login']; } - $s_last_visit = ( $userdata['session_logged_in'] ) ? phpBB2::create_date($board_config['default_dateformat'], $userdata['user_lastvisit'], $board_config['board_timezone']) : ''; - + $s_last_visit = ( $userdata['session_logged_in'] ) ? $phpBB2->create_date($board_config['default_dateformat'], $userdata['user_lastvisit'], $board_config['board_timezone']) : ''; + + // // Obtain number of new private messages // if user is logged in + // if ( ($userdata['session_logged_in']) && (empty($gen_simple_header)) ) { - if (isset($userdata['user_new_privmsg'])) + if ( $userdata['user_new_privmsg'] ) { $l_message_new = ( $userdata['user_new_privmsg'] == 1 ) ? $lang['New_pm'] : $lang['New_pms']; $l_privmsgs_text = sprintf($l_message_new, $userdata['user_new_privmsg']); @@ -333,7 +832,7 @@ function page_header($mode = false) $mx_priv_msg = $lang['Private_Messages']; } - if (isset($userdata['user_unread_privmsg'])) + if ( $userdata['user_unread_privmsg'] ) { $l_message_unread = ( $userdata['user_unread_privmsg'] == 1 ) ? $lang['Unread_pm'] : $lang['Unread_pms']; $l_privmsgs_text_unread = sprintf($l_message_unread, $userdata['user_unread_privmsg']); @@ -356,7 +855,6 @@ function page_header($mode = false) 'U_LOGIN_LOGOUT' => mx_append_sid(PORTAL_URL . $u_login_logout), 'L_LOGIN_LOGOUT' => $l_login_logout, 'LAST_VISIT_DATE' => sprintf($lang['You_last_visit'], $s_last_visit), - 'PRIVATE_MESSAGE_INFO' => $l_privmsgs_text, 'PRIVATE_MESSAGE_INFO_UNREAD' => $l_privmsgs_text_unread, 'PRIVATE_MESSAGE_NEW_FLAG' => $s_privmsg_new, @@ -364,23 +862,22 @@ function page_header($mode = false) 'L_PRIVATEMSGS' => $mx_priv_msg, // Backend - 'PHPBB' => false, + 'PHPBB' => true, // Show phpbb stats? - 'PHPBB_STATS' => false, + 'PHPBB_STATS' => $mx_page->phpbb_stats, // Allow autologin? - 'ALLOW_AUTOLOGIN' => false, + 'ALLOW_AUTOLOGIN' => !$userdata['session_logged_in'] && (!isset($board_config['allow_autologin']) || $board_config['allow_autologin']), // phpBB PM - 'ENABLE_PM_POPUP' => false, + 'ENABLE_PM_POPUP' => $userdata['session_logged_in'] && !empty($userdata['user_popup_pm']), )); break; case 'generate_nav_links': - /* $u_register = 'profile.'.$phpEx.'?mode=register' ; $u_profile = 'profile.'.$phpEx.'?mode=editprofile'; $u_privatemsgs = 'privmsg.'.$phpEx.'?folder=inbox'; @@ -406,7 +903,6 @@ function page_header($mode = false) 'U_GROUP_CP' => mx_append_sid(PHPBB_URL . $u_group_cp), 'U_SEND_PASSWORD' => $u_sendpassword, )); - */ break; } @@ -424,9 +920,11 @@ function page_tail($mode = false) switch ($mode) { case 'generate_backend_version': + $current_phpbb_version = '0.0.0'; $template->assign_vars(array( - 'PHPBB_BACKEND' => false, + 'PHPBB_BACKEND' => true, + 'PHPBB_VERSION' => ($userdata['user_level'] == ADMIN && $userdata['user_id'] != ANONYMOUS) ? $current_phpbb_version : '', 'U_PHPBB_ROOT_PATH' => PHPBB_URL, )); @@ -434,6 +932,191 @@ function page_tail($mode = false) } } + /** + * obtain_forum_config + * + * @access public + * @param boolean $use_cache + * @return unknown + */ + function obtain_forum_config($use_cache = true) + { + if ( ($config = $this->obtain_portal_config($use_cache)) ) + { + return $config; + } + } + + /** + * Set forum config values + * + * @param unknown_type $config_name + * @param unknown_type $config_value + */ + function set_forum_config($key, $new_value, $use_cache = false) + { + $this->set_portal_config($key, $new_value); + } + + /** + * Get MX-Publisher config data + * + * @access public + * @return unknown + */ + public function obtain_portal_config($use_cache = true) + { + global $db, $mx_cache; + + if ( ($portal_config = $mx_cache->get('mx_config')) && ($use_cache) ) + { + return $portal_config; + } + else + { + $sql = "SELECT * + FROM " . PORTAL_TABLE . " + WHERE portal_id = '1'"; + + if ( !($result = $db->sql_query($sql)) ) + { + if (!function_exists('mx_message_die')) + { + die("Couldnt query portal configuration, Allso this hosting or server is using a cache optimizer not compatible with MX-Publisher or just lost connection to database wile query."); + } + else + { + mx_message_die( GENERAL_ERROR, 'Couldnt query portal configuration', '', __LINE__, __FILE__, $sql ); + } + } + $row = $db->sql_fetchrow($result); + foreach ($row as $config_name => $config_value) + { + $portal_config[$config_name] = trim($config_value); + } + $db->sql_freeresult($result); + $mx_cache->put('mx_config', $portal_config); + + return ($portal_config); + } + } + + /** + * Set config value. Creates missing config entry. + * + */ + function set_portal_config($key, $new_value) + { + global $db, $mx_cache, $portal_config; + + // Read out config values + $portal_config = $this->obtain_portal_config(); + + $new[$key] = $new_value; + + $sql = "UPDATE " . PORTAL_TABLE . " SET " . $db->sql_build_array('UPDATE', utf8_normalize_nfc($new)); + + if( !($db->sql_query($sql)) ) + { + mx_message_die(GENERAL_ERROR, "Failed to update portal configuration ", "", __LINE__, __FILE__, $sql); + } + + if (!$db->sql_affectedrows() && !isset($portal_config[$key])) + { + $sql = 'INSERT INTO ' . PORTAL_TABLE . ' ' . $db->sql_build_array('INSERT', array( + $db->sql_escape($key) => $db->sql_escape($new_value))); + + //$after = (!empty($column_data['after'])) ? ' AFTER ' . $column_data['after'] : ''; + //$sql = 'ALTER TABLE `' . $table . '` ADD `' . $column_name . '` ' . (($column_data['column_type_sql'] = 'NULL') ? 'TEXT' : $column_data['column_type_sql']) . ' ' . (!empty($column_data[$column_name]) ? $column_data[$column_name] : 'NULL') . ' DEFAULT NULL' . $after; + + $db->sql_query($sql); + } + + $portal_config[$key] = $new_value; + + $mx_cache->destroy('mx_config'); + } + + /** + * Get userdata + * + * Get Userdata, $mx_user can be username or user_id. If force_str is true, the username will be forced. + * Cached sql, since this function is used for every block. + * + * @param unknown_type $mx_user id or name + * @param boolean $force_str force clean_username + * @return array + */ + function get_userdata($mxuser, $force_str = false) + { + global $db, $phpBB2; + + if (!is_numeric($mxuser) || $force_str) + { + $mx_user = $phpBB2->phpbb_clean_username($mxuser); + } + else + { + $mx_user = intval($mxuser); + } + + $sql = "SELECT * + FROM " . USERS_TABLE . " + WHERE "; + $sql .= ((is_integer($mxuser)) ? "user_id = $mxuser" : "username = '" . str_replace("\'", "''", $mxuser) . "'" ) . " AND user_id <> " . ANONYMOUS; + if (!($result = $db->sql_query($sql, 120))) + { + if (!function_exists('mx_message_die')) + { + die("Tried obtaining data for a non-existent user. Function mx_backend->get_userdata()"); + } + else + { + mx_message_die(GENERAL_ERROR, 'Tried obtaining data for a non-existent user', '', __LINE__, __FILE__, $sql); + } + } + $return = ($row = $db->sql_fetchrow($result)) ? $row : false; + /* + foreach ($row as $user_key => $user_value) + { + $userdata[$user_key] = trim($user_value); + } + */ + $db->sql_freeresult($result); + //return ($userdata); + return $return; + } + + /** + * Set user data value. + * + */ + function set_userdata($key, $new_value) + { + global $db, $mx_user; + + $new[$key] = $new_value; + + if (!isset($mx_user->data[$key]) || ($key == 'user_style')) + { + mx_message_die(GENERAL_ERROR, "Wrong Backend? Adding this entry $key key to update MXP configuration is not supported with this backend.", "", __LINE__, __FILE__, $sql); + } + + $sql = "UPDATE " . USERS_TABLE . " + SET " . $db->sql_build_array('UPDATE', utf8_normalize_nfc($new)) . " + WHERE user_id = '" . $mx_user->data['user_id'] . "'"; + if (!($db->sql_query($sql))) + { + mx_message_die(GENERAL_ERROR, "Failed to update user data value ", "", __LINE__, __FILE__, $sql); + } + + if (!$db->sql_affectedrows() && !isset($mx_user->data[$key])) + { + mx_message_die(GENERAL_ERROR, "Wrong Backend? Adding missing entry key to update MXP configuration is not supported ATM.", "", __LINE__, __FILE__, $sql); + } + $mx_user->data[$key] = $new_value; + } + /** * Enter description here... * @@ -479,8 +1162,8 @@ function obtain_phpbb_config($use_cache = true) return ( $config ); } - } - + } + /** * Enter description here... * @@ -531,7 +1214,9 @@ function generate_session_online_sql($guest = false) */ function decode_ip($str_ip) { - return phpBB2::decode_ip($str_ip); + global $phpBB2; + + return $phpBB2->decode_ip($str_ip); } /** @@ -541,7 +1226,9 @@ function decode_ip($str_ip) */ function get_phpbb_version() { - return ''; + global $board_config; + + return '0.0.0'; } /** @@ -570,11 +1257,12 @@ function confirm_backend() */ function get_username_string($mode, $user_id, $username = false, $user_color = false, $guest_username = false, $custom_profile_url = false) { - global $lang, $userdata; + global $lang, $mx_user, $userdata, $theme, $phpEx; $lang['Guest'] = !$guest_username ? $lang['Guest'] : $guest_username; $this_userdata = mx_get_userdata($user_id, false); + $username = ($username) ? $username : $this_userdata['username']; if ($this_userdata['user_level'] == ADMIN) @@ -590,12 +1278,20 @@ function get_username_string($mode, $user_id, $username = false, $user_color = f else { $user_colour = $theme['fontcolor1']; - $topic_poster_style = 'style="font-weight : bold;"'; + $user_style = 'style="font-weight : bold;"'; } - $profile_url = $username; - - $full_url = (($user_id == ANONYMOUS) || ($user_id == MUSIC_GUEST)) ? '' . $lang['Guest'] . '' : '' . $username . ''; + // Only show the link if not anonymous + if ($user_id && $user_id != ANONYMOUS) + { + $profile_url = mx3_append_sid(PHPBB_URL . "profile.$phpEx", 'mode=viewprofile&u=' . (int) $user_id); + $full_url = '' . $username . ''; + } + else + { + $profile_url = $lang['Guest']; + $full_url = $lang['Guest']; + } switch ($mode) { @@ -616,7 +1312,6 @@ function get_username_string($mode, $user_id, $username = false, $user_color = f return $full_url; break; } - return $username; } // @@ -645,11 +1340,10 @@ function load_forum_stats() * * @return unknown */ - function phpbb_version_check() + function phpbb_version_check($force_update = false, $warn_fail = false, $ttl = 86400) { return ''; } - } // diff --git a/includes/sessions/internal/functions.php b/includes/sessions/internal/functions.php new file mode 100644 index 00000000..481c635a --- /dev/null +++ b/includes/sessions/internal/functions.php @@ -0,0 +1,91 @@ +theme['fontcolor3']) ? $mx_user->theme['fontcolor3'] : $user_colour; + $user_style = 'style="color:#' . $user_colour . '; font-weight : bold;"'; + } + else if ($this_userdata['user_level'] == MOD) + { + $user_colour = ($mx_user->theme['fontcolor2']) ? $mx_user->theme['fontcolor2'] : $user_colour; + $user_style = 'style="color:#' . $user_colour . '; font-weight : bold;"'; + } + else + { + $user_colour = ($mx_user->theme['fontcolor1']) ? $mx_user->theme['fontcolor1'] : $user_colour; + $user_style = 'style="color:#' . $user_colour . '; font-weight : bold;"'; + } + // print_r(substr($user_colour, 0, 3) . substr($user_colour, 3, 2)); + // Only show the link if not anonymous + if ($user_id != ANONYMOUS) + { + $profile_url = mx_append_sid(PHPBB_URL . "profile.$phpEx?mode=viewprofile&u=" . (int) $user_id); + $full_url = '' . $username . ''; + } + else + { + $profile_url = $lang['Guest']; + $full_url = $lang['Guest']; + } + + switch ($mode) + { + case 'profile_url': + case 'profile': + return $profile_url; + break; + + case 'username': + return $username; + break; + + case 'colour': + return $user_colour; + break; + + case 'full': + case 'no_profile': + default: + return $full_url; + break; + } +} + +?> \ No newline at end of file diff --git a/includes/sessions/internal/login.php b/includes/sessions/internal/login.php index 74cb5cb9..2bd4ef6c 100644 --- a/includes/sessions/internal/login.php +++ b/includes/sessions/internal/login.php @@ -16,7 +16,7 @@ if ($mx_request_vars->is_request('login') && (!$userdata['session_logged_in'] || $mx_request_vars->is_post('admin')) ) { - $username = $mx_request_vars->is_post('username') ? phpBB2::phpbb_clean_username($mx_request_vars->post('username', MX_TYPE_NO_TAGS)) : ''; + $username = $mx_request_vars->is_post('username') ? $phpBB2->phpbb_clean_username($mx_request_vars->post('username', MX_TYPE_NO_TAGS)) : ''; $password = $mx_request_vars->post('password', MX_TYPE_NO_TAGS); $sql = "SELECT user_id, username, user_password, user_active, user_level, user_login_tries, user_last_login_try diff --git a/includes/sessions/internal/session.php b/includes/sessions/internal/session.php index 4bf4707d..cee7fd8d 100644 --- a/includes/sessions/internal/session.php +++ b/includes/sessions/internal/session.php @@ -2,7 +2,7 @@ /** * * @package Style -* @version $Id: session.php,v 1.22 2014/09/29 11:42:31 orynider Exp $ +* @version $Id: session.php,v 1.18 2014/05/09 07:52:03 orynider Exp $ * @copyright (c) 2002-2008 MX-Publisher Project Team & (C) 2001 The phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU General Public License v2 * @link http://mxpcms.sourceforge.net/ @@ -30,6 +30,8 @@ class session var $host = ''; var $session_id = ''; var $ip = ''; + var $page_id = ''; + var $user_ip = ''; var $load = 0; var $time_now = 0; var $update_session_page = true; @@ -45,7 +47,30 @@ class session var $lang_path; var $img_lang; var $img_array = array(); + + /** + * Load sessions + * @access public + * + */ + function session() + { + global $mx_cache, $board_config, $db, $phpbb_root_path, $mx_root_path, $phpEx; + + $this->cache = $mx_cache; + $this->config = $board_config; + $this->db = $db; + $this->user = $this; + $this->service_providers = array('user_id' => 1, 'session_id' => 0, 'provider' => '', 'oauth_token' => ''); + $this->phpbb_root_path = $phpbb_root_path; + $this->mx_root_path = $mx_root_path; + $this->php_ext = $phpEx; + + + $this->lang_path = $mx_root_path . 'language/'; + } + /** * Load sessions * @access public @@ -53,16 +78,80 @@ class session */ function load() { - global $portal_config; + if (!isset($this->user_ip)) + { + global $user_ip; + + $this->user_ip = $user_ip; + } + + if (!isset($this->page_id)) + { + global $mx_request_vars; - $this->data = $this->session_pagestart($this->user_ip, - (MX_PORTAL_PAGES_OFFSET + $this->page_id)); + $this->page_id = $mx_request_vars->request('page', MX_TYPE_INT, 1); + } + + if (!isset($this->config)) + { + global $board_config; - // Simulate the user lang setting - $this->data['user_lang'] = $portal_config['default_lang']; - $this->data['user_dateformat'] = $portal_config['default_dateformat']; - $this->data['user_timezone'] = $portal_config['board_timezone']; - $this->data['user_dst'] = 1; + $this->config = $board_config; + } + + if (!isset($this->mx_root_path)) + { + global $mx_root_path; + + $this->mx_root_path = $mx_root_path; + } + + if (!isset($this->phpbb_root_path)) + { + global $phpbb_root_path; + + $this->phpbb_root_path = $phpbb_root_path; + } + + if (!isset($this->cache)) + { + global $mx_cache; + $this->cache = $mx_cache; + + if (!isset($this->cache)) + { + $this->cache= new mx_cache(); + } + } + + // + // Populate user data + // + $this->data = $this->session_pagestart($this->user_ip, - ( MX_PORTAL_PAGES_OFFSET + $this->page_id )); + + if (preg_match('/bot|crawl|curl|dataprovider|search|get|spider|find|java|majesticsEO|google|yahoo|teoma|contaxe|yandex|libwww-perl|facebookexternalhit/i', $_SERVER['HTTP_USER_AGENT'])) + { + $this->data['is_bot'] = true; + } + else + { + $this->data['is_bot'] = false; + } + $this->data['user_perm_from'] = ''; + $this->data['user_topic_sortby_type'] = 't'; + $this->data['user_topic_sortby_dir'] = 'd'; + $this->data['user_topic_show_days'] = 0; + $this->data['user_last_privmsg'] = 0; + $this->data['user_post_sortby_type'] = 't'; + $this->data['user_post_sortby_dir'] = 'a'; + $this->data['user_post_show_days'] = 0; + $this->data['user_new_privmsg'] = 0; + $this->data['user_unread_privmsg'] = 0; + $this->data['user_form_salt'] = bin2hex(random_bytes(8)); + $this->data['user_avatar'] = 'includes/shared/phpbb2/images/user_avatar.png'; + $this->data['user_avatar_type'] = 2; + // // Populate session_id $this->session_id = $this->data['session_id']; } @@ -90,7 +179,7 @@ function session_begin($user_id, $user_ip, $page_id, $auto_create = 0, $enable_a else { $sessiondata = array(); - $session_id = $mx_request_vars->get('sid', MX_TYPE_NO_TAGS); + $session_id = $mx_request_vars->is_get('sid',MX_TYPE_NO_TAGS); $sessionmethod = SESSION_METHOD_GET; } @@ -104,7 +193,7 @@ function session_begin($user_id, $user_ip, $page_id, $auto_create = 0, $enable_a $last_visit = 0; $current_time = time(); - + // // Are auto-logins allowed? // If allow_autologin is not set or is true then they are @@ -114,23 +203,25 @@ function session_begin($user_id, $user_ip, $page_id, $auto_create = 0, $enable_a { $enable_autologin = $sessiondata['autologinid'] = false; } - + // // First off attempt to join with the autologin value if we have one // If not, just use the user_id value // $userdata = array(); - + if ($user_id != ANONYMOUS) { if (isset($sessiondata['autologinid']) && (string) $sessiondata['autologinid'] != '' && $user_id) { - $sql = 'SELECT u.* - FROM ' . USERS_TABLE . ' u, ' . SESSIONS_KEYS_TABLE . ' k + $sql = 'SELECT u.*, u.user_id as user_colour, u.user_level as user_type, p.default_lang as user_lang, p.board_timezone as user_timezone + FROM ' . USERS_TABLE . ' u, ' . SESSIONS_KEYS_TABLE . ' k, ' . PORTAL_TABLE . ' p WHERE u.user_id = ' . (int) $user_id . " AND u.user_active = 1 AND k.user_id = u.user_id - AND k.key_id = '" . md5($sessiondata['autologinid']) . "'"; + AND k.key_id = '" . md5($sessiondata['autologinid']) . "' + AND p.portal_id = '1'"; + if (!($result = $db->sql_query($sql))) { mx_message_die(CRITICAL_ERROR, 'Error doing DB query userdata row fetch', '', __LINE__, __FILE__, $sql); @@ -145,11 +236,13 @@ function session_begin($user_id, $user_ip, $page_id, $auto_create = 0, $enable_a { $sessiondata['autologinid'] = ''; $sessiondata['userid'] = $user_id; - - $sql = 'SELECT * - FROM ' . USERS_TABLE . ' - WHERE user_id = ' . (int) $user_id . ' - AND user_active = 1'; + + $sql = 'SELECT u.*, u.user_id as user_colour, u.user_level as user_type, p.default_lang as user_lang, p.board_timezone as user_timezone + FROM ' . USERS_TABLE . ' u, ' . PORTAL_TABLE . ' p + WHERE u.user_id = ' . (int) $user_id . ' + AND u.user_active = 1 + AND p.portal_id = 1'; + if (!($result = $db->sql_query($sql))) { mx_message_die(CRITICAL_ERROR, 'Error doing DB query userdata row fetch', '', __LINE__, __FILE__, $sql); @@ -161,7 +254,11 @@ function session_begin($user_id, $user_ip, $page_id, $auto_create = 0, $enable_a $login = 1; } } - + elseif ($mx_request_vars->is_request('login')) + { + die('Invalid user_id to login: '.ANONYMOUS); + } + // // At this point either $userdata should be populated or // one of the below is true @@ -174,10 +271,11 @@ function session_begin($user_id, $user_ip, $page_id, $auto_create = 0, $enable_a $sessiondata['autologinid'] = ''; $sessiondata['userid'] = $user_id = ANONYMOUS; $enable_autologin = $login = 0; - - $sql = 'SELECT * - FROM ' . USERS_TABLE . ' - WHERE user_id = ' . (int) $user_id; + + $sql = 'SELECT u.*, u.user_id as user_colour, u.user_level as user_type, p.default_lang as user_lang, p.board_timezone as user_timezone + FROM ' . USERS_TABLE . ' u, ' . SESSIONS_KEYS_TABLE . ' k, ' . PORTAL_TABLE . ' p + WHERE u.user_id = ' . (int) $user_id . ' + AND p.portal_id = 1'; if (!($result = $db->sql_query($sql))) { mx_message_die(CRITICAL_ERROR, 'Error doing DB query userdata row fetch', '', __LINE__, __FILE__, $sql); @@ -187,36 +285,13 @@ function session_begin($user_id, $user_ip, $page_id, $auto_create = 0, $enable_a $db->sql_freeresult($result); } - - // - // Initial ban check against user id, IP and email address - // /* - preg_match('/(..)(..)(..)(..)/', $user_ip, $user_ip_parts); - - $sql = "SELECT ban_ip, ban_userid, ban_email - FROM " . BANLIST_TABLE . " - WHERE ban_ip IN ('" . $user_ip_parts[1] . $user_ip_parts[2] . $user_ip_parts[3] . $user_ip_parts[4] . "', '" . $user_ip_parts[1] . $user_ip_parts[2] . $user_ip_parts[3] . "ff', '" . $user_ip_parts[1] . $user_ip_parts[2] . "ffff', '" . $user_ip_parts[1] . "ffffff') - OR ban_userid = $user_id"; - if ( $user_id != ANONYMOUS ) - { - $sql .= " OR ban_email LIKE '" . str_replace("\'", "''", $userdata['user_email']) . "' - OR ban_email LIKE '" . substr(str_replace("\'", "''", $userdata['user_email']), strpos(str_replace("\'", "''", $userdata['user_email']), "@")) . "'"; - } - if ( !($result = $db->sql_query($sql)) ) - { - mx_message_die(CRITICAL_ERROR, 'Could not obtain ban information', '', __LINE__, __FILE__, $sql); - } - - if ( $ban_info = $db->sql_fetchrow($result) ) - { - if ( $ban_info['ban_ip'] || $ban_info['ban_userid'] || $ban_info['ban_email'] ) - { - mx_message_die(CRITICAL_MESSAGE, 'You_been_banned'); - } - } - */ - + * Initial ban check against user id, IP and email address + * Is user banned? Are they excluded? Won't return on ban, exists within method + * / + $this->check_ban_for_current_session($board_config); + /**/ + // // Create or update the session // @@ -236,7 +311,7 @@ function session_begin($user_id, $user_ip, $page_id, $auto_create = 0, $enable_a mx_message_die(CRITICAL_ERROR, 'Error creating new session', '', __LINE__, __FILE__, $sql); } } - + if ( $user_id != ANONYMOUS ) { $last_visit = ( $userdata['user_session_time'] > 0 ) ? $userdata['user_session_time'] : $current_time; @@ -275,9 +350,14 @@ function session_begin($user_id, $user_ip, $page_id, $auto_create = 0, $enable_a if ( !$db->sql_query($sql) ) { - mx_message_die(CRITICAL_ERROR, 'Error updating session key', '', __LINE__, __FILE__, $sql); + $sql2 = 'UPDATE ' . SESSIONS_KEYS_TABLE . " + SET last_login = $current_time + WHERE key_id = '" . md5($sessiondata['autologinid']) . "'"; + if ( !$db->sql_query($sql2) ) + { + mx_message_die(CRITICAL_ERROR, 'Error updating session key', '', __LINE__, __FILE__, $sql); + } } - $sessiondata['autologinid'] = $auto_login_key; unset($auto_login_key); } @@ -334,7 +414,7 @@ function session_pagestart($user_ip, $thispage_id) else { $sessiondata = array(); - $session_id = $mx_request_vars->get('sid',MX_TYPE_NO_TAGS); + $session_id = $mx_request_vars->is_get('sid', MX_TYPE_NO_TAGS); $sessionmethod = SESSION_METHOD_GET; } @@ -355,23 +435,18 @@ function session_pagestart($user_ip, $thispage_id) // session_id exists so go ahead and attempt to grab all // data in preparation // - $sql = "SELECT u.*, s.* - FROM " . SESSIONS_TABLE . " s, " . USERS_TABLE . " u + $sql = "SELECT u.*, u.user_id as user_colour, u.user_level as user_type, p.default_lang as user_lang, p.board_timezone as user_timezone, s.* + FROM " . SESSIONS_TABLE . " s, " . USERS_TABLE . " u, " . PORTAL_TABLE . " p WHERE s.session_id = '$session_id' - AND u.user_id = s.session_user_id"; + AND u.user_id = s.session_user_id + AND p.portal_id = 1"; if ( !($result = $db->sql_query($sql)) ) { - $user_id = ( isset($sessiondata['userid']) ) ? intval($sessiondata['userid']) : ANONYMOUS; - - if ( !($userdata = $this->session_begin($user_id, $user_ip, $thispage_id, TRUE)) ) - { - mx_message_die(CRITICAL_ERROR, 'Error doing DB query userdata row fetch', '', __LINE__, __FILE__, $sql); - } + mx_message_die(CRITICAL_ERROR, 'Error doing DB query userdata row fetch', '', __LINE__, __FILE__, $sql); } - else - { - $userdata = $db->sql_fetchrow($result); - } + + $userdata = $db->sql_fetchrow($result); + // // Did the session exist in the DB? // @@ -500,8 +575,8 @@ function session_end($session_id, $user_id) // We expect that message_die will be called after this function, // but just in case it isn't, reset $userdata to the details for a guest // - $sql = 'SELECT * - FROM ' . USERS_TABLE . ' + $sql = 'SELECT u.*, u.user_id as user_colour, u.user_level as user_type, p.default_lang as user_lang, p.board_timezone as user_timezone + FROM ' . USERS_TABLE . ' u, ' . PORTAL_TABLE . ' p WHERE user_id = ' . ANONYMOUS; if ( !($result = $db->sql_query($sql)) ) { @@ -611,1080 +686,5223 @@ function session_reset_keys($user_id, $user_ip) unset($auto_login_key); } } + + /** + * Sets a cookie + * + * Sets a cookie of the given name with the specified data for the given length of time. + */ + function set_cookie($name, $cookiedata, $cookietime) + { + global $board_config; - /** ******************************************************************************************************* - * Include the User class - ******************************************************************************************************* */ + $name_data = rawurlencode($board_config['cookie_name'] . '_' . $name) . '=' . rawurlencode($cookiedata); + $expire = gmdate('D, d-M-Y H:i:s \\G\\M\\T', $cookietime); + $domain = (!$board_config['cookie_domain'] || $board_config['cookie_domain'] == 'localhost' || $board_config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $board_config['cookie_domain']; + + header('Set-Cookie: ' . $name_data . '; expires=' . $expire . '; path=' . $board_config['cookie_path'] . $domain . ((!$board_config['cookie_secure']) ? '' : '; secure') . '; HttpOnly', false); + } /** - * Define backend specific lang defs + * Check for banned user + * + * Checks whether the supplied user is banned by id, ip or email. If no parameters + * are passed to the method pre-existing session data is used. If $return is false + * this routine does not return on finding a banned user, it outputs a relevant + * message and stops execution. + * + * @param string|array $user_ips Can contain a string with one IP or an array of multiple IPs */ - function setup($lang_set = false, $style = false) + function check_ban($user_id = false, $user_ips = false, $user_email = false, $return = false) { - global $db, $template, $board_config, $userdata, $phpbb_auth, $phpEx, $phpbb_root_path, $mx_root_path, $mx_cache; - global $mx_request_vars, $portal_config, $shared_lang_path; //added for mxp + global $board_config, $db; - $lang_set = !$lang_set ? (defined('IN_ADMIN') ? 'lang_admin' : 'lang_main') : $lang_set; + if (defined('IN_CHECK_BAN')) + { + return; + } - $this->lang_name = $this->lang['default_lang']; - $this->lang_path = $shared_lang_path; + $banned = false; - $this->date_format = $board_config['default_dateformat']; - $this->timezone = $board_config['board_timezone'] * 3600; - $this->dst = $this->data['user_dst'] * 3600; + preg_match('/(..)(..)(..)(..)/', $user_ips, $user_ip_parts); + /* + $sql = "SELECT ban_ip, ban_userid, ban_email + FROM " . BANLIST_TABLE . " + WHERE ban_ip IN ('" . $user_ip_parts[1] . $user_ip_parts[2] . $user_ip_parts[3] . $user_ip_parts[4] . "', '" . $user_ip_parts[1] . $user_ip_parts[2] . $user_ip_parts[3] . "ff', '" . $user_ip_parts[1] . $user_ip_parts[2] . "ffff', '" . $user_ip_parts[1] . "ffffff') + OR ban_userid = $user_id"; + if ( $user_id != ANONYMOUS ) + { + $sql .= " OR ban_email LIKE '" . str_replace("\'", "''", $userdata['user_email']) . "' + OR ban_email LIKE '" . substr(str_replace("\'", "''", $userdata['user_email']), strpos(str_replace("\'", "''", $userdata['user_email']), "@")) . "'"; + } - // - // We include common language file here to not load it every time a custom language file is included - // - $lang = &$this->lang; + // Determine which entries to check, only return those + if ($user_email === false) + { + $sql .= " AND ban_email = ''"; + } - /* Sort of pointless here, since we have already included all main lang files - if ((@include $this->lang_path . "common.$phpEx") === false) + if ($user_ips === false) { - //this will fix the path for anonymouse users - if ((@include $phpbb_root_path . $this->lang_path . "common.$phpEx") === false) + $sql .= " AND (ban_ip = '' OR ban_exclude = 1)"; + } + + if ($user_id === false) + { + $sql .= ' AND (ban_userid = 0 OR ban_exclude = 1)'; + } + else + { + $sql .= ' AND (ban_userid = ' . $user_id; + + if ($user_email !== false) { - die('Language file ' . $this->lang_path . "common.$phpEx" . ' couldn\'t be opened.'); + $sql .= " OR ban_email <> ''"; } - } - $this->add_lang($lang_set); + if ($user_ips !== false) + { + $sql .= " OR ban_ip <> ''"; + } - // We include common language file here to not load it every time a custom language file is included - //$lang = &$this->lang; - unset($lang_set); - */ + $sql .= ')'; + } - return; - } - /** - * Sync UserData - * @access private - */ - function sync_userdata($userdata = false) - { - if (empty($userdata)) + if ( !($result = $db->sql_query($sql)) ) { - return false; - } - foreach ($userdata as $key => $value) + mx_message_die(CRITICAL_ERROR, 'Could not obtain ban information', '', __LINE__, __FILE__, $sql); + } + + $ban_triggered_by = 'user'; + if ( $ban_info = $db->sql_fetchrow($result) ) { - $do = true; - switch ($key) - { - // Rename user_data keys and get internal sitename/sitedesc - case 'user_id': - case 'user_name': - case 'user_regdate': - case 'user_posts': - case 'user_level': - case 'user_lang': - break; - /* - case 'last_login': - $key = 'user_lastvisit'; - break; - */ - } - if ($do) + if ( $ban_info['ban_ip'] || $ban_info['ban_userid'] || $ban_info['ban_email'] ) { - return $userdata[$key] = $value; + $banned = true; + $return = true; } - } - } + } + $db->sql_freeresult($result); + */ + if ($banned && !$return) + { + mx_message_die(CRITICAL_MESSAGE, 'You_been_banned'); + } - /** - * A replacement for unserialize that returns whether it worked and - * populates the unserialized variable by reference. - * - * @author walf - * @link http://www.php.net/manual/pt_BR/function.unserialize.php#105500 - * @param string $serialized the serialized data - * @param array $into the variable to hold the unserialized array - * @return bool whether the data was unserialized or not - * borrowed here from SMF Backend - * @since 0.1.2 - * - */ - function funserialize($serialized, &$into) - { - static $sfalse; - if ($sfalse === null) - { - $sfalse = serialize(false); - } - $into = @unserialize($serialized); - return $into !== false || @rtrim($serialized) === $sfalse; - //whitespace at end of serialized var is ignored by PHP + return ($banned) ? true : false; } /** - * Setup style - * - * Define backend specific style defs + * Check the current session for bans * + * @return true if session user is banned. */ - function setup_style() + protected function check_ban_for_current_session($config) { - return; + if (!defined('SKIP_CHECK_BAN') && $this->data['user_type'] != USER_FOUNDER) + { + if (!isset($config['forwarded_for_check'])) + { + $this->check_ban($this->data['user_id'], $this->ip); + } + else + { + $ips = explode(' ', $this->forwarded_for); + $ips[] = $this->ip; + $this->check_ban($this->data['user_id'], $ips); + } + } } /** - * Add Language Items - use_db and use_help are assigned where needed (only use them to force inclusion) + * Check if ip is blacklisted + * This should be called only where absolutely necessary * - * @param mixed $lang_set specifies the language entries to include - * @param bool $use_db internal variable for recursion, do not use - * @param bool $use_help internal variable for recursion, do not use + * Only IPv4 (rbldns does not support AAAA records/IPv6 lookups) * - * Examples: - *- * $lang_set = array('posting', 'help' => 'faq'); - * $lang_set = array('posting', 'viewtopic', 'help' => array('bbcode', 'faq')) - * $lang_set = array(array('posting', 'viewtopic'), 'help' => array('bbcode', 'faq')) - * $lang_set = 'posting' - * $lang_set = array('help' => 'faq', 'db' => array('help:faq', 'posting')) - *
+ * @author satmd (from the php manual) + * @param string $mode register/post - spamcop for example is omitted for posting + * @param string|false $ip the IPv4 address to check + * + * @return false if ip is not blacklisted, else an array([checked server], [lookup]) */ - function add_lang($lang_set, $use_db = false, $use_help = false) + function check_dnsbl($mode, $ip = false) { - global $phpEx; + if ($ip === false) + { + $ip = $this->ip; + } - if (is_array($lang_set)) + // Neither Spamhaus nor Spamcop supports IPv6 addresses. + if (strpos($ip, ':') !== false) { - foreach ($lang_set as $key => $lang_file) - { - // Please do not delete this line. - // We have to force the type here, else [array] language inclusion will not work - $key = (string) $key; + return false; + } - if ($key == 'db') - { - $this->add_lang($lang_file, true, $use_help); - } - else if ($key == 'help') - { - $this->add_lang($lang_file, $use_db, true); - } - else if (!is_array($lang_file)) + $dnsbl_check = array( + 'sbl.spamhaus.org' => 'http://www.spamhaus.org/query/bl?ip=', + ); + + if ($mode == 'register') + { + $dnsbl_check['bl.spamcop.net'] = 'http://spamcop.net/bl.shtml?'; + } + + if ($ip) + { + $quads = explode('.', $ip); + $reverse_ip = $quads[3] . '.' . $quads[2] . '.' . $quads[1] . '.' . $quads[0]; + + // Need to be listed on all servers... + $listed = true; + $info = array(); + + foreach ($dnsbl_check as $dnsbl => $lookup) + { + if (phpbb_checkdnsrr($reverse_ip . '.' . $dnsbl . '.', 'A') === true) { - $this->set_lang($this->lang, $this->help, $lang_file, $use_db, $use_help); + $info = array($dnsbl, $lookup . $ip); } else { - $this->add_lang($lang_file, $use_db, $use_help); + $listed = false; } } - unset($lang_set); - } - elseif ($lang_set) - { - $this->set_lang($this->lang, $this->help, $lang_set, $use_db, $use_help); + + if ($listed) + { + return $info; + } } + + return false; } + + /** ******************************************************************************************************* + * Include the User class + ******************************************************************************************************* */ /** - * Set language entry (called by add_lang) - * @access private + * Define backend specific lang defs */ - function set_lang(&$lang, &$help, $lang_file, $use_db = false, $use_help = false) + function setup($lang_set = false, $style = false) { - global $phpbb_root_path, $phpEx; + global $mx_cache, $template, $phpbb_auth, $phpEx, $phpbb_root_path, $mx_root_path; + global $mx_request_vars, $portal_config, $shared_lang_path, $phpBB2; //added for mxp - // $lang == $this->lang - // $help == $this->help - // - add appropriate variables here, name them as they are used within the language file... - if (!$use_db) + + global $board_config, $theme, $images; + global $db, $board_config, $userdata, $phpbb_root_path; + global $template, $lang, $phpEx, $nav_links; + + $this->data = !empty($this->data['user_id']) ? $this->data : $this->session_pagestart($this->user_ip, $this->page_id); + + $this->cache = is_object($mx_cache) ? $mx_cache : new base(); + + if (preg_match('/bot|crawl|curl|dataprovider|search|get|spider|find|java|majesticsEO|google|yahoo|teoma|contaxe|yandex|libwww-perl|facebookexternalhit/i', $_SERVER['HTTP_USER_AGENT'])) { - if ($use_help && strpos($lang_file, '/') !== false) + $this->data['is_bot'] = true; + } + else + { + $this->data['is_bot'] = false; + } + + // + // Populate session_id + // + $this->session_id = $this->data['session_id']; + + $this->lang_path = $shared_lang_path; + $this->lang_name = isset($this->data['user_lang']) ? $this->data['user_lang'] : $board_config['default_lang']; + + //$this->lang_path = $phpbb_root_path . 'language/'; + + $lang_set = !$lang_set ? (defined('IN_ADMIN') ? 'lang_admin' : 'lang_main') : $lang_set; + // + // Grab MXP global variables, re-cache if necessary + // - optional parameter to enable/disable cache for config data. If enabled, remember to refresh the MX-Publisher cache whenever updating MXP config settings + // - true: enable cache, false: disable cache + if (empty($portal_config['portal_status'])) + { + $portal_config = $this->obtain_mxbb_config(false); + } + // + // Grab phpBB global variables, re-cache if necessary + // - optional parameter to enable/disable cache for config data. If enabled, remember to refresh the MX-Publisher cache whenever updating phpBB config settings + // - true: enable cache, false: disable cache + if (empty($board_config['script_path'])) + { + $board_config = $mx_cache->obtain_config(false); + } + $board_config['avatar_gallery_path'] = 'includes/shared/phpbb2/images/avatar/'; + $board_config['user_timezone'] = !empty($board_config['user_timezone']) ? $board_config['user_timezone'] : $board_config['board_timezone']; + $this->data['user_dst'] = !empty($this->data['user_dst']) ? $this->data['user_dst'] : $this->data['user_timezone']; + $board_config['require_activation'] = 0; + $this->date_format = $board_config['default_dateformat']; + $this->timezone = $board_config['user_timezone'] * 3600; + $this->dst = $this->data['user_timezone'] * 3600; + + $sign = ($board_config['board_timezone'] < 0) ? '-' : '+'; + $time_offset = abs($board_config['board_timezone']); + + $offset_seconds = $time_offset % 3600; + $offset_minutes = $offset_seconds / 60; + $offset_hours = ($time_offset - $offset_seconds) / 3600; + + // Zone offset + $zone_offset = $this->timezone + $this->dst; + + $offset_string = sprintf($board_config['default_dateformat'], $sign, $offset_hours, $offset_minutes); + + $s_date = gmdate("Y-m-d\TH:i:s", time() + $zone_offset) . $offset_string; + + // Format Timezone. We are unable to use array_pop here, because of PHP3 compatibility + $l_timezone = explode('.', $board_config['board_timezone']); + $l_timezone = (count($l_timezone) > 1) ? $this->lang(sprintf('%.1f', $board_config['board_timezone'])) : $offset_string; + + $server_name = !empty($board_config['server_name']) ? preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($board_config['server_name'])) : 'localhost'; + $server_protocol = ($board_config['cookie_secure'] ) ? 'http://' : 'http://'; + $server_port = (($board_config['server_port']) && ($board_config['server_port'] <> 80)) ? ':' . trim($board_config['server_port']) . '/' : '/'; + $script_name_phpbb = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($board_config['script_path'])) . '/'; + $server_url = $server_protocol . str_replace("//", "/", $server_name . $server_port . '/'); //On some server the slash is not added and this trick will fix it + $corrected_url = $server_protocol . $server_name . $server_port . $script_name_phpbb; + $board_url = PORTAL_URL; + $web_path = (defined('PORTAL_URL')) ? $board_url : $corrected_url; + + @define('PHPBB_URL', $board_url); + + // + // Send a proper content-language to the output + // + $img_lang = $default_lang = ($this->data['user_lang']) ? $this->data['user_lang'] : $board_config['default_lang']; + + if ($this->data['user_id'] != ANONYMOUS) + { + if (!empty($this->data['user_lang'])) { - $language_filename = $this->lang_path . substr($lang_file, 0, stripos($lang_file, '/') + 1) . 'help_' . substr($lang_file, stripos($lang_file, '/') + 1) . '.' . $phpEx; + $default_lang = $phpBB2->phpbb_ltrim(basename($phpBB2->phpbb_rtrim($this->data['user_lang'])), "'"); } - else + + if (!empty($this->data['user_dateformat'])) { - $language_filename = $this->lang_path . (($use_help) ? 'help_' : '') . $lang_file . '.' . $phpEx; + $board_config['default_dateformat'] = $this->data['user_dateformat']; } - //fix for mxp - if ((@include $language_filename) === false) + if (isset($userdata['user_timezone'])) { - //this will fix the path for anonymouse users - if ((@include $phpbb_root_path . $language_filename) === false) - { - die('Language file ' . $language_filename . ' couldn\'t be opened.'); - } + $board_config['board_timezone'] = $this->data['user_timezone']; } } else { - // Get Database Language Strings - // Put them into $lang if nothing is prefixed, put them into $help if help: is prefixed - // For example: help:faq, posting - die("You should not use db with MX-Publisher!"); + $default_lang = $phpBB2->phpbb_ltrim(basename($phpBB2->phpbb_rtrim($board_config['default_lang'])), "'"); } - - // We include common language file here to not load it every time a custom language file is included - $this->lang = &$lang; - } - - /** - * Specify/Get image - // - // phpBB2 Graphics - redefined for mxBB - // - Uncomment and redefine phpBB graphics - // - // If you need to redefine some phpBB graphics, look within the phpBB/templates folder for the template_name.cfg file and - // redefine those $image['xxx'] you want. Note: Many phpBB images are reused all over mxBB (eg see below), thus if you redefine - // common phpBB images, this will have immedaite effect for all mxBB pages. - // - */ - function img($img, $alt = '', $width = false, $suffix = '', $type = 'full_tag') - { - static $imgs; - global $phpbb_root_path, $mx_root_path, $mx_images; - // - // Load phpBB Template configuration data - // - First try current template - // - if ( file_exists( $phpbb_root_path . $this->current_template_path . "/images" ) ) + // Shared phpBB2 lang files dir + // Load vanilla phpBB2 lang files if is possible + $shared_phpbb2_path = $mx_root_path . 'includes/shared/phpbb2/'; + $shared_phpbb3_path = $mx_root_path . 'includes/shared/phpbb3/'; + $shared_lang_path = $mx_root_path . 'includes/shared/phpbb2/language/'; + $lang_path = $mx_root_path . 'includes/shared/phpbb2/language/'; + + if (!file_exists(@phpbb_realpath($shared_phpbb2_path . 'lang_' . $default_lang . '/lang_main.'.$phpEx)) && !file_exists(@phpbb_realpath($shared_lang_path . 'lang_' . $default_lang . '/lang_main.'.$phpEx))) { - $current_template_path = $this->current_template_path; - $template_name = $this->template_name; - - @include($phpbb_root_path . $this->current_template_path . '/' . $this->template_name . '.cfg'); + if ($userdata['user_id'] !== ANONYMOUS) + { + // For logged in users, try the board default language next + // Just in case we do fallback on $board_config['phpbb_lang'] + // Since $board_config['default_lang'] has been overwiten in function $mx_user->_init_userprefs() + $default_lang = phpbb_ltrim(basename(phpbb_rtrim($board_config['phpbb_lang'])), "'"); + } + else + { + // For guests it means the default language is not present, try english + // This is a long shot since it means serious errors in the setup to reach here, + // but english is part of a new install so it's worth us trying + $default_lang = 'english'; + } + + if (!file_exists(@phpbb_realpath($shared_phpbb2_path . 'language/lang_' . $default_lang . '/lang_main.'.$phpEx))) + { + mx_message_die(CRITICAL_ERROR, 'Could not locate valid phpBB2 language pack in $mx_user->setup() for: ' . $default_lang); + } } - // - // Since we have no current Template Config file, try the cloned template instead - // - if ( file_exists( $phpbb_root_path . $this->cloned_current_template_path . "/images" ) && !defined('TEMPLATE_CONFIG') ) + // If we've had to change the value in any way then let's write it back to the database + // before we go any further since it means there is something wrong with it + if ($this->data['user_id'] != ANONYMOUS && $this->data['user_lang'] !== $default_lang) { - $current_template_path = $this->cloned_current_template_path; - $template_name = $this->cloned_template_name; + /* * / + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_lang = '" . $this->decode_lang($this->lang['default_lang']) . "' + WHERE user_lang = '" . $this->decode_lang($this->data['user_lang']) . "'"; + if (!($result = $db->sql_query($sql))) + { + mx_message_die(CRITICAL_ERROR, 'Could not update user language info in setup'); + } + /* */ + $this->data['user_lang'] = $default_lang; + } + elseif ($this->data['user_id'] == ANONYMOUS && $board_config['default_lang'] !== $default_lang) + { + $sql = "UPDATE " . PORTAL_TABLE . " SET + default_lang = '" . $this->decode_lang($this->lang['default_lang']) . "' + WHERE portal_id = '1'"; - @include($phpbb_root_path . $this->cloned_current_template_path . '/' . $this->cloned_template_name . '.cfg'); + if (!($result = $db->sql_query($sql))) + { + mx_message_die(CRITICAL_ERROR, 'Could not update user language info'); + } } + $board_config['default_lang'] = $default_lang; + $portal_config['default_lang'] = $default_lang; + $this->lang_name = $this->lang['default_lang'] = $default_lang; + $this->lang_path = $shared_phpbb2_path . 'language/lang_' . $board_config['default_lang'] . '/'; + // - // Last attempt, use default template intead + // We include common language file here to not load it every time a custom language file is included // - if ( file_exists( $phpbb_root_path . $this->default_current_template_path . "/images" ) && !defined('TEMPLATE_CONFIG') ) - { - $current_template_path = $this->default_current_template_path; - $template_name = $this->default_template_name; + $lang = &$this->lang; - @include($phpbb_root_path . $this->default_current_template_path . '/' . $this->default_template_name . '.cfg'); + /** Sort of pointless here, since we have already included all main lang files **/ + if ((@include $this->lang_path . "lang_main.$phpEx") === false) + { + //this will fix the path for anonymouse users + if ((@include $phpbb_root_path . $this->lang_path . "lang_main.$phpEx") === false) + { + die('Language file (setup) ' . $this->lang_path . "lang_main.$phpEx" . ' couldn\'t be opened.'); + } } + // include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.' . $phpEx); + + $this->add_lang($lang_set); - $this->img_lang = (file_exists($phpbb_root_path . $current_template_path . $this->lang_name)) ? $this->lang_name : $board_config['default_lang']; - - /* Here we overwrite phpBB images from the template configuration file with images from database */ + // We include common language file here to not load it every time a custom language file is included + $this->set_lang($this->lang, $this->help, 'common'); + // $lang = &$this->lang; - $this->img_array['image_filename'] = array( - 'img_site_logo' => "logo.gif", - 'img_upload_bar' => "upload_bar.gif", - 'img_icon_contact_aim' => "icon_aim.gif", - 'img_icon_contact_email' => "icon_email.gif", - 'img_icon_contact_icq' => "icon_icq_add.gif", - 'img_icon_contact_jabber' => "icon_jabber.gif", - 'img_icon_contact_msnm' => "icon_msnm.gif", - 'img_icon_contact_pm' => "icon_pm.gif", - 'img_icon_contact_yahoo' => "icon_yim.gif", - 'img_icon_contact_www' => "icon_www.gif", - 'img_icon_post_delete' => "icon_delete.gif", - 'img_icon_post_edit' => "icon_edit.gif", - 'img_icon_post_info' => "icon_info.gif", - 'img_icon_post_quote' => "icon_quote.gif", - 'img_icon_post_report' => "icon_report.gif", - 'img_icon_user_online' => "icon_online.gif", - 'img_icon_user_offline' => "icon_offline.gif", - 'img_icon_user_profile' => "icon_profile.gif", - 'img_icon_user_search' => "icon_search.gif", - 'img_icon_user_warn' => "icon_warn.gif", - 'img_button_pm_forward' => "reply.gif", - 'img_button_pm_new' => "msg_newpost.gif", - 'img_button_pm_reply' => "reply.gif", - 'img_button_topic_locked' => "msg_newpost.gif", - 'img_button_topic_new' => "post.gif", - 'img_button_topic_reply' => "reply.gif", - 'img_forum_link' => "forum_link.gif", - 'img_forum_read' => "forum_read.gif", - 'img_forum_read_locked' => "forum_read_locked.gif", - 'img_forum_read_subforum' => "forum_read_subforum.gif", - 'img_forum_unread' => "forum_unread.gif", - 'img_forum_unread_locked' => "forum_unread_locked.gif", - 'img_forum_unread_subforum' => "forum_unread_subforum.gif", - 'img_topic_moved' => "topic_moved.gif", - 'img_topic_read' => "topic_read.gif", - 'img_topic_read_mine' => "topic_read_mine.gif", - 'img_topic_read_hot' => "topic_read_hot.gif", - 'img_topic_read_hot_mine' => "topic_read_hot_mine.gif", - 'img_topic_read_locked' => "topic_read_locked.gif", - 'img_topic_read_locked_mine' => "topic_read_locked_mine.gif", - 'img_topic_unread' => "topic_unread.gif", - 'img_topic_unread_mine' => "topic_unread_mine.gif", - 'img_topic_unread_hot' => "topic_unread_hot.gif", - 'img_topic_unread_hot_mine' => "topic_unread_hot_mine.gif", - 'img_topic_unread_locked' => "topic_unread_locked.gif", - 'img_topic_unread_locked_mine' => "topic_unread_locked_mine.gif", - 'img_sticky_read' => "sticky_read.gif", - 'img_sticky_read_mine' => "sticky_read_mine.gif", - 'img_sticky_read_locked' => "sticky_read_locked.gif", - 'img_sticky_read_locked_mine' => "ticky_read_locked_mine.gif", - 'img_sticky_unread' => "sticky_unread.gif", - 'img_sticky_unread_mine' => "sticky_unread_mine.gif", - 'img_sticky_unread_locked' => "sticky_unread_locked.gif", - 'img_sticky_unread_locked_mine' => "sticky_unread_locked_mine.gif", - 'img_announce_read' => "announce_read.gif", - 'img_announce_read_mine' => "announce_read_mine.gif", - 'img_announce_read_locked' => "announce_read_locked.gif", - 'img_announce_read_locked_mine' => "announce_read_locked_mine.gif", - 'img_announce_unread' => "announce_unread.gif", - 'img_announce_unread_mine' => "announce_unread_mine.gif", - 'img_announce_unread_locked' => "announce_unread_locked.gif", - 'img_announce_unread_locked_mine' => "announce_unread_locked_mine.gif", - 'img_global_read' => "announce_read.gif", - 'img_global_read_mine' => "announce_read_mine.gif", - 'img_global_read_locked' => "announce_read_locked.gif", - 'img_global_read_locked_mine' => "announce_read_locked_mine.gif", - 'img_global_unread' => "announce_unread.gif", - 'img_global_unread_mine' => "announce_unread_mine.gif", - 'img_global_unread_locked' => "announce_unread_locked.gif", - 'img_global_unread_locked_mine' => "announce_unread_locked_mine.gif", - 'img_subforum_read' => "", - 'img_subforum_unread' => "", - 'img_pm_read' => "topic_read.gif", - 'img_pm_unread' => "topic_unread.gif", - 'img_icon_back_top' => "", - 'img_icon_post_target' => "icon_post_target.gif", - 'img_icon_post_target_unread' => "icon_post_target_unread.gif", - 'img_icon_topic_attach' => "icon_topic_attach.gif", - 'img_icon_topic_latest' => "icon_topic_latest.gif", - 'img_icon_topic_newest' => "icon_topic_newest.gif", - 'img_icon_topic_reported' => "icon_topic_reported.gif", - 'img_icon_topic_unapproved' => "icon_topic_unapproved.gif" + unset($lang_set); + + if (defined('IN_ADMIN')) + { + if(!file_exists(@phpbb_realpath($shared_phpbb2_path . 'language/lang_' . $board_config['default_lang'] . '/lang_admin.'.$phpEx))) + { + $board_config['default_lang'] = 'english'; + } + include($shared_phpbb2_path . 'language/lang_' . $board_config['default_lang'] . '/lang_admin.' . $phpEx); + } + + // + // We setup common user language variables + // + $this->lang = &$lang; + //print_r($this->lang); + $this->user_lang = !empty($this->lang['USER_LANG']) ? $this->lang['USER_LANG'] : $this->encode_lang($this->lang_name); + $user_lang = $this->user_lang; + + $this->user_language = $this->encode_lang($this->lang_name); + $this->default_language = $this->encode_lang($board_config['default_lang']); + + $this->user_language_name = $this->decode_lang($this->lang_name); + $this->default_language_name = $this->decode_lang($board_config['default_lang']); + + $counter = 0; //First language pack lang_id + $lang_ids = array(); + $lang_list = $this->get_lang_list(); + + if (is_array($lang_list)) + { + foreach ($lang_list as $lang_english_name => $lang_local_name) + { + $lang_ids[$lang_english_name] = $counter; + $counter++; + } + } + + $lang_entries = array( + 'lang_id' => !empty($lang_ids['lang_' . $this->user_language_name]) ? $lang_ids['lang_' . $this->user_language_name] : $counter, + 'lang_iso' => !empty($lang['USER_LANG']) ? $lang['USER_LANG'] : $this->encode_lang($this->lang_name), + 'lang_dir' => 'lang_' . $this->lang_name, + 'lang_english_name' => $this->user_language_name, + 'lang_local_name' => $this->ucstrreplace('lang_', '', $this->lang_name), + 'lang_author' => !empty($lang['TRANSLATION_INFO']) ? $lang['TRANSLATION_INFO'] : 'Language pack author not set in ACP.' ); - $this->img_array['image_lang'] = array( - 'img_icon_post_edit' => $this->img_lang, - 'img_icon_post_quote' => $this->img_lang, - 'img_button_pm_forward' => $this->img_lang, - 'img_button_pm_new' => $this->img_lang, - 'img_button_pm_reply' => $this->img_lang, - 'img_button_topic_new' => $this->img_lang, - 'img_button_topic_reply' => $this->img_lang - ); + // + // Finishing setting language variables to ouput + // + $this->lang_iso = $lang_iso = $lang_entries['lang_iso']; + $this->lang_dir = $lang_dir = $lang_entries['lang_dir']; + $this->lang_english_name = $lang_english_name = $lang_entries['lang_english_name']; + $this->lang_local_name = $lang_local_name = $lang_entries['lang_local_name']; - $img_data = &$imgs[$img]; - - if (empty($img_data)) + // + // Set up style to output + // + if ($this->data['user_id'] == ANONYMOUS && empty($this->data['user_style'])) { - if (!isset($this->img_array[$img])) - { - // Do not fill the image to let designers decide what to do if the image is empty - $img_data = ''; - return $img_data; - } + $this->data['user_style'] = $board_config['default_style']; + } + + /* + * This code was or is used for phpBB3 backend + * now commented here + * * * / + if (!empty($_GET['style']) || isset($_COOKIE['style'])) + { + global $SID, $_EXTRA_URL; - $img_data['src'] = PHPBB_URL . $current_template_path . ($this->img_array[$img]['image_lang'] ? $this->img_array[$img]['image_lang'] .'/' : '') . $this->img_array[$img]['image_filename']; - $img_data['width'] = (!empty($width)) ? $width : ''; //$this->img_array[$img]['image_width']; - $img_data['height'] = (!empty($height)) ? $height : ''; //$this->img_array[$img]['image_height']; + $style_request = phpBB3::request_var('style', 0); + $SID .= '&style=' . $style_request; + $_EXTRA_URL = array('style=' . $style_request); + + if ( $theme = $this->_setup_style($style_request) ) + { + setcookie('style', $style_request, (time() + 21600), $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']); + return; + } } + /** + * + * */ + - $alt = (!empty($this->lang[$alt])) ? $this->lang[$alt] : $alt; + + /* + * Setup demo style code + * Start + * * / + if ( isset($_GET['demo_theme']) || isset($_COOKIE['demo_theme'])) + { + $style_request = isset($_GET['demo_theme']) ? intval($_GET['demo_theme']) : intval($_COOKIE['demo_theme']); + if ( $theme = $this->_setup_style($style_request) ) + { + setcookie('demo_theme', $style_request, (time()+21600), $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']); + return; + } + } + /* + * Setup demo style code + * Ends + */ + + $style_request = $mx_request_vars->request('style', MX_TYPE_INT, 1); + + if ($mx_request_vars->is_get('style') && (!$board_config['override_user_style'] || !defined('IN_ADMIN'))) + { + global $SID, $_EXTRA_URL; - switch ($type) + $style = $style_request; + $SID .= '&style=' . $style; + $_EXTRA_URL = array('style=' . $style); + } + else { - case 'src': - return $img_data['src']; - break; + // Set up style + $style = ($style) ? $style : ((!$board_config['override_user_style']) ? $this->data['user_style'] : $board_config['default_style']); + } + /* + * Setup style code + * Start + * * / + //If user have other style in mxp then the one from phpBB not to have forum page and modules graphics will be messaed up + //Anonymouse users should see all block graphic corect + //Query phpBB style_id corepondent to mxp themes_id + $sql = "SELECT s.* + FROM " . MX_THEMES_TABLE . " AS m, " . THEMES_TABLE . " AS s + WHERE s.themes_id = " . (int) $style_id . " + AND s.template_name = m.template_name"; + $result = $db->sql_query($sql); + $this->style = $this->theme = $theme = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + // Fallback to user's standard style + if (!$this->style && $style_id != $this->data['user_style']) + { + $style_id = $this->data['user_style']; + + $sql = "SELECT s.* + FROM " . MX_THEMES_TABLE . " AS m, " . THEMES_TABLE . " AS s + WHERE s.themes_id = " . (int) $style_id . " + AND s.template_name = m.template_name"; + $result = $db->sql_query($sql); + $this->style = $this->theme = $theme = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + } + // Fallback to user's standard style + if (!$this->style) + { + $this->style = $this->theme = $theme = setup_style($style_id); + + mx_message_die(CRITICAL_ERROR, "Could not query database for phpbb_styles info style_id [$style_id]", "", __LINE__, __FILE__, $sql); + } + + $this->template_name = $theme['template_name']; + + // We are trying to setup a style which does not exist in the database + // Try to fallback to the board default (if the user had a custom style) + // and then any users using this style to the default if it succeeds + if ($theme['themes_id'] != $board_config['default_style']) + { + $sql = 'SELECT template_name + FROM ' . THEMES_TABLE . ' + WHERE themes_id = ' . (int) $board_config['default_style']; + + if ($row = $db->sql_fetchrow($result = $db->sql_query($sql))) + { + $db->sql_freeresult($result); + $this->default_current_template_name = !empty($row['template_name']) ? $row['template_name'] : $this->default_current_template_name; + } + } + + //Setup cloned template as prosilver based for phpBB3 styles + if( @file_exists(@phpbb_realpath($phpbb_root_path . $this->template_path . $this->template_name . '/style.cfg')) ) + { + $cfg = parse_cfg_file($phpbb_root_path . $this->template_path . $this->template_name . '/style.cfg'); + $this->cloned_template_name = !empty($cfg['parent']) ? $cfg['parent'] : 'prosilver'; + $this->cloned_template_path = $this->template_path . $this->cloned_template_name; + $this->default_template_name = !empty($cfg['parent']) ? $cfg['parent'] : 'prosilver'; + } + + //Setup current_template_path + $this->default_current_template_path = $this->template_path . $this->default_current_template_name; + $this->current_template_path = $this->template_path . $this->template_name; + $this->theme['theme_path'] = $this->template_name; + + $parsed_array = $this->cache->get('_cfg_' . $this->template_path); - case 'width': - return ($width === false) ? $img_data['width'] : $width; - break; + if ($parsed_array === false) + { + $parsed_array = array(); + } + + if( @file_exists(@phpbb_realpath($phpbb_root_path . $this->current_template_path . '/style.cfg')) ) + { + //parse phpBB3 style cfg file + $cfg_file_name = 'style.cfg'; + $cfg_file = $phpbb_root_path . $this->current_template_path . '/style.cfg'; + + if (!isset($parsed_array['filetime']) || (@filemtime($cfg_file) > $parsed_array['filetime'])) + { + // Re-parse cfg file + $parsed_array = parse_cfg_file($cfg_file); + $parsed_array['filetime'] = @filemtime($cfg_file); + $this->cache->put('_cfg_' . $this->template_path, $parsed_array); + } + } + else + { + //parse phpBB2 style cfg file + $cfg_file_name = $this->template_name . '.cfg'; + $cfg_file = $phpbb_root_path . $this->current_template_path . '/' . $cfg_file_name; + + if (file_exists($phpbb_root_path . $this->current_template_path . '/' . $cfg_file_name)) + { + if (!isset($parsed_array['filetime']) || (@filemtime($cfg_file) > $parsed_array['filetime'])) + { + $parsed_array = parse_cfg_file($cfg_file); + $parsed_array['filetime'] = @filemtime($cfg_file); + $this->cache->put('_cfg_' . $this->template_path, $parsed_array); + } + } + } + + $check_for = array( + 'pagination_sep' => (string) ', ' + ); - case 'height': - return $img_data['height']; - break; + foreach ($check_for as $key => $default_value) + { + $this->style[$key] = (isset($parsed_array[$key])) ? $parsed_array[$key] : $default_value; + $this->theme[$key] = (isset($parsed_array[$key])) ? $parsed_array[$key] : $default_value; + settype($this->style[$key], gettype($default_value)); + settype($this->theme[$key], gettype($default_value)); + if (is_string($default_value)) + { + $this->style[$key] = htmlspecialchars($this->style[$key]); + $this->theme[$key] = htmlspecialchars($this->theme[$key]); + } + } + + // If the style author specified the theme needs to be cached + // (because of the used paths and variables) than make sure it is the case. + // For example, if the theme uses language-specific images it needs to be stored in db. + if (file_exists($phpbb_root_path . $this->template_path . $this->template_name . '/theme/stylesheet.css')) + { + //phpBB3 Style Sheet + $theme_file = 'stylesheet.css'; + $css_file_path = $this->template_path . $this->template_name . '/theme/'; + $stylesheet = file_get_contents("{$phpbb_root_path}{$this->template_path}{$this->template_name}/theme/stylesheet.css"); + } + else + { + //phpBB2 Style Sheet + $theme_file = !empty($this->theme['head_stylesheet']) ? $this->theme['head_stylesheet'] : $this->template_name . '.css'; + $css_file_path = $this->template_path . $this->template_name . '/'; + if (file_exists($phpbb_root_path . $this->template_path . $this->template_name . '/' . $theme_file)) + { + $stylesheet = file_get_contents("{$phpbb_root_path}{$this->template_path}{$this->template_name}/{$theme_file}"); + } + } + + if (!empty($stylesheet)) + { + // Match CSS imports + $matches = array(); + preg_match_all('/@import url\(["\'](.*)["\']\);/i', $stylesheet, $matches); + + if (sizeof($matches)) + { + $content = ''; + foreach ($matches[0] as $idx => $match) + { + if ($content = @file_get_contents("{$phpbb_root_path}{$css_file_path}" . $matches[1][$idx])) + { + $content = trim($content); + } + else + { + $content = ''; + } + $stylesheet = str_replace($match, $content, $stylesheet); + } + unset($content); + } - default: - $use_width = ($width === false) ? $img_data['width'] : $width; + $stylesheet = str_replace('./', $css_file_path, $stylesheet); - return ''; - break; + $theme_info = array( + 'theme_data' => $stylesheet, + 'theme_mtime' => time(), + 'theme_storedb' => 0 + ); + $theme_data = &$theme_info['theme_data']; + } + + // + // - First try old Olympus image sets then phpBB2 and phpBB3 Proteus template lang images + // + if (@is_dir("{$phpbb_root_path}{$this->template_path}{$this->template_name}/imageset/")) + { + $this->imageset_path = '/imageset/'; //Olympus ImageSet + $this->img_lang = (file_exists($phpbb_root_path . $this->template_path . $this->template_name . $this->imageset_path . $this->lang_iso)) ? $this->lang_iso : $this->default_language; + $this->img_lang_dir = $this->img_lang; + $this->imageset_backend = 'olympus'; + } + elseif (@is_dir("{$phpbb_root_path}{$this->template_path}{$this->template_name}/theme/images/")) + { + $this->imageset_path = '/theme/images/'; //phpBB3 Images + if ((@is_dir("{$phpbb_root_path}{$this->template_path}{$this->template_name}/theme/images/lang_{$this->user_language_name}")) || (@is_dir("{$phpbb_root_path}{$this->template_path}{$this->template_name}/theme/images/lang_{$this->default_language_name}"))) + { + $this->img_lang = (file_exists($phpbb_root_path . $this->template_path . $this->template_name . $this->imageset_path . 'lang_' . $this->user_language_name)) ? $this->user_language_name : $this->default_language_name; + $this->img_lang_dir = 'lang_' . $this->img_lang; + $this->imageset_backend = 'phpbb2'; + } + if ((@is_dir("{$phpbb_root_path}{$this->template_path}{$this->template_name}/theme/images/{$this->user_language}")) || (@is_dir("{$phpbb_root_path}{$this->template_path}{$this->template_name}/theme/images/{$this->default_language}"))) + { + $this->img_lang = (file_exists($phpbb_root_path . $this->template_path . $this->template_name . $this->imageset_path . $this->user_language_name)) ? $this->user_language : $this->default_language; + $this->img_lang_dir = $this->img_lang; + $this->imageset_backend = 'phpbb3'; + } + } + elseif (@is_dir("{$phpbb_root_path}{$this->template_path}{$this->template_name}/images/")) + { + $this->imageset_path = '/images/'; //phpBB2 Images + $this->img_lang = (file_exists($phpbb_root_path . $this->template_path . $this->template_name . $this->imageset_path . '/images/lang_' . $this->user_language_name)) ? $this->user_language_name : $this->default_language_name; + $this->img_lang_dir = 'lang_' . $this->img_lang; + $this->imageset_backend = 'phpbb2'; + } + + // + // Olympus image sets main images + // + if (@file_exists("{$phpbb_root_path}{$this->template_path}{$this->template_name}{$this->imageset_path}/imageset.cfg")) + { + $cfg_data_imageset = parse_cfg_file("{$phpbb_root_path}{$this->template_path}{$this->template_name}{$this->imageset_path}/imageset.cfg"); + + foreach ($cfg_data_imageset as $image_name => $value) + { + if (strpos($value, '*') !== false) + { + if (substr($value, -1, 1) === '*') + { + list($image_filename, $image_height) = explode('*', $value); + $image_width = 0; + } + else + { + list($image_filename, $image_height, $image_width) = explode('*', $value); + } + } + else + { + $image_filename = $value; + $image_height = $image_width = 0; + } + + if (strpos($image_name, 'img_') === 0 && $image_filename) + { + $image_name = substr($image_name, 4); + $row[] = array( + 'image_name' => (string) $image_name, + 'image_filename' => (string) $image_filename, + 'image_height' => (int) $image_height, + 'image_width' => (int) $image_width, + 'imageset_id' => (int) $style_id, + 'image_lang' => '', + ); + + if (!empty($row['image_lang'])) + { + $localised_images = true; + } + $row['image_filename'] = !empty($row['image_filename']) ? rawurlencode($row['image_filename']) : ''; + $row['image_name'] = !empty($row['image_name']) ? rawurlencode($row['image_name']) : ''; + $this->img_array[$row['image_name']] = $row; + } + } + } + + // + // - Olympus image sets lolalised images + // + if (@file_exists("{$phpbb_root_path}{$this->template_path}{$this->template_name}{$this->imageset_path}{$this->img_lang}/imageset.cfg")) + { + $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}{$this->template_path}{$this->template_name}{$this->imageset_path}{$this->img_lang}/imageset.cfg"); + foreach ($cfg_data_imageset_data as $image_name => $value) + { + if (strpos($value, '*') !== false) + { + if (substr($value, -1, 1) === '*') + { + list($image_filename, $image_height) = explode('*', $value); + $image_width = 0; + } + else + { + list($image_filename, $image_height, $image_width) = explode('*', $value); + } + } + else + { + $image_filename = $value; + $image_height = $image_width = 0; + } + + if (strpos($image_name, 'img_') === 0 && $image_filename) + { + $image_name = substr($image_name, 4); + $row[] = array( + 'image_name' => (string) $image_name, + 'image_filename' => (string) $image_filename, + 'image_height' => (int) $image_height, + 'image_width' => (int) $image_width, + 'imageset_id' => !empty($this->theme['imageset_id']) ? (int) $this->theme['imageset_id'] : 0, + 'image_lang' => (string) $this->img_lang, + ); + + if (!empty($row['image_lang'])) + { + $localised_images = true; + } + $row['image_filename'] = !empty($row['image_filename']) ? rawurlencode($row['image_filename']) : ''; + $row['image_name'] = !empty($row['image_name']) ? rawurlencode($row['image_name']) : ''; + $this->img_array[$row['image_name']] = $row; + } + } + } + + // + // - phpBB3 Rhea and Proteus lang images + // + + + // + // - Try redefining phpBB2 images + // + if (empty($this->img_array)) + { + // * Now check for the correct existance of all of the images into + // * each image of a prosilver based style. + + + // Here we overwrite phpBB images from the template db or configuration file + $rows = array( + array( 'image_id' => 1, + 'image_name' => 'site_logo', + 'image_filename' => 'site_logo.gif', + 'image_lang' => '', + 'image_height' => 52, + 'image_width' => 139, + 'imageset_id' => 1 + ), + array( 'image_id' => 2, + 'image_name' => 'forum_link', + 'image_filename' => 'forum_link.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27, + 'imageset_id' => 1 + ), + array( 'image_id' => 3, + 'image_name' => 'forum_read', + 'image_filename' => 'forum_read.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27, + 'imageset_id' => 1 + ), + array( 'image_id' => 4, + 'image_name' => 'forum_read_locked', + 'image_filename' => 'forum_read_locked.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27, + 'imageset_id' => 1 + ), + array( 'image_id' => 5, + 'image_name' => 'forum_read_subforum', + 'image_filename' => 'forum_read_subforum.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27, + 'imageset_id' => 1 + ), + array( + 'image_id' => 6, + 'image_name' => 'forum_unread', + 'image_filename' => 'forum_unread.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27, + 'imageset_id' => 1 + ), + array( 'image_id' => 7, + 'image_name' => 'forum_unread_locked', + 'image_filename' => 'forum_unread_locked.gif', + 'image_lang' => '', 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 8, + 'image_name' => 'forum_unread_subforum', + 'image_filename' => 'forum_unread_subforum.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 9, + 'image_name' => 'topic_moved', + 'image_filename' => 'topic_moved.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 10, + 'image_name' => 'topic_read', + 'image_filename' => 'topic_read.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 11, + 'image_name' => 'topic_read_mine', + 'image_filename' => 'topic_read_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 12, + 'image_name' => 'topic_read_hot', + 'image_filename' => 'topic_read_hot.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 13, + 'image_name' => 'topic_read_hot_mine', + 'image_filename' => 'topic_read_hot_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 14, + 'image_name' => 'topic_read_locked', + 'image_filename' => 'topic_read_locked.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 15, + 'image_name' => 'topic_read_locked_mine', + 'image_filename' => 'topic_read_locked_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 16, + 'image_name' => 'topic_unread', + 'image_filename' => 'topic_unread.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 17, + 'image_name' => 'topic_unread_mine', + 'image_filename' => 'topic_unread_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 18, + 'image_name' => 'topic_unread_hot', + 'image_filename' => 'topic_unread_hot.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 19, + 'image_name' => 'topic_unread_hot_mine', + 'image_filename' => 'topic_unread_hot_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 20, + 'image_name' => 'topic_unread_locked', + 'image_filename' => 'topic_unread_locked.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 21, + 'image_name' => 'topic_unread_locked_mine', + 'image_filename' => 'topic_unread_locked_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 22, + 'image_name' => 'sticky_read', + 'image_filename' => 'sticky_read.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 23, + 'image_name' => 'sticky_read_mine', + 'image_filename' => 'sticky_read_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 24, + 'image_name' => 'sticky_read_locked', + 'image_filename' => 'sticky_read_locked.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 25, + 'image_name' => 'sticky_read_locked_mine', + 'image_filename' => 'sticky_read_locked_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 26, + 'image_name' => 'sticky_unread', + 'image_filename' => 'sticky_unread.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 27, + 'image_name' => 'sticky_unread_mine', + 'image_filename' => 'sticky_unread_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 28, + 'image_name' => 'sticky_unread_locked', + 'image_filename' => 'sticky_unread_locked.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 29, + 'image_name' => 'sticky_unread_locked_mine', + 'image_filename' => 'sticky_unread_locked_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 30, + 'image_name' => 'announce_read', + 'image_filename' => 'announce_read.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 31, + 'image_name' => 'announce_read_mine', + 'image_filename' => 'announce_read_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 32, + 'image_name' => 'announce_read_locked', + 'image_filename' => 'announce_read_locked.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 33, + 'image_name' => 'announce_read_locked_mine', + 'image_filename' => 'announce_read_locked_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 34, + 'image_name' => 'announce_unread', + 'image_filename' => 'announce_unread.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 35, + 'image_name' => 'announce_unread_mine', + 'image_filename' => 'announce_unread_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 36, + 'image_name' => 'announce_unread_locked', + 'image_filename' => 'announce_unread_locked.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 37, + 'image_name' => 'announce_unread_locked_mine', + 'image_filename' => 'announce_unread_locked_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 38, + 'image_name' => 'global_read', + 'image_filename' => 'announce_read.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 39, + 'image_name' => 'global_read_mine', + 'image_filename' => 'announce_read_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 40, + 'image_name' => 'global_read_locked', + 'image_filename' => 'announce_read_locked.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 41, + 'image_name' => 'global_read_locked_mine', + 'image_filename' => 'announce_read_locked_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 42, + 'image_name' => 'global_unread', + 'image_filename' => 'announce_unread.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 43, + 'image_name' => 'global_unread_mine', + 'image_filename' => 'announce_unread_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 44, + 'image_name' => 'global_unread_locked', + 'image_filename' => 'announce_unread_locked.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 45, + 'image_name' => 'global_unread_locked_mine', + 'image_filename' => 'announce_unread_locked_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 46, + 'image_name' => 'pm_read', + 'image_filename' => 'topic_read.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 47, + 'image_name' => 'pm_unread', + 'image_filename' => 'topic_unread.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 48, + 'image_name' => 'icon_back_top', + 'image_filename' => 'icon_back_top.gif', + 'image_lang' => '', + 'image_height' => 11, + 'image_width' => 11 , + 'imageset_id' => 1 + ), + array( 'image_id' => 49, + 'image_name' => 'icon_contact_aim', + 'image_filename' => 'icon_contact_aim.gif', + 'image_lang' => '', + 'image_height' => 20, + 'image_width' => 20, + 'imageset_id' => 1 + ), + array( 'image_id' => 50, + 'image_name' => 'icon_contact_email', + 'image_filename' => 'icon_contact_email.gif', + 'image_lang' => '', + 'image_height' => 20, + 'image_width' => 20, + 'imageset_id' => 1 + ), + array( 'image_id' => 51, + 'image_name' => 'icon_contact_icq', + 'image_filename' => 'icon_contact_icq.gif', + 'image_lang' => '', + 'image_height' => 20, + 'image_width' => 20, + 'imageset_id' => 1 + ), + array( 'image_id' => 52, + 'image_name' => 'icon_contact_jabber', + 'image_filename' => 'icon_contact_jabber.gif', + 'image_lang' => '', + 'image_height' => 20, + 'image_width' => 20, + 'imageset_id' => 1 + ), + array( 'image_id' => 53, + 'image_name' => 'icon_contact_msnm', + 'image_filename' => 'icon_contact_msnm.gif', + 'image_lang' => '', + 'image_height' => 20, + 'image_width' => 20, + 'imageset_id' => 1 + ), + array( 'image_id' => 54, + 'image_name' => 'icon_contact_www', + 'image_filename' => 'icon_contact_www.gif', + 'image_lang' => '', + 'image_height' => 20, + 'image_width' => 20, + 'imageset_id' => 1 + ), + array( 'image_id' => 55, + 'image_name' => 'icon_contact_yahoo', + 'image_filename' => 'icon_contact_yahoo.gif', + 'image_lang' => '', + 'image_height' => 20, + 'image_width' => 20, + 'imageset_id' => 1 + ), + array( 'image_id' => 56, + 'image_name' => 'icon_post_delete', + 'image_filename' => 'icon_post_delete.gif', + 'image_lang' => '', + 'image_height' => 20, + 'image_width' => 20, + 'imageset_id' => 1 + ), + array( 'image_id' => 57, + 'image_name' => 'icon_post_info', + 'image_filename' => 'icon_post_info.gif', + 'image_lang' => '', + 'image_height' => 20, + 'image_width' => 20, + 'imageset_id' => 1 + ), + array( 'image_id' => 58, + 'image_name' => 'icon_post_report', + 'image_filename' => + 'icon_post_report.gif', + 'image_lang' => '', + 'image_height' => 20, + 'image_width' => 20, + 'imageset_id' => 1 + ), + array( 'image_id' => 59, + 'image_name' => 'icon_post_target', + 'image_filename' => 'icon_post_target.gif', + 'image_lang' => '', + 'image_height' => 9, + 'image_width' => 11 , + 'imageset_id' => 1 + ), + array( 'image_id' => 60, + 'image_name' => 'icon_post_target_unread', + 'image_filename' => 'icon_post_target_unread.gif', + 'image_lang' => '', + 'image_height' => 9, + 'image_width' => 11 , + 'imageset_id' => 1 + ), + array( 'image_id' => 61, + 'image_name' => 'icon_topic_attach', + 'image_filename' => 'icon_topic_attach.gif', + 'image_lang' => '', + 'image_height' => 10, + 'image_width' => 7 , + 'imageset_id' => 1 + ), + array( 'image_id' => 62, + 'image_name' => 'icon_topic_latest', + 'image_filename' => 'icon_topic_latest.gif', + 'image_lang' => '', + 'image_height' => 9, + 'image_width' => 11 , + 'imageset_id' => 1 + ), + array( 'image_id' => 63, + 'image_name' => 'icon_topic_newest', + 'image_filename' => 'icon_topic_newest.gif', + 'image_lang' => '', + 'image_height' => 9, + 'image_width' => 11 , + 'imageset_id' => 1 + ), + array( 'image_id' => 64, + 'image_name' => 'icon_topic_reported', + 'image_filename' => 'icon_topic_reported.gif', + 'image_lang' => '', + 'image_height' => 14, + 'image_width' => 16 , + 'imageset_id' => 1 + ), + array( 'image_id' => 65, + 'image_name' => 'icon_topic_unapproved', + 'image_filename' => 'icon_topic_unapproved.gif', + 'image_lang' => '', + 'image_height' => 14, + 'image_width' => 16 , + 'imageset_id' => 1 + ), + array( 'image_id' => 66, + 'image_name' => 'icon_user_warn', + 'image_filename' => 'icon_user_warn.gif', + 'image_lang' => '', + 'image_height' => 20, + 'image_width' => 20, + 'imageset_id' => 1 + ), + array( 'image_id' => 67, + 'image_name' => 'subforum_read', + 'image_filename' => 'subforum_read.gif', + 'image_lang' => '', + 'image_height' => 9, + 'image_width' => 11 , + 'imageset_id' => 1 + ), + array( 'image_id' => 68, + 'image_name' => 'subforum_unread', + 'image_filename' => 'subforum_unread.gif', + 'image_lang' => '', + 'image_height' => 9, + 'image_width' => 11 , + 'imageset_id' => 1 + ), + array( 'image_id' => 69, + 'image_name' => 'icon_contact_pm', + 'image_filename' => 'icon_contact_pm.gif', + 'image_lang' => '{LANG}', + 'image_height' => 20, + 'image_width' => 28 , + 'imageset_id' => 1 + ), + array( 'image_id' => 70, + 'image_name' => 'icon_post_edit', + 'image_filename' => 'icon_post_edit.gif', + 'image_lang' => '{LANG}', + 'image_height' => 20, + 'image_width' => 42 , + 'imageset_id' => 1 + ), + array( 'image_id' => 71, + 'image_name' => 'icon_post_quote', + 'image_filename' => 'icon_post_quote.gif', + 'image_lang' => '{LANG}', + 'image_height' => 20, + 'image_width' => 54 , + 'imageset_id' => 1 + ), + array( 'image_id' => 72, + 'image_name' => 'icon_user_online', + 'image_filename' => 'icon_user_online.gif', + 'image_lang' => '{LANG}', + 'image_height' => 58, + 'image_width' => 58 , + 'imageset_id' => 1 + ), + array( 'image_id' => 73, + 'image_name' => 'button_pm_forward', + 'image_filename' => 'button_pm_forward.gif', + 'image_lang' => '{LANG}', + 'image_height' => 25, + 'image_width' => 96 , + 'imageset_id' => 1 + ), + array( 'image_id' => 74, + 'image_name' => 'button_pm_new', + 'image_filename' => 'button_pm_new.gif', + 'image_lang' => '{LANG}', + 'image_height' => 25, + 'image_width' => 84 , + 'imageset_id' => 1 + ), + array( 'image_id' => 75, + 'image_name' => 'button_pm_reply', + 'image_filename' => 'button_pm_reply.gif', + 'image_lang' => '{LANG}', + 'image_height' => 25, + 'image_width' => 96 , + 'imageset_id' => 1 + ), + array( 'image_id' => 76, + 'image_name' => 'button_topic_locked', + 'image_filename' => 'button_topic_locked.gif', + 'image_lang' => '{LANG}', + 'image_height' => 25, + 'image_width' => 88 , + 'imageset_id' => 1 + ), + array( 'image_id' => 77, + 'image_name' => 'button_topic_new', + 'image_filename' => 'button_topic_new.gif', + 'image_lang' => '{LANG}', + 'image_height' => 25, + 'image_width' => 96 , + 'imageset_id' => 1 + ), + array( 'image_id' => 78, + 'image_name' => 'button_topic_reply', + 'image_filename' => 'button_topic_reply.gif', + 'image_lang' => '{LANG}', + 'image_height' => 25, + 'image_width' => 96 , + 'imageset_id' => 1 + ) + ); + + foreach ($rows as $row) + { + $row['image_filename'] = rawurlencode($row['image_filename']); + + if(empty($row['image_name'])) + { + //print_r('Your style configuration file has a typo! '); + //print_r($row); + $row['image_name'] = 'spacer.gif'; + } + + $this->img_array[$row['image_name']] = $row; + } + } + + /** + * Now check for the correct existance of all images of the $user->style['style_path'] + * $template->set_template(); + * print_r($this->images['forum']); + */ + //$this->setup_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' => mx_append_sid($phpbb_root_path . 'index.' . $phpEx), + 'title' => sprintf($lang['Forum_Index'], $board_config['sitename']) + ); + $nav_links['search'] = array ( + 'url' => mx_append_sid($phpbb_root_path . 'search.' . $phpEx), + 'title' => $lang['Search'] + ); + $nav_links['help'] = array ( + 'url' => mx_append_sid($phpbb_root_path . 'faq.' . $phpEx), + 'title' => $lang['FAQ'] + ); + $nav_links['author'] = array ( + 'url' => mx_append_sid($phpbb_root_path . 'memberlist.' . $phpEx), + 'title' => $lang['Memberlist'] + ); + + // + // Dummy include, to make all original phpBB functions available + // + include_once($phpbb_root_path . 'includes/functions.' . $phpEx); // In case we need old functions... + + // + // Is phpBB File Attachment MOD present? + // + if( file_exists($phpbb_root_path . 'attach_mod') ) + { + include_once($phpbb_root_path . 'attach_mod/attachment_mod.' . $phpEx); } + + return; } /** - * Get option bit field from user options + * Setup style + * + * Define backend specific style defs + * + */ + function setup_style() + { + $template = new mx_Template($this->mx_root_path . $this->template_path . $this->template_name); + @define('IP_ROOT_PATH', $this->mx_root_path); //for ICY-PHOENIX Styles + + if (is_object($template)) + { + if(is_dir($this->mx_root_path . $this->current_template_path . '/theme/images/')) + { + $current_template_images = $this->current_template_images = $this->current_template_path . "/theme/images"; + } + elseif(is_dir($this->mx_root_path . $this->current_template_path . '/images/')) + { + $current_template_images = $this->current_template_images = $this->current_template_path . "/images"; + } + + global $phpBB2; + + $phpbb_root_path = $this->mx_root_path; + + $current_template_path = $this->template_path . $this->template_name; + + $cfg = array(); + //$row = $this->theme; + + /** + /* session->setup_style( ) + **/ + unset($GLOBALS['TEMPLATE_CONFIG']); + $mx_template_config = false; + if(@file_exists(@$phpBB2->phpbb_realpath($mx_root_path . $this->template_path . $this->template_name . '/' . $this->template_name . '.cfg')) ) + { + @include($mx_root_path . $this->template_path . $this->template_name . '/' . $this->template_name . '.cfg'); + + if (!defined('TEMPLATE_CONFIG')) + { + // + // Do not alter this line! + // + @define(TEMPLATE_CONFIG, TRUE); + } + } + elseif( @file_exists(@phpbb_realpath($mx_root_path . $this->template_path . $this->template_name . "/style.cfg")) ) + { + // + // Do not alter this line! + // + @define(TEMPLATE_CONFIG, TRUE); + $cfg = parse_cfg_file($mx_root_path. $this->template_path . basename($this->template_name) . '/style.cfg'); + + // + // - First try phpBB2 then phpBB3 template lang images then old Olympus image sets + // + if ( file_exists($mx_root_path . $this->current_template_path . '/images/') ) + { + $this->current_template_images = $this->current_template_path . '/images'; + } + else if ( file_exists($mx_root_path . $this->current_template_path . '/theme/images/') ) + { + $this->current_template_images = $this->current_template_path . '/theme/images'; + } + if ( file_exists($mx_root_path . $this->current_template_path . '/imageset/') ) + { + $this->current_template_images = $this->current_template_path . '/imageset'; + } + + $current_template_images = $this->current_template_images; + + $images['icon_quote'] = "$current_template_images/{LANG}/" . $this->img('icon_post_quote.gif', '', '', '', 'filename'); + $images['icon_edit'] = "$current_template_images/{LANG}/" . $this->img('icon_post_edit.gif', '', '', '', 'filename'); + $images['icon_search'] = "$current_template_images/{LANG}/" . $this->img('icon_user_search.gif', '', '', '', 'filename'); + $images['icon_profile'] = "$current_template_images/{LANG}/" . $this->img('icon_user_profile.gif', '', '', '', 'filename'); + $images['icon_pm'] = "$current_template_images/{LANG}/" . $this->img('icon_contact_pm.gif', '', '', '', 'filename'); + $images['icon_email'] = "$current_template_images/{LANG}/" . $this->img('icon_contact_email.gif', '', '', '', 'filename'); + $images['icon_delpost'] = "$current_template_images/{LANG}/" . $this->img('icon_post_delete.gif', '', '', '', 'filename'); + $images['icon_ip'] = "$current_template_images/{LANG}/" . $this->img('icon_user_ip.gif', '', '', '', 'filename'); + $images['icon_www'] = "$current_template_images/{LANG}/" . $this->img('icon_contact_www.gif', '', '', '', 'filename'); + $images['icon_icq'] = "$current_template_images/{LANG}/" . $this->img('icon_contact_icq_add.gif', '', '', '', 'filename'); + $images['icon_aim'] = "$current_template_images/{LANG}/" . $this->img('icon_contact_aim.gif', '', '', '', 'filename'); + $images['icon_yim'] = "$current_template_images/{LANG}/" . $this->img('icon_contact_yim.gif', '', '', '', 'filename'); + $images['icon_msnm'] = "$current_template_images/{LANG}/" . $this->img('icon_contact_msnm.gif', '', '', '', 'filename'); + $images['icon_minipost'] = "$current_template_images/" . $this->img('icon_post_target.gif', '', '', '', 'filename'); + $images['icon_gotopost'] = "$current_template_images/" . $this->img('icon_gotopost.gif', '', '', '', 'filename'); + $images['icon_minipost_new'] = "$current_template_images/" . $this->img('icon_post_target_unread.gif', '', '', '', 'filename'); + $images['icon_latest_reply'] = "$current_template_images/" . $this->img('icon_latest_reply.gif', '', '', '', 'filename'); + $images['icon_newest_reply'] = "$current_template_images/" . $this->img('icon_newest_reply.gif', '', '', '', 'filename'); + + $images['forum'] = "$current_template_images/" . $this->img('forum_read.gif', '', '27', '', 'filename'); + $images['forum_new'] = "$current_template_images/" . $this->img('forum_unread.gif', '', '', '', 'filename'); + $images['forum_locked'] = "$current_template_images/" . $this->img('forum_read_locked.gif', '', '', '', 'filename'); + + // Begin Simple Subforums MOD + $images['forums'] = "$current_template_images/" . $this->img('forum_read_subforum.gif', '', '', '', 'filename'); + $images['forums_new'] = "$current_template_images/" . $this->img('forum_unread_subforum.gif', '', '', '', 'filename'); + // End Simple Subforums MOD + + $images['folder'] = "$current_template_images/" . $this->img('topic_read.gif', '', '', '', 'filename'); + $images['folder_new'] = "$current_template_images/" . $this->img('topic_unread.gif', '', '', '', 'filename'); + $images['folder_hot'] = "$current_template_images/" . $this->img('topic_read_hot.gif', '', '', '', 'filename'); + $images['folder_hot_new'] = "$current_template_images/" . $this->img('topic_unread_hot.gif', '', '', '', 'filename'); + $images['folder_locked'] = "$current_template_images/" . $this->img('topic_read_locked.gif', '', '', '', 'filename'); + $images['folder_locked_new'] = "$current_template_images/" . $this->img('topic_unread_locked.gif', '', '', '', 'filename'); + $images['folder_sticky'] = "$current_template_images/" . $this->img('topic_read_mine.gif', '', '', '', 'filename'); + $images['folder_sticky_new'] = "$current_template_images/" . $this->img('topic_unread_mine.gif', '', '', '', 'filename'); + $images['folder_announce'] = "$current_template_images/" . $this->img('announce_read.gif', '', '', '', 'filename'); + $images['folder_announce_new'] = "$current_template_images/" . $this->img('announce_unread.gif', '', '', '', 'filename'); + + $images['post_new'] = "$current_template_images/{LANG}/" . $this->img('button_topic_new.gif', '', '', '', 'filename'); + $images['post_locked'] = "$current_template_images/{LANG}/" . $this->img('button_topic_locked.gif', '', '', '', 'filename'); + $images['reply_new'] = "$current_template_images/{LANG}/" . $this->img('button_topic_reply.gif', '', '', '', 'filename'); + $images['reply_locked'] = "$current_template_images/{LANG}/" . $this->img('icon_post_target_unread.gif', '', '', '', 'filename'); + + $images['pm_inbox'] = "$current_template_images/" . $this->img('msg_inbox.gif', '', '', '', 'filename'); + $images['pm_outbox'] = "$current_template_images/" . $this->img('msg_outbox.gif', '', '', '', 'filename'); + $images['pm_savebox'] = "$current_template_images/" . $this->img('msg_savebox.gif', '', '', '', 'filename'); + $images['pm_sentbox'] = "$current_template_images/" . $this->img('msg_sentbox.gif', '', '', '', 'filename'); + $images['pm_readmsg'] = "$current_template_images/" . $this->img('topic_read.gif', '', '', '', 'filename'); + $images['pm_unreadmsg'] = "$current_template_images/" . $this->img('topic_unread.gif', '', '', '', 'filename'); + $images['pm_replymsg'] = "$current_template_images/{LANG}/" . $this->img('reply.gif', '', '', '', 'filename'); + $images['pm_postmsg'] = "$current_template_images/{LANG}/" . $this->img('msg_newpost.gif', '', '', '', 'filename'); + $images['pm_quotemsg'] = "$current_template_images/{LANG}/" . $this->img('icon_quote.gif', '', '', '', 'filename'); + $images['pm_editmsg'] = "$current_template_images/{LANG}/" . $this->img('icon_edit.gif', '', '', '', 'filename'); + $images['pm_new_msg'] = ""; + $images['pm_no_new_msg'] = ""; + + $images['Topic_watch'] = ""; + $images['topic_un_watch'] = ""; + $images['topic_mod_lock'] = "$current_template_images/" . $this->img('topic_lock.gif', '', '', '', 'filename'); + $images['topic_mod_unlock'] = "$current_template_images/" . $this->img('topic_unlock.gif', '', '', '', 'filename'); + $images['topic_mod_split'] = "$current_template_images/" . $this->img('topic_split.gif', '', '', '', 'filename'); + $images['topic_mod_move'] = "$current_template_images/" . $this->img('topic_move.gif', '', '', '', 'filename'); + $images['topic_mod_delete'] = "$current_template_images/" . $this->img('topic_delete.gif', '', '', '', 'filename'); + + $images['voting_graphic'][0] = "$current_template_images/voting_bar.gif"; + $images['voting_graphic'][1] = "$current_template_images/voting_bar.gif"; + $images['voting_graphic'][2] = "$current_template_images/voting_bar.gif"; + $images['voting_graphic'][3] = "$current_template_images/voting_bar.gif"; + $images['voting_graphic'][4] = "$current_template_images/voting_bar.gif"; + + // + // Vote graphic length defines the maximum length of a vote result + // graphic, ie. 100% = this length + // + $board_config['vote_graphic_length'] = 205; + $board_config['privmsg_graphic_length'] = 175; + } + + if (!defined('TEMPLATE_CONFIG')) + { + mx_message_die(CRITICAL_ERROR, "Could not open $this->template_name template config file", '', __LINE__, __FILE__, $sql); + } + + $img_lang = (file_exists(@$phpBB2->phpbb_realpath($mx_root_path . $this->current_template_path . '/images/lang_' . $board_config['default_lang']))) ? $board_config['default_lang'] : 'english'; + + while(list($key, $value) = @each($images)) + { + if (!is_array($value)) + { + $this->images[$key] = $images[$key] = str_replace('{LANG}', $this->img_lang_dir, $value); + } + } + } + } + + /** + * Add Language Items - use_db and use_help are assigned where needed (only use them to force inclusion) + * + * @param mixed $lang_set specifies the language entries to include + * @param bool $use_db internal variable for recursion, do not use + * @param bool $use_help internal variable for recursion, do not use + * + * Examples: + *
+ * $lang_set = array('posting', 'help' => 'faq'); + * $lang_set = array('posting', 'viewtopic', 'help' => array('bbcode', 'faq')) + * $lang_set = array(array('posting', 'viewtopic'), 'help' => array('bbcode', 'faq')) + * $lang_set = 'posting' + * $lang_set = array('help' => 'faq', 'db' => array('help:faq', 'posting')) + *
*/ - function optionget($key, $data = false) + function add_lang($lang_set, $use_db = false, $use_help = false) { - if (!isset($this->keyvalues[$key])) + global $phpEx; + + if (is_array($lang_set)) { - $var = ($data) ? $data : $this->data['user_options']; - $this->keyvalues[$key] = ($var & 1 << $this->keyoptions[$key]) ? true : false; + foreach ($lang_set as $key => $lang_file) + { + // Please do not delete this line. + // We have to force the type here, else [array] language inclusion will not work + $key = (string) $key; + + if ($key == 'db') + { + $this->add_lang($lang_file, true, $use_help); + } + else if ($key == 'help') + { + $this->add_lang($lang_file, $use_db, true); + } + else if (!is_array($lang_file)) + { + $this->set_lang($this->lang, $this->help, $lang_file, $use_db, $use_help); + } + else + { + $this->add_lang($lang_file, $use_db, $use_help); + } + } + unset($lang_set); + } + elseif ($lang_set) + { + $this->set_lang($this->lang, $this->help, $lang_set, $use_db, $use_help); + } + } + + /** + * Set language entry (called by add_lang) + * @access private + */ + function set_lang(&$lang, &$help, $lang_file, $use_db = false, $use_help = false) + { + global $mx_root_path, $phpbb_root_path, $phpEx; + + // $lang == $this->lang + // $help == $this->help + // - add appropriate variables here, name them as they are used within the language file... + if (!$use_db) + { + if ($use_help && strpos($lang_file, '/') !== false) + { + $language_filename = $this->lang_path . substr($lang_file, 0, stripos($lang_file, '/') + 1) . 'help_' . substr($lang_file, stripos($lang_file, '/') + 1) . '.' . $phpEx; + } + else + { + $language_filename = $this->lang_path . (($use_help) ? 'help_' : '') . $lang_file . '.' . $phpEx; + } + + //fix for mxp + if ((@include $language_filename) === false) + { + // + //this will fix the path for shared language files + // + $language_phpbb2_filename = substr_count($language_filename, 'phpbb3') ? str_replace("phpbb3", "phpbb2", $language_filename) : str_replace("phpbb3", "phpbb2", $language_filename); + $language_phpbb3_filename = substr_count($language_filename, 'phpbb2') ? str_replace("phpbb2", "phpbb3", $language_filename) : str_replace("phpb2", "phpbb3", $language_filename); + + // + //this will fix the path for anonymouse users + // + $shared_phpbb2_path = substr_count($phpbb_root_path, 'phpbb3') ? str_replace("phpbb3", "phpbb2", $phpbb_root_path) : str_replace("phpbb3", "phpbb2", $phpbb_root_path); + $shared_phpbb3_path = substr_count($phpbb_root_path, 'phpbb2') ? str_replace("phpbb2", "phpbb3", $phpbb_root_path) : str_replace("phpb2", "phpbb3", $phpbb_root_path); + + if ((@include $language_phpbb3_filename) !== false) + { + //continue; + } + elseif ((@include $language_phpbb2_filename) !== false) + { + //continue; + } + elseif ((@include $phpbb_root_path . $language_filename) !== false) + { + //continue; + } + elseif ((@include $mx_root_path . $language_filename) !== false) + { + //continue; + } + elseif ((@include str_replace("phpbb3", "phpbb2", $language_filename)) !== false) + { + //continue; + } + elseif ((@include str_replace("phpbb2", "phpbb3", $language_filename)) === false) + { + $language_filename = $mx_root_path . '/language/' .$this->lang_english_name . (($use_help) ? 'help_' : '') . $lang_file . '.' . $phpEx; + + if ((@include str_replace("phpbb3", "phpbb2", $language_filename)) !== false) + { + die('Language file (set_lang) ' . str_replace("phpbb2", "phpbb3", $language_filename) . ' couldn\'t be opened by set_lang().'); + } + } + } + } + else + { + // Get Database Language Strings + // Put them into $lang if nothing is prefixed, put them into $help if help: is prefixed + // For example: help:faq, posting + die("You should not use db with MX-Publisher!"); + } + + // We include common language file here to not load it every time a custom language file is included + $this->lang = &$lang; + } + + /** + * Add Language Items from an extension - use_db and use_help are assigned where needed (only use them to force inclusion) + * + * @param string $ext_name The extension to load language from, or empty for core files + * @param mixed $lang_set specifies the language entries to include + * @param bool $use_db internal variable for recursion, do not use + * @param bool $use_help internal variable for recursion, do not use + * + * Note: $use_db and $use_help should be removed. Kept for BC purposes. + * + * @deprecated: 3.2.0-dev (To be removed: 4.0.0) + */ + function add_lang_ext($ext_name, $lang_set, $use_db = false, $use_help = false) + { + if ($ext_name === '/') + { + $ext_name = ''; + } + + $this->add_lang($lang_set, $use_db, $use_help, $ext_name); + } + + + /** + * More advanced language substitution + * Function to mimic sprintf() with the possibility of using phpBB's language system to substitute nullar/singular/plural forms. + * Params are the language key and the parameters to be substituted. + * This function/functionality is inspired by SHS` and Ashe. + * + * Example call: $user->lang('NUM_POSTS_IN_QUEUE', 1); + */ + /** + * Advanced language substitution + * + * Function to mimic sprintf() with the possibility of using phpBB's language system to substitute nullar/singular/plural forms. + * Params are the language key and the parameters to be substituted. + * This function/functionality is inspired by SHS` and Ashe. + * + * Example call: $user->lang('NUM_POSTS_IN_QUEUE', 1); + * + * If the first parameter is an array, the elements are used as keys and subkeys to get the language entry: + * Example: $user->lang(array('datetime', 'AGO'), 1) uses $user->lang['datetime']['AGO'] as language entry. + * + * @return string Return localized string or the language key if the translation is not available + */ + public function lang() + { + $args = func_get_args(); + $key = $args[0]; + //$key = array_shift($args); + if (is_array($key)) + { + $lang = &$this->lang[array_shift($key)]; + + foreach ($key as $_key) + { + $lang = &$lang[$_key]; + } + } + else + { + $lang = &$this->lang[$key]; + } + + // Return if language string does not exist + if (!isset($lang) || (!is_string($lang) && !is_array($lang))) + { + global $lang; + } + + // Return if language string does not exist + if (!isset($lang) || (!is_string($lang) && !is_array($lang))) + { + return $key; + } + + // If the language entry is a string, we simply mimic sprintf() behaviour + if (is_string($lang)) + { + if (sizeof($args) == 1) + { + return $lang; + } + + // Replace key with language entry and simply pass along... + $args[0] = $lang; + return call_user_func_array('sprintf', $args); + } + + // It is an array... now handle different nullar/singular/plural forms + $key_found = false; + + // We now get the first number passed and will select the key based upon this number + for ($i = 1, $num_args = sizeof($args); $i < $num_args; $i++) + { + if (is_int($args[$i])) + { + $numbers = array_keys($lang); + + foreach ($numbers as $num) + { + if ($num > $args[$i]) + { + break; + } + + $key_found = $num; + } + break; + } + } + + // Ok, let's check if the key was found, else use the last entry (because it is mostly the plural form) + if ($key_found === false) + { + $numbers = array_keys($lang); + $key_found = end($numbers); + } + + + + // Use the language string we determined and pass it to sprintf() + $args[0] = $lang[$key_found]; + return call_user_func_array('sprintf', $args); + //return $this->lang_array($key, $args); + } + + /** + * Format user date + * + * @param int $gmepoch unix timestamp + * @param string $format date format in date() notation. | used to indicate relative dates, for example |d m Y|, h:i is translated to Today, h:i. + * @param bool $forcedate force non-relative date format. + * + * @return mixed translated date + */ + function format_date($gmepoch, $format = false, $forcedate = false) + { + static $midnight; + static $date_cache; + + $format = (!$format) ? $this->date_format : $format; + $now = time(); + $delta = $now - $gmepoch; + + if (!isset($date_cache[$format])) + { + // Is the user requesting a friendly date format (i.e. 'Today 12:42')? + $date_cache[$format] = array( + 'is_short' => strpos($format, '|'), + 'format_short' => substr($format, 0, strpos($format, '|')) . '||' . substr(strrchr($format, '|'), 1), + 'format_long' => str_replace('|', '', $format), + // Filter out values that are not strings (e.g. arrays) for strtr(). + 'lang' => array_filter($this->lang['datetime'], 'is_string'), + ); + + // Short representation of month in format? Some languages use different terms for the long and short format of May + if ((strpos($format, '\M') === false && strpos($format, 'M') !== false) || (strpos($format, '\r') === false && strpos($format, 'r') !== false)) + { + $date_cache[$format]['lang']['May'] = $this->lang('datetime', 'May_short'); + } + } + + // Zone offset + $zone_offset = $this->timezone + $this->dst; + + // Show date <= 1 hour ago as 'xx min ago' but not greater than 60 seconds in the future + // A small tolerence is given for times in the future but in the same minute are displayed as '< than a minute ago' + if ($delta <= 3600 && $delta > -60 && ($delta >= -5 || (($now / 60) % 60) == (($gmepoch / 60) % 60)) && $date_cache[$format]['is_short'] !== false && !$forcedate && isset($this->lang['datetime']['AGO'])) + { + return $this->lang(array('datetime', 'AGO'), max(0, (int) floor($delta / 60))); + } + + if (!$midnight) + { + list($d, $m, $y) = explode(' ', gmdate('j n Y', time() + $zone_offset)); + $midnight = gmmktime(0, 0, 0, $m, $d, $y) - $zone_offset; + } + + if ($date_cache[$format]['is_short'] !== false && !$forcedate && !($gmepoch < $midnight - 86400 || $gmepoch > $midnight + 172800)) + { + $day = false; + + if ($gmepoch > $midnight + 86400) + { + $day = 'TOMORROW'; + } + else if ($gmepoch > $midnight) + { + $day = 'TODAY'; + } + else if ($gmepoch > $midnight - 86400) + { + $day = 'YESTERDAY'; + } + + if ($day !== false) + { + return str_replace('||', $this->lang['datetime'][$day], strtr(@gmdate($date_cache[$format]['format_short'], $gmepoch + $zone_offset), $date_cache[$format]['lang'])); + } + } + + return strtr(@gmdate($date_cache[$format]['format_long'], $gmepoch + $zone_offset), $date_cache[$format]['lang']); + } + + /** + * Create a \phpbb\datetime object in the context of the current user + * + * @since 3.1 + * @param string $time String in a format accepted by strtotime(). + * @param DateTimeZone $timezone Time zone of the time. + * @return \phpbb\datetime Date time object linked to the current users locale + */ + public function create_datetime($time = 'now', \DateTimeZone $timezone = null) + { + $timezone = $timezone ?: $this->timezone; + /** + $timezones = array('Europe/London', 'Mars/Olympus', 'Mars/Ascraeus', timezone_name_from_abbr('', $timezone, 0)); + + foreach ($timezones as $tz) + { + try + { + $mars = new DateTimeZone($tz); + } + + catch(Exception $e) + { + echo $e->getMessage() . '
'; + } + } + */ + return new DateTime($time, new DateTimeZone(timezone_name_from_abbr('', $timezone, 0))); + } + + /** + * Get the UNIX timestamp for a datetime in the users timezone, so we can store it in the database. + * + * @param string $format Format of the entered date/time + * @param string $time Date/time with the timezone applied + * @param DateTimeZone $timezone Timezone of the date/time, falls back to timezone of current user + * @return int Returns the unix timestamp + */ + public function get_timestamp_from_format($format, $time, \DateTimeZone $timezone = null) + { + $timezone = $timezone ?: $this->timezone; + $date = \DateTime::createFromFormat($format, $time, $timezone); + return ($date !== false) ? $date->format('U') : false; + } + + /** + * Get language id currently used by the user + */ + function get_iso_lang_id() + { + global $board_config, $db; + + if (!empty($this->lang_id)) + { + return $this->lang_id; + } + + if (!$this->lang_name) + { + $this->lang_name = $board_config['default_lang']; + } + + $sql = 'SELECT lang_id + FROM ' . LANG_TABLE . " + WHERE lang_iso = '" . $db->sql_escape($this->lang_name) . "'"; + $result = $db->sql_query($sql); + $this->lang_id = (int) $db->sql_fetchfield('lang_id'); + $db->sql_freeresult($result); + + return $this->lang_id; + } + + /** + * Generates default bitfield + * + * This bitfield decides which bbcodes are defined in a template. + * + * @return string Bitfield + */ + public function default_bitfield() + { + static $value; + if (isset($value)) + { + return $value; + } + + // Hardcoded template bitfield to add for new templates + $default_bitfield = '1111111111111'; + + $bitfield = new bitfield(); + for ($i = 0; $i < strlen($default_bitfield); $i++) + { + if ($default_bitfield[$i] == '1') + { + $bitfield->set($i); + } + } + + return $bitfield->get_base64(); + } + + /** + * Read style configuration file + * + * @param string $dir style directory + * @return array|bool Style data, false on error + */ + protected function read_style_cfg($dir) + { + static $required = array('name', 'phpbb_version', 'copyright'); + $cfg = parse_cfg_file($this->styles_path . $dir . '/style.cfg'); + + // Check if it is a valid file + foreach ($required as $key) + { + if (!isset($cfg[$key])) + { + return false; + } + } + + // Check data + if (!isset($cfg['parent']) || !is_string($cfg['parent']) || $cfg['parent'] == $cfg['name']) + { + $cfg['parent'] = ''; + } + if (!isset($cfg['template_bitfield'])) + { + $cfg['template_bitfield'] = $this->default_bitfield(); + } + + return $cfg; + } + + /** + * Specify/Get phpBB3 images array from phpBB2 images variable + */ + function image_rows($images) + { + /* Here we overwrite phpBB images from the template db or configuration file */ + $rows = array( + array( 'image_id' => 1, + 'image_name' => $this->img_name_ext('site_logo.gif', false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext('site_logo.gif', false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 52, + 'image_width' => 139, + 'imageset_id' => 1 + ), + array( 'image_id' => 2, + 'image_name' => 'forum_link', + 'image_filename' => 'forum_link.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27, + 'imageset_id' => 1 + ), + array( 'image_id' => 3, + 'image_name' => $this->img_name_ext($images['forum'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['forum'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27, + 'imageset_id' => 1 + ), + array( 'image_id' => 4, + 'image_name' => $this->img_name_ext($images['forum_locked'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['forum_locked'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27, + 'imageset_id' => 1 + ), + array( 'image_id' => 5, + 'image_name' => $this->img_name_ext($images['forums'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['forums'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27, + 'imageset_id' => 1 + ), + array( + 'image_id' => 6, + 'image_name' => $this->img_name_ext($images['forum_new'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['forum_new'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27, + 'imageset_id' => 1 + ), + array( 'image_id' => 7, + 'image_name' => 'forum_unread_locked', + 'image_filename' => 'forum_unread_locked.gif', + 'image_lang' => '', 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 8, + 'image_name' => $this->img_name_ext($images['forums_new'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['forums_new'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 9, + 'image_name' => 'topic_moved', + 'image_filename' => 'topic_moved.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 10, + 'image_name' => $this->img_name_ext($images['folder'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['folder'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 11, + 'image_name' => $this->img_name_ext($images['folder_sticky'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['folder_sticky'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 12, + 'image_name' => $this->img_name_ext($images['folder_hot'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['folder_hot'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 13, + 'image_name' => 'topic_read_hot_mine', + 'image_filename' => 'topic_read_hot_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 14, + 'image_name' => $this->img_name_ext($images['folder_locked'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['folder_locked'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 15, + 'image_name' => 'topic_read_locked_mine', + 'image_filename' => 'topic_read_locked_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 16, + 'image_name' => $this->img_name_ext($images['folder_new'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['folder_new'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 17, + 'image_name' => $this->img_name_ext($images['folder_sticky_new'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['folder_sticky_new'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 18, + 'image_name' => $this->img_name_ext($images['folder_hot_new'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['folder_hot_new'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 19, + 'image_name' => 'topic_unread_hot_mine', + 'image_filename' => 'topic_unread_hot_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 20, + 'image_name' => $this->img_name_ext($images['folder_locked_new'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['folder_locked_new'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 21, + 'image_name' => 'topic_unread_locked_mine', + 'image_filename' => 'topic_unread_locked_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 22, + 'image_name' => 'sticky_read', + 'image_filename' => 'sticky_read.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 23, + 'image_name' => 'sticky_read_mine', + 'image_filename' => 'sticky_read_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 24, + 'image_name' => 'sticky_read_locked', + 'image_filename' => 'sticky_read_locked.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 25, + 'image_name' => 'sticky_read_locked_mine', + 'image_filename' => 'sticky_read_locked_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 26, + 'image_name' => 'sticky_unread', + 'image_filename' => 'sticky_unread.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 27, + 'image_name' => 'sticky_unread_mine', + 'image_filename' => 'sticky_unread_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 28, + 'image_name' => 'sticky_unread_locked', + 'image_filename' => 'sticky_unread_locked.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 29, + 'image_name' => 'sticky_unread_locked_mine', + 'image_filename' => 'sticky_unread_locked_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 30, + 'image_name' => $this->img_name_ext($images['folder_announce'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['folder_announce'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 31, + 'image_name' => 'announce_read_mine', + 'image_filename' => 'announce_read_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 32, + 'image_name' => 'announce_read_locked', + 'image_filename' => 'announce_read_locked.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 33, + 'image_name' => 'announce_read_locked_mine', + 'image_filename' => 'announce_read_locked_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 34, + 'image_name' => $this->img_name_ext($images['folder_announce_new'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['folder_announce_new'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 35, + 'image_name' => 'announce_unread_mine', + 'image_filename' => 'announce_unread_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 36, + 'image_name' => 'announce_unread_locked', + 'image_filename' => 'announce_unread_locked.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 37, + 'image_name' => 'announce_unread_locked_mine', + 'image_filename' => 'announce_unread_locked_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 38, + 'image_name' => 'global_read', + 'image_filename' => $this->img_name_ext($images['folder_announce'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 39, + 'image_name' => 'global_read_mine', + 'image_filename' => 'announce_read_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 40, + 'image_name' => 'global_read_locked', + 'image_filename' => 'announce_read_locked.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 41, + 'image_name' => 'global_read_locked_mine', + 'image_filename' => 'announce_read_locked_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 42, + 'image_name' => 'global_unread', + 'image_filename' => $this->img_name_ext($images['folder_announce_new'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 43, + 'image_name' => 'global_unread_mine', + 'image_filename' => 'announce_unread_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 44, + 'image_name' => 'global_unread_locked', + 'image_filename' => 'announce_unread_locked.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 45, + 'image_name' => 'global_unread_locked_mine', + 'image_filename' => 'announce_unread_locked_mine.gif', + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 46, + 'image_name' => 'pm_read', + 'image_filename' => $this->img_name_ext($images['folder'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 47, + 'image_name' => 'pm_unread', + 'image_filename' => $this->img_name_ext($images['folder_new'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 27, + 'image_width' => 27 , + 'imageset_id' => 1 + ), + array( 'image_id' => 48, + 'image_name' => 'icon_back_top', + 'image_filename' => 'icon_back_top.gif', + 'image_lang' => '', + 'image_height' => 11, + 'image_width' => 11 , + 'imageset_id' => 1 + ), + array( 'image_id' => 49, + 'image_name' => $this->img_name_ext($images['icon_aim'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['icon_aim'], false, false, $type = 'filename'), + 'image_lang' => '{LANG}', + 'image_height' => 20, + 'image_width' => 20, + 'imageset_id' => 1 + ), + array( 'image_id' => 50, + 'image_name' => $this->img_name_ext($images['icon_email'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['icon_email'], false, false, $type = 'filename'), + 'image_lang' => '{LANG}', + 'image_height' => 20, + 'image_width' => 20, + 'imageset_id' => 1 + ), + array( 'image_id' => 51, + 'image_name' => $this->img_name_ext($images['icon_icq'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['icon_icq'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 20, + 'image_width' => 20, + 'imageset_id' => 1 + ), + array( 'image_id' => 52, + 'image_name' => 'icon_contact_jabber', + 'image_filename' => 'icon_contact_jabber.gif', + 'image_lang' => '', + 'image_height' => 20, + 'image_width' => 20, + 'imageset_id' => 1 + ), + array( 'image_id' => 53, + 'image_name' => $this->img_name_ext($images['icon_msnm'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['icon_msnm'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 20, + 'image_width' => 20, + 'imageset_id' => 1 + ), + array( 'image_id' => 54, + 'image_name' => $this->img_name_ext($images['icon_www'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['icon_www'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 20, + 'image_width' => 20, + 'imageset_id' => 1 + ), + array( 'image_id' => 55, + 'image_name' => $this->img_name_ext($images['icon_yim'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['icon_yim'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 20, + 'image_width' => 20, + 'imageset_id' => 1 + ), + array( 'image_id' => 56, + 'image_name' => $this->img_name_ext($images['icon_delpost'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['icon_delpost'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 20, + 'image_width' => 20, + 'imageset_id' => 1 + ), + array( 'image_id' => 57, + 'image_name' => 'icon_post_info', + 'image_filename' => 'icon_post_info.gif', + 'image_lang' => '', + 'image_height' => 20, + 'image_width' => 20, + 'imageset_id' => 1 + ), + array( 'image_id' => 58, + 'image_name' => 'icon_post_report', + 'image_filename' => 'icon_post_report.gif', + 'image_lang' => '', + 'image_height' => 20, + 'image_width' => 20, + 'imageset_id' => 1 + ), + array( 'image_id' => 59, + 'image_name' => $this->img_name_ext($images['icon_minipost'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['icon_minipost'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 9, + 'image_width' => 11 , + 'imageset_id' => 1 + ), + array( 'image_id' => 60, + 'image_name' => $this->img_name_ext($images['icon_minipost_new'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['icon_minipost_new'], false, false, $type = 'filename'), + 'image_lang' => '', + 'image_height' => 9, + 'image_width' => 11 , + 'imageset_id' => 1 + ), + array( 'image_id' => 61, + 'image_name' => 'icon_topic_attach', + 'image_filename' => 'icon_topic_attach.gif', + 'image_lang' => '', + 'image_height' => 10, + 'image_width' => 7 , + 'imageset_id' => 1 + ), + array( 'image_id' => 62, + 'image_name' => 'icon_topic_latest', + 'image_filename' => 'icon_topic_latest.gif', + 'image_lang' => '', + 'image_height' => 9, + 'image_width' => 11 , + 'imageset_id' => 1 + ), + array( 'image_id' => 63, + 'image_name' => 'icon_topic_newest', + 'image_filename' => 'icon_topic_newest.gif', + 'image_lang' => '', + 'image_height' => 9, + 'image_width' => 11 , + 'imageset_id' => 1 + ), + array( 'image_id' => 64, + 'image_name' => 'icon_topic_reported', + 'image_filename' => 'icon_topic_reported.gif', + 'image_lang' => '', + 'image_height' => 14, + 'image_width' => 16 , + 'imageset_id' => 1 + ), + array( 'image_id' => 65, + 'image_name' => 'icon_topic_unapproved', + 'image_filename' => 'icon_topic_unapproved.gif', + 'image_lang' => '', + 'image_height' => 14, + 'image_width' => 16 , + 'imageset_id' => 1 + ), + array( 'image_id' => 66, + 'image_name' => 'icon_user_warn', + 'image_filename' => 'icon_user_warn.gif', + 'image_lang' => '', + 'image_height' => 20, + 'image_width' => 20, + 'imageset_id' => 1 + ), + array( 'image_id' => 67, + 'image_name' => 'subforum_read', + 'image_filename' => 'subforum_read.gif', + 'image_lang' => '', + 'image_height' => 9, + 'image_width' => 11 , + 'imageset_id' => 1 + ), + array( 'image_id' => 68, + 'image_name' => 'subforum_unread', + 'image_filename' => 'subforum_unread.gif', + 'image_lang' => '', + 'image_height' => 9, + 'image_width' => 11 , + 'imageset_id' => 1 + ), + array( 'image_id' => 69, + 'image_name' => $this->img_name_ext($images['icon_pm'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['icon_pm'], false, false, $type = 'filename'), + 'image_lang' => '{LANG}', + 'image_height' => 20, + 'image_width' => 28 , + 'imageset_id' => 1 + ), + array( 'image_id' => 70, + 'image_name' => $this->img_name_ext($images['icon_edit'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['icon_edit'], false, false, $type = 'filename'), + 'image_lang' => '{LANG}', + 'image_height' => 20, + 'image_width' => 42 , + 'imageset_id' => 1 + ), + array( 'image_id' => 71, + 'image_name' => $this->img_name_ext($images['icon_quote'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['icon_quote'], false, false, $type = 'filename'), + 'image_lang' => '{LANG}', + 'image_height' => 20, + 'image_width' => 54 , + 'imageset_id' => 1 + ), + array( 'image_id' => 72, + 'image_name' => 'icon_user_online', + 'image_filename' => 'icon_user_online.gif', + 'image_lang' => '{LANG}', + 'image_height' => 58, + 'image_width' => 58 , + 'imageset_id' => 1 + ), + array( 'image_id' => 73, + 'image_name' => 'button_pm_forward', + 'image_filename' => 'button_pm_forward.gif', + 'image_lang' => '{LANG}', + 'image_height' => 25, + 'image_width' => 96 , + 'imageset_id' => 1 + ), + array( 'image_id' => 74, + 'image_name' => 'button_pm_new', + 'image_filename' => 'button_pm_new.gif', + 'image_lang' => '{LANG}', + 'image_height' => 25, + 'image_width' => 84 , + 'imageset_id' => 1 + ), + array( 'image_id' => 75, + 'image_name' => 'button_pm_reply', + 'image_filename' => 'button_pm_reply.gif', + 'image_lang' => '{LANG}', + 'image_height' => 25, + 'image_width' => 96 , + 'imageset_id' => 1 + ), + array( 'image_id' => 76, + 'image_name' => $this->img_name_ext($images['post_locked'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['post_locked'], false, false, $type = 'filename'), + 'image_lang' => '{LANG}', + 'image_height' => 25, + 'image_width' => 88 , + 'imageset_id' => 1 + ), + array( 'image_id' => 77, + 'image_name' => $this->img_name_ext($images['post_new'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['post_new'], false, false, $type = 'filename'), + 'image_lang' => '{LANG}', + 'image_height' => 25, + 'image_width' => 96 , + 'imageset_id' => 1 + ), + array( 'image_id' => 78, + 'image_name' => $this->img_name_ext($images['reply_new'], false, false, $type = 'name'), + 'image_filename' => $this->img_name_ext($images['reply_new'], false, false, $type = 'filename'), + 'image_lang' => '{LANG}', + 'image_height' => 25, + 'image_width' => 96 , + 'imageset_id' => 1 + ) + ); + return $rows; + } + + /** + * Specify/Get image name , extension + */ + function img_name_ext($img, $prefix = 'img_', $new_prefix = '', $type = 'filename') + { + if (strpos($img, '.') !== false) + { + // Nested img + $image_filename = $img; + $img_ext = substr(strrchr($image_filename, '.'), 1); + $img = basename($image_filename, '.' . $img_ext); + + unset($img_name, $image_filename); + } + else + { + $img_ext = 'gif'; + } + + switch ($type) + { + case 'filename': + return $img . '.' . $img_ext; + break; + + case 'class': + return $prefix . '_' . $img; + break; + + case 'name': + return $img; + break; + + case 'ext': + return $img_ext; + break; + } + } + + /** + * Specify/Get image + // + // phpBB2 Graphics - redefined for mxBB + // - Uncomment and redefine phpBB graphics + // + // If you need to redefine some phpBB graphics, look within the phpBB/templates folder for the template_name.cfg file and + // redefine those $image['xxx'] you want. Note: Many phpBB images are reused all over mxBB (eg see below), thus if you redefine + // common phpBB images, this will have immedaite effect for all mxBB pages. + // + */ + function img($img, $alt = '', $width = false, $suffix = '', $type = '') + { + static $imgs; + global $phpbb_root_path, $root_path, $theme; + + $title = ''; + + if ($alt) + { + $alt = $this->lang($alt); + $title = ' title="' . $alt . '"'; + } + + if (strpos($img, '.') !== false) + { + // Nested img + $image_filename = $img; + $img_ext = substr(strrchr($image_filename, '.'), 1); + $img = basename($image_filename, '.' . $img_ext); + $this->img_array['image_filename'] = array( + 'img_'.$img => $img . '.' . $img_ext, + ); + unset($img_name, $image_filename); + } + + if ($width !== false) + { + $this->img_array['image_width'] = array( + 'img_'.$img => $width, + ); + } + + // print_r($this->img_array['image_filename']); + // array ( [img_forum_read] => forum_read.gif ) + // Load phpBB Template configuration data + $current_template_path = $this->current_template_path; + $template_name = $this->template_name; + + // + // - First try phpBB2 then phpBB3 template + // + if ( file_exists($phpbb_root_path . $this->current_template_path . '/' . $this->template_name . '.cfg') ) + { + @include($phpbb_root_path . $this->current_template_path . '/' . $this->template_name . '.cfg'); + @define('TEMPLATE_CONFIG', true); + + //$img_keys = array_keys($images); + //$img_values = array_values($images); + + $rows = $this->image_rows($images); + + foreach ($rows as $row) + { + $row['image_filename'] = rawurlencode($row['image_filename']); + + if(empty($row['image_name'])) + { + //print_r('Your style configuration file has a typo! '); + //print_r($phpbb_root_path . $this->current_template_path . '/' . $this->template_name . '.cfg '); + //print_r($row); + $row['image_name'] = 'spacer.gif'; + } + /** + * Now check for the correct existance of all of the images into + * each image of a prosilver based style. + */ + $this->img_array[$row['image_name']] = $row; + } + } + else if ( file_exists($phpbb_root_path . $current_template_path . '/theme/stylesheet.css') ) + { + @define('TEMPLATE_CONFIG', true); + $current_template_images = $current_template_path . "/theme/images"; + } + + // + // Since we have no current Template Config file, try the cloned template instead + // + if ( file_exists($phpbb_root_path . $this->cloned_current_template_path . '/' . $this->cloned_template_name . '.cfg') && !defined('TEMPLATE_CONFIG') ) + { + $current_template_path = $this->cloned_current_template_path; + $template_name = $this->cloned_template_name; + + @include($phpbb_root_path . $this->cloned_current_template_path . '/' . $this->cloned_template_name . '.cfg'); + + $rows = $this->image_rows($images); + + foreach ($rows as $row) + { + $row['image_filename'] = rawurlencode($row['image_filename']); + + if(empty($row['image_name'])) + { + print_r('Your style configuration file has a typo! '); + print_r($phpbb_root_path . $this->current_template_path . '/' . $this->template_name . '.cfg '); + print_r($row); + } + /** + * Now check for the correct existance of all of the images into + * each image of a prosilver based style. + */ + $this->img_array[$row['image_name']] = $row; + } + } + + // + // Last attempt, use default template intead + // + if ( file_exists($phpbb_root_path . $this->default_current_template_path . '/' . $this->default_template_name . '.cfg') && !defined('TEMPLATE_CONFIG') ) + { + $current_template_path = $this->default_current_template_path; + $template_name = $this->default_template_name; + + @include($phpbb_root_path . $this->default_current_template_path . '/' . $this->default_template_name . '.cfg'); + + $rows = $this->image_rows($images); + + foreach ($rows as $row) + { + $row['image_filename'] = rawurlencode($row['image_filename']); + + if(empty($row['image_name'])) + { + print_r('Your style configuration file has a typo! '); + print_r($phpbb_root_path . $this->current_template_path . '/' . $this->template_name . '.cfg '); + print_r($row); + } + /** + * Now check for the correct existance of all of the images into + * each image of a prosilver based style. + */ + $this->img_array[$row['image_name']] = $row; + } + } + + // + // - First try phpBB2 then phpBB3 template lang images then old Olympus image sets + // default language + if ( file_exists($phpbb_root_path . $current_template_path . '/images/lang_' . $this->default_language_name . '/') ) + { + $this->img_lang = $this->default_language_name; + } + else if ( file_exists($phpbb_root_path . $current_template_path . '/theme/images/lang_' . $this->default_language_name . '/') ) + { + $this->img_lang = $this->default_language_name; + } + else if ( file_exists($phpbb_root_path . $current_template_path . '/theme/images/' . $this->default_language . '/') ) + { + $this->img_lang = $this->default_language; + } + else if ( file_exists($phpbb_root_path . $current_template_path . '/theme/imageset/' . $this->default_language . '/') ) + { + $this->img_lang = $this->default_language; + } + + // + // - First try phpBB2 then phpBB3 template lang images then old Olympus image sets + // user language + if ( file_exists($phpbb_root_path . $current_template_path . '/images/lang_' . $this->user_language_name . '/') ) + { + $this->img_lang = $this->user_language_name; + } + else if ( file_exists($phpbb_root_path . $current_template_path . '/theme/images/lang_' . $this->user_language_name . '/') ) + { + $this->img_lang = $this->user_language_name; + } + else if ( file_exists($phpbb_root_path . $current_template_path . '/theme/images/' . $this->user_language . '/') ) + { + $this->img_lang = $this->user_language; + } + else if ( file_exists($phpbb_root_path . $current_template_path . '/theme/imageset/' . $this->user_language . '/') ) + { + $this->img_lang = $this->user_language; + } + + if (empty($this->img_array)) + { + /** + * Now check for the correct existance of all of the images into + * each image of a prosilver based style. + foreach ($rows as $row) + { + $row['image_filename'] = rawurlencode($row['image_filename']); + $this->img_array[$row['image_name']] = $row; + } + */ + trigger_error('NO_STYLE_DATA', E_USER_ERROR); + } + + $img_data = &$this->img_array['image_filename'][$img]; + + if (empty($img_data)) + { + if (!isset($this->img_array['image_filename']['img_'.$img]) && !isset($this->img_array['image_filename'][$img])) + { + // Do not fill the image to let designers decide what to do if the image is empty + $img_data = ''; + return $img_data; + } + + if (isset($this->img_array['image_lang']['img_'.$img]) && isset($this->img_array['image_lang'][$img])) + { + // + // - First try phpBB2 then phpBB3 template lang images + // + if ( file_exists($phpbb_root_path . $current_template_path . '/images/' . $this->img_array['image_lang']['img_'.$img] . '/') ) + { + $current_template_images = $current_template_path . '/images/' . $this->img_array['image_lang']['img_'.$img]; + } + else if ( file_exists($phpbb_root_path . $current_template_path . '/theme/images/' . $this->img_array['image_lang']['img_'.$img] . '/') ) + { + $current_template_images = $current_template_path . '/theme/images/' . $this->img_array['image_lang']['img_'.$img]; + } + else if ( file_exists($phpbb_root_path . $current_template_path . '/theme/images/' . $this->encode_lang($this->lang_name) . '/') ) + { + $current_template_images = $current_template_path . '/theme/images/' . $this->encode_lang($this->lang_name); + } + else if ( file_exists($phpbb_root_path . $current_template_path . '/theme/imageset/' . $this->encode_lang($this->lang_name) . '/') ) + { + $current_template_images = $current_template_path . '/theme/imageset/' . $this->encode_lang($this->lang_name); + } + } + + $img_data['src'] = PHPBB_URL . $current_template_images . '/' . (!empty($this->img_array['image_filename']['img_'.$img]) ? $this->img_array['image_filename']['img_'.$img] : $this->img_array['image_filename'][$img]); + $img_data['width'] = !empty($height) ? $height : (!empty($this->img_array['image_width']) ? (!empty($this->img_array['image_width']['img_'.$img]) ? $this->img_array['image_width']['img_'.$img] : (!empty($this->img_array['image_width'][$img]) ? $this->img_array['image_width'][$img] : 47)) : 47); + $img_data['height'] = !empty($height) ? $height : (!empty($this->img_array['image_height']) ? (!empty($this->img_array['image_width']['img_'.$img]) ? $this->img_array['image_height']['img_'.$img] : (!empty($this->img_array['image_height'][$img]) ? $this->img_array['image_height'][$img] : 47)) : 47); + } + + $alt = (!empty($this->lang[$alt])) ? $this->lang[$alt] : $alt; + + $use_width = ($width === false) ? $img_data['width'] : $width; + + switch ($type) + { + case 'src': + return $img_data['src']; + break; + + case 'width': + return $use_width; + break; + + case 'height': + return $img_data['height']; + break; + + case 'filename': + return $img . '.' . $img_ext; + break; + + case 'class': + case 'name': + return $img; + break; + + case 'alt': + return $alt; + break; + + case 'ext': + return $img_ext; + break; + + case 'full_tag': + return ''; + break; + + case 'html': + default: + return '' . $alt . ''; + break; + } + } + + /** + * Specify/Get image + // + // phpBB2 Graphics - redefined for mxBB + // - Uncomment and redefine phpBB graphics + // + // If you need to redefine some phpBB graphics, look within the phpBB/templates folder for the template_name.cfg file and + // redefine those $image['xxx'] you want. Note: Many phpBB images are reused all over mxBB (eg see below), thus if you redefine + // common phpBB images, this will have immedaite effect for all mxBB pages. + // + */ + function mx_img($img, $alt = '', $width = false, $suffix = '', $type = 'full_tag') + { + static $imgs; + global $phpbb_root_path, $mx_root_path, $mx_images; + + // + // Load phpBB Template configuration data + // - First try current template + // + if ( file_exists( $phpbb_root_path . $this->current_template_path . "/images" ) ) + { + $current_template_path = $this->current_template_path; + $template_name = $this->template_name; + + @include($phpbb_root_path . $this->current_template_path . '/' . $this->template_name . '.cfg'); + } + + // + // Since we have no current Template Config file, try the cloned template instead + // + if ( file_exists( $phpbb_root_path . $this->cloned_current_template_path . "/images" ) && !defined('TEMPLATE_CONFIG') ) + { + $current_template_path = $this->cloned_current_template_path; + $template_name = $this->cloned_template_name; + + @include($phpbb_root_path . $this->cloned_current_template_path . '/' . $this->cloned_template_name . '.cfg'); + } + + // + // Last attempt, use default template intead + // + if ( file_exists( $phpbb_root_path . $this->default_current_template_path . "/images" ) && !defined('TEMPLATE_CONFIG') ) + { + $current_template_path = $this->default_current_template_path; + $template_name = $this->default_template_name; + + @include($phpbb_root_path . $this->default_current_template_path . '/' . $this->default_template_name . '.cfg'); + } + + $this->img_lang = (file_exists($phpbb_root_path . $current_template_path . $this->lang_name)) ? $this->lang_name : $board_config['default_lang']; + + /* Here we overwrite phpBB images from the template configuration file with images from database */ + + $this->img_array['image_filename'] = array( + 'img_site_logo' => "logo.gif", + 'img_upload_bar' => "upload_bar.gif", + 'img_icon_contact_aim' => "icon_aim.gif", + 'img_icon_contact_email' => "icon_email.gif", + 'img_icon_contact_icq' => "icon_icq_add.gif", + 'img_icon_contact_jabber' => "icon_jabber.gif", + 'img_icon_contact_msnm' => "icon_msnm.gif", + 'img_icon_contact_pm' => "icon_pm.gif", + 'img_icon_contact_yahoo' => "icon_yim.gif", + 'img_icon_contact_www' => "icon_www.gif", + 'img_icon_post_delete' => "icon_delete.gif", + 'img_icon_post_edit' => "icon_edit.gif", + 'img_icon_post_info' => "icon_info.gif", + 'img_icon_post_quote' => "icon_quote.gif", + 'img_icon_post_report' => "icon_report.gif", + 'img_icon_user_online' => "icon_online.gif", + 'img_icon_user_offline' => "icon_offline.gif", + 'img_icon_user_profile' => "icon_profile.gif", + 'img_icon_user_search' => "icon_search.gif", + 'img_icon_user_warn' => "icon_warn.gif", + 'img_button_pm_forward' => "reply.gif", + 'img_button_pm_new' => "msg_newpost.gif", + 'img_button_pm_reply' => "reply.gif", + 'img_button_topic_locked' => "msg_newpost.gif", + 'img_button_topic_new' => "post.gif", + 'img_button_topic_reply' => "reply.gif", + 'img_forum_link' => "forum_link.gif", + 'img_forum_read' => "forum_read.gif", + 'img_forum_read_locked' => "forum_read_locked.gif", + 'img_forum_read_subforum' => "forum_read_subforum.gif", + 'img_forum_unread' => "forum_unread.gif", + 'img_forum_unread_locked' => "forum_unread_locked.gif", + 'img_forum_unread_subforum' => "forum_unread_subforum.gif", + 'img_topic_moved' => "topic_moved.gif", + 'img_topic_read' => "topic_read.gif", + 'img_topic_read_mine' => "topic_read_mine.gif", + 'img_topic_read_hot' => "topic_read_hot.gif", + 'img_topic_read_hot_mine' => "topic_read_hot_mine.gif", + 'img_topic_read_locked' => "topic_read_locked.gif", + 'img_topic_read_locked_mine' => "topic_read_locked_mine.gif", + 'img_topic_unread' => "topic_unread.gif", + 'img_topic_unread_mine' => "topic_unread_mine.gif", + 'img_topic_unread_hot' => "topic_unread_hot.gif", + 'img_topic_unread_hot_mine' => "topic_unread_hot_mine.gif", + 'img_topic_unread_locked' => "topic_unread_locked.gif", + 'img_topic_unread_locked_mine' => "topic_unread_locked_mine.gif", + 'img_sticky_read' => "sticky_read.gif", + 'img_sticky_read_mine' => "sticky_read_mine.gif", + 'img_sticky_read_locked' => "sticky_read_locked.gif", + 'img_sticky_read_locked_mine' => "ticky_read_locked_mine.gif", + 'img_sticky_unread' => "sticky_unread.gif", + 'img_sticky_unread_mine' => "sticky_unread_mine.gif", + 'img_sticky_unread_locked' => "sticky_unread_locked.gif", + 'img_sticky_unread_locked_mine' => "sticky_unread_locked_mine.gif", + 'img_announce_read' => "announce_read.gif", + 'img_announce_read_mine' => "announce_read_mine.gif", + 'img_announce_read_locked' => "announce_read_locked.gif", + 'img_announce_read_locked_mine' => "announce_read_locked_mine.gif", + 'img_announce_unread' => "announce_unread.gif", + 'img_announce_unread_mine' => "announce_unread_mine.gif", + 'img_announce_unread_locked' => "announce_unread_locked.gif", + 'img_announce_unread_locked_mine' => "announce_unread_locked_mine.gif", + 'img_global_read' => "announce_read.gif", + 'img_global_read_mine' => "announce_read_mine.gif", + 'img_global_read_locked' => "announce_read_locked.gif", + 'img_global_read_locked_mine' => "announce_read_locked_mine.gif", + 'img_global_unread' => "announce_unread.gif", + 'img_global_unread_mine' => "announce_unread_mine.gif", + 'img_global_unread_locked' => "announce_unread_locked.gif", + 'img_global_unread_locked_mine' => "announce_unread_locked_mine.gif", + 'img_subforum_read' => "", + 'img_subforum_unread' => "", + 'img_pm_read' => "topic_read.gif", + 'img_pm_unread' => "topic_unread.gif", + 'img_icon_back_top' => "", + 'img_icon_post_target' => "icon_post_target.gif", + 'img_icon_post_target_unread' => "icon_post_target_unread.gif", + 'img_icon_topic_attach' => "icon_topic_attach.gif", + 'img_icon_topic_latest' => "icon_topic_latest.gif", + 'img_icon_topic_newest' => "icon_topic_newest.gif", + 'img_icon_topic_reported' => "icon_topic_reported.gif", + 'img_icon_topic_unapproved' => "icon_topic_unapproved.gif" + ); + + $this->img_array['image_lang'] = array( + 'img_icon_post_edit' => $this->img_lang, + 'img_icon_post_quote' => $this->img_lang, + 'img_button_pm_forward' => $this->img_lang, + 'img_button_pm_new' => $this->img_lang, + 'img_button_pm_reply' => $this->img_lang, + 'img_button_topic_new' => $this->img_lang, + 'img_button_topic_reply' => $this->img_lang + ); + + $img_data = &$imgs[$img]; + + if (empty($img_data)) + { + if (!isset($this->img_array[$img])) + { + // Do not fill the image to let designers decide what to do if the image is empty + $img_data = ''; + return $img_data; + } + + $img_data['src'] = PHPBB_URL . $current_template_path . ($this->img_array[$img]['image_lang'] ? $this->img_array[$img]['image_lang'] .'/' : '') . $this->img_array[$img]['image_filename']; + $img_data['width'] = (!empty($width)) ? $width : ''; //$this->img_array[$img]['image_width']; + $img_data['height'] = (!empty($height)) ? $height : ''; //$this->img_array[$img]['image_height']; + } + + $alt = (!empty($this->lang[$alt])) ? $this->lang[$alt] : $alt; + + switch ($type) + { + case 'src': + return $img_data['src']; + break; + + case 'width': + return ($width === false) ? $img_data['width'] : $width; + break; + + case 'height': + return $img_data['height']; + break; + + default: + $use_width = ($width === false) ? $img_data['width'] : $width; + + return '
'; + break; + } + } + + /** + * Get option bit field from user options + */ + function optionget($key, $data = false) + { + if (!isset($this->keyvalues[$key])) + { + $var = ($data) ? $data : '230271'; //$this->data['user_options']; + $this->keyvalues[$key] = ($var & 1 << $this->keyoptions[$key]) ? true : false; + } + + return $this->keyvalues[$key]; + } + + /** + * Set option bit field for user options + */ + function optionset($key, $value, $data = false) + { + $var = ($data) ? $data : '230271'; //$this->data['user_options']; + + if ($value && !($var & 1 << $this->keyoptions[$key])) + { + $var += 1 << $this->keyoptions[$key]; + } + else if (!$value && ($var & 1 << $this->keyoptions[$key])) + { + $var -= 1 << $this->keyoptions[$key]; + } + else + { + return ($data) ? $var : false; + } + + if (!$data) + { + $this->data['user_options'] = $var; + return true; + } + else + { + return $var; + } + } + + /** + * Load available languages list + * author: Jan Kalah aka culprit_cz + * @return array available languages list: KEY = folder name + */ + function get_lang_list($ext_root_path = '') + { + if (count($this->language_list)) + { + return $this->language_list; + } + /* c:\Wamp\www\Rhea\language\ */ + $dir = opendir($this->phpbb_root_path . 'language/'); + while($f = readdir($dir)) + { + if (($f == '.' || $f == '..') || !is_dir($this->phpbb_root_path . 'language/' . $f)) + { + continue; + } + $this->language_list[$f] = $this->ucstrreplace('lang_', '', $f); + } + closedir($dir); + if (!empty($ext_root_path)) + { + $dir = opendir($this->phpbb_root_path . 'ext/' . $ext_root_path . '/language/'); + while($f = readdir($dir)) + { + if (($f == '.' || $f == '..') || !is_dir($this->phpbb_root_path . 'ext/' . $ext_root_path . '/language/' . $f)) + { + continue; + } + $this->ext_language_list[$f] = $this->ucstrreplace('lang_', '', $f); + } + closedir($dir); + return $this->language_list = array_merge($this->ext_language_list, $this->language_list); + } + return $this->language_list; + } + + /** + * encode_lang + * + * This function is used with phpBB2 backend to specify xml:lang in overall headers (only two chars are allowed) + * Do not change! + * + * $default_lang = $mx_user->encode_lang($board_config['default_lang']); + * + * @param unknown_type $lang + * @return unknown + */ + function encode_lang($lang) + { + switch($lang) + { + case 'afar': + $lang_name = 'aa'; + break; + case 'abkhazian': + $lang_name = 'ab'; + break; + case 'avestan': + $lang_name = 'ae'; + break; + case 'afrikaans': + $lang_name = 'af'; + break; + case 'akan': + $lang_name = 'ak'; + break; + case 'amharic': + $lang_name = 'am'; + break; + case 'aragonese': + $lang_name = 'an'; + break; + case 'arabic': + $lang_name = 'ar'; + break; + case 'assamese': + $lang_name = 'as'; + break; + case 'avaric': + $lang_name = 'av'; + break; + case 'aymara': + $lang_name = 'ay'; + break; + case 'azerbaijani': + $lang_name = 'az'; + break; + case 'bashkir': + $lang_name = 'ba'; + break; + case 'belarusian': + $lang_name = 'be'; + break; + case 'bulgarian': + $lang_name = 'bg'; + break; + case 'bihari': + $lang_name = 'bh'; + break; + case 'bislama': + $lang_name = 'bi'; + break; + case 'bambara': + $lang_name = 'bm'; + break; + case 'bengali': + $lang_name = 'bn'; + break; + case 'tibetan': + $lang_name = 'bo'; + break; + case 'breton': + $lang_name = 'br'; + break; + case 'bosnian': + $lang_name = 'bs'; + break; + case 'catalan': + $lang_name = 'ca'; + break; + case 'chechen': + $lang_name = 'ce'; + break; + case 'chamorro': + $lang_name = 'ch'; + break; + case 'corsican': + $lang_name = 'co'; + break; + case 'cree': + $lang_name = 'cr'; + break; + case 'czech': + $lang_name = 'cs'; + break; + case 'slavonic': + $lang_name = 'cu'; + break; + case 'chuvash': + $lang_name = 'cv'; + break; + case 'welsh_cymraeg': + $lang_name = 'cy'; + break; + case 'danish': + $lang_name = 'da'; + break; + case 'german': + $lang_name = 'de'; + break; + case 'divehi': + $lang_name = 'dv'; + break; + case 'dzongkha': + $lang_name = 'dz'; + break; + case 'ewe': + $lang_name = 'ee'; + break; + case 'greek': + $lang_name = 'el'; + break; + case 'hebrew': + $lang_name = 'he'; + break; + case 'english': + $lang_name = 'en'; + break; + case 'english_us': + $lang_name = 'en_us'; + break; + case 'esperanto': + $lang_name = 'eo'; + break; + case 'spanish': + $lang_name = 'es'; + break; + case 'estonian': + $lang_name = 'et'; + break; + case 'basque': + $lang_name = 'eu'; + break; + case 'persian': + $lang_name = 'fa'; + break; + case 'fulah': + $lang_name = 'ff'; + break; + case 'finnish': + $lang_name = 'fi'; + break; + case 'fijian': + $lang_name = 'fj'; + break; + case 'faroese': + $lang_name = 'fo'; + break; + case 'french': + $lang_name = 'fr'; + break; + case 'frisian': + $lang_name = 'fy'; + break; + case 'irish': + $lang_name = 'ga'; + break; + case 'scottish': + $lang_name = 'gd'; + break; + case 'galician': + $lang_name = 'gl'; + break; + case 'guaraní': + $lang_name = 'gn'; + break; + case 'gujarati': + $lang_name = 'gu'; + break; + case 'manx': + $lang_name = 'gv'; + break; + case 'hausa': + $lang_name = 'ha'; + break; + case 'hebrew': + $lang_name = 'he'; + break; + case 'hindi': + $lang_name = 'hi'; + break; + case 'hiri_motu': + $lang_name = 'ho'; + break; + case 'croatian': + $lang_name = 'hr'; + break; + case 'haitian': + $lang_name = 'ht'; + break; + case 'hungarian': + $lang_name = 'hu'; + break; + case 'armenian': + $lang_name = 'hy'; + break; + case 'herero': + $lang_name = 'hz'; + break; + case 'interlingua': + $lang_name = 'ia'; + break; + case 'indonesian': + $lang_name = 'id'; + break; + case 'interlingue': + $lang_name = 'ie'; + break; + case 'igbo': + $lang_name = 'ig'; + break; + case 'sichuan_yi': + $lang_name = 'ii'; + break; + case 'inupiaq': + $lang_name = 'ik'; + break; + case 'ido': + $lang_name = 'io'; + break; + case 'icelandic': + $lang_name = 'is'; + break; + case 'italian': + $lang_name = 'it'; + break; + case 'inuktitut': + $lang_name = 'iu'; + break; + case 'japanese': + $lang_name = 'ja'; + break; + case 'javanese': + $lang_name = 'jv'; + break; + case 'georgian': + $lang_name = 'ka'; + break; + case 'kongo': + $lang_name = 'kg'; + break; + case 'kikuyu': + $lang_name = 'ki'; + break; + case 'kwanyama': + $lang_name = 'kj'; + break; + case 'kazakh': + $lang_name = 'kk'; + break; + case 'kalaallisut': + $lang_name = 'kl'; + break; + case 'khmer': + $lang_name = 'km'; + break; + case 'kannada': + $lang_name = 'kn'; + break; + case 'korean': + $lang_name = 'ko'; + break; + case 'kanuri': + $lang_name = 'kr'; + break; + case 'kashmiri': + $lang_name = 'ks'; + break; + case 'kurdish': + $lang_name = 'ku'; + break; + case 'kv': + $lang_name = 'komi'; + break; + case 'cornish_kernewek': + $lang_name = 'kw'; + break; + case 'kirghiz': + $lang_name = 'ky'; + break; + case 'latin': + $lang_name = 'la'; + break; + case 'luxembourgish': + $lang_name = 'lb'; + break; + case 'ganda': + $lang_name = 'lg'; + break; + case 'limburgish': + $lang_name = 'li'; + break; + case 'lingala': + $lang_name = 'ln'; + break; + case 'lao': + $lang_name = 'lo'; + break; + case 'lithuanian': + $lang_name = 'lt'; + break; + case 'luba-katanga': + $lang_name = 'lu'; + break; + case 'latvian': + $lang_name = 'lv'; + break; + case 'malagasy': + $lang_name = 'mg'; + break; + case 'marshallese': + $lang_name = 'mh'; + break; + case 'maori': + $lang_name = 'mi'; + break; + case 'macedonian': + $lang_name = 'mk'; + break; + case 'malayalam': + $lang_name = 'ml'; + break; + case 'mongolian': + $lang_name = 'mn'; + break; + case 'moldavian': + $lang_name = 'mo'; + break; + case 'marathi': + $lang_name = 'mr'; + break; + case 'malay': + $lang_name = 'ms'; + break; + case 'maltese': + $lang_name = 'mt'; + break; + case 'burmese': + $lang_name = 'my'; + break; + case 'nauruan': + $lang_name = 'na'; + break; + case 'norwegian': + $lang_name = 'nb'; + break; + case 'ndebele': + $lang_name = 'nd'; + break; + case 'nepali': + $lang_name = 'ne'; + break; + case 'ndonga': + $lang_name = 'ng'; + break; + case 'dutch': + $lang_name = 'nl'; + break; + case 'norwegian_nynorsk': + $lang_name = 'nn'; + break; + case 'norwegian': + $lang_name = 'no'; + break; + case 'southern_ndebele': + $lang_name = 'nr'; + break; + case 'navajo': + $lang_name = 'nv'; + break; + case 'chichewa': + $lang_name = 'ny'; + break; + case 'occitan': + $lang_name = 'oc'; + break; + case 'ojibwa': + $lang_name = 'oj'; + break; + case 'oromo': + $lang_name = 'om'; + break; + case 'oriya': + $lang_name = 'or'; + break; + case 'ossetian': + $lang_name = 'os'; + break; + case 'panjabi': + $lang_name = 'pa'; + break; + case 'pali': + $lang_name = 'pi'; + break; + case 'polish': + $lang_name = 'pl'; + break; + case 'pashto': + $lang_name = 'ps'; + break; + case 'portuguese': + $lang_name = 'pt'; + break; + case 'portuguese_brasil': + $lang_name = 'pt_br'; + break; + case 'quechua': + $lang_name = 'qu'; + break; + case 'romansh': + $lang_name = 'rm'; + break; + case 'kirundi': + $lang_name = 'rn'; + break; + case 'romanian': + $lang_name = 'ro'; + break; + case 'russian': + $lang_name = 'ru'; + break; + case 'kinyarwanda': + $lang_name = 'rw'; + break; + case 'sanskrit': + $lang_name = 'sa'; + break; + case 'sardinian': + $lang_name = 'sc'; + break; + case 'sindhi': + $lang_name = 'sd'; + break; + case 'northern_sami': + $lang_name = 'se'; + break; + case 'sango': + $lang_name = 'sg'; + break; + case 'serbo-croatian': + $lang_name = 'sh'; + break; + case 'sinhala': + $lang_name = 'si'; + break; + case 'slovak': + $lang_name = 'sk'; + break; + case 'slovenian': + $lang_name = 'sl'; + break; + case 'samoan': + $lang_name = 'sm'; + break; + case 'shona': + $lang_name = 'sn'; + break; + case 'somali': + $lang_name = 'so'; + break; + case 'albanian': + $lang_name = 'sq'; + break; + case 'serbian': + $lang_name = 'sr'; + break; + case 'swati': + $lang_name = 'ss'; + break; + case 'sotho': + $lang_name = 'st'; + break; + case 'sundanese': + $lang_name = 'su'; + break; + case 'swedish': + $lang_name = 'sv'; + break; + case 'swahili': + $lang_name = 'sw'; + break; + case 'tamil': + $lang_name = 'ta'; + break; + case 'telugu': + $lang_name = 'te'; + break; + case 'tajik': + $lang_name = 'tg'; + break; + case 'thai': + $lang_name = 'th'; + break; + case 'tigrinya': + $lang_name = 'ti'; + break; + case 'turkmen': + $lang_name = 'tk'; + break; + case 'tagalog': + $lang_name = 'tl'; + break; + case 'tswana': + $lang_name = 'tn'; + break; + case 'tonga': + $lang_name = 'to'; + break; + case 'turkish': + $lang_name = 'tr'; + break; + case 'tsonga': + $lang_name = 'ts'; + break; + case 'tatar': + $lang_name = 'tt'; + break; + case 'twi': + $lang_name = 'tw'; + break; + case 'tahitian': + $lang_name = 'ty'; + break; + case 'uighur': + $lang_name = 'ug'; + break; + case 'ukrainian': + $lang_name = 'uk'; + break; + case 'urdu': + $lang_name = 'ur'; + break; + case 'uzbek': + $lang_name = 'uz'; + break; + case 'venda': + $lang_name = 've'; + break; + case 'vietnamese': + $lang_name = 'vi'; + break; + case 'volapuk': + $lang_name = 'vo'; + break; + case 'walloon': + $lang_name = 'wa'; + break; + case 'wolof': + $lang_name = 'wo'; + break; + case 'xhosa': + $lang_name = 'xh'; + break; + case 'yiddish': + $lang_name = 'yi'; + break; + case 'yoruba': + $lang_name = 'yo'; + break; + case 'zhuang': + $lang_name = 'za'; + break; + case 'chinese': + $lang_name = 'zh'; + break; + case 'chinese_simplified': + $lang_name = 'zh_cmn_hans'; + break; + case 'chinese_traditional': + $lang_name = 'zh_cmn_hant'; + break; + case 'zulu': + $lang_name = 'zu'; + break; + default: + $lang_name = $lang; + break; + } + return $lang_name; + } + + /** + * decode_lang + * + * $default_lang = $mx_user->decode_lang($board_config['default_lang']); + * @used in URL Language Detection i.e. $this->decode_lang($_GET['lang']) + * @param iso_type $lang + * @return standard_type $lang + */ + function decode_lang($lang) + { + switch($lang) + { + case 'aa': + $lang_name = 'afar'; + break; + case 'ab': + $lang_name = 'abkhazian'; + break; + case 'ae': + $lang_name = 'avestan'; + break; + case 'af': + $lang_name = 'afrikaans'; + break; + case 'ak': + $lang_name = 'akan'; + break; + case 'am': + $lang_name = 'amharic'; + break; + case 'an': + $lang_name = 'aragonese'; + break; + case 'ar': + $lang_name = 'arabic'; + break; + case 'as': + $lang_name = 'assamese'; + break; + case 'av': + $lang_name = 'avaric'; + break; + case 'ay': + $lang_name = 'aymara'; + break; + case 'az': + $lang_name = 'azerbaijani'; + break; + case 'ba': + $lang_name = 'bashkir'; + break; + case 'be': + $lang_name = 'belarusian'; + break; + case 'bg': + $lang_name = 'bulgarian'; + break; + case 'bh': + $lang_name = 'bihari'; + break; + case 'bi': + $lang_name = 'bislama'; + break; + case 'bm': + $lang_name = 'bambara'; + break; + case 'bn': + $lang_name = 'bengali'; + break; + case 'bo': + $lang_name = 'tibetan'; + break; + case 'br': + $lang_name = 'breton'; + break; + case 'bs': + $lang_name = 'bosnian'; + break; + case 'ca': + $lang_name = 'catalan'; + break; + case 'ce': + $lang_name = 'chechen'; + break; + case 'ch': + $lang_name = 'chamorro'; + break; + case 'co': + $lang_name = 'corsican'; + break; + case 'cr': + $lang_name = 'cree'; + break; + case 'cs': + $lang_name = 'czech'; + break; + case 'cu': + $lang_name = 'slavonic'; + break; + case 'cv': + $lang_name = 'chuvash'; + break; + case 'cy': + $lang_name = 'welsh_cymraeg'; + break; + case 'da': + $lang_name = 'danish'; + break; + case 'de': + $lang_name = 'german'; + break; + case 'dv': + $lang_name = 'divehi'; + break; + case 'dz': + $lang_name = 'dzongkha'; + break; + case 'ee': + $lang_name = 'ewe'; + break; + case 'el': + $lang_name = 'greek'; + break; + case 'he': + $lang_name = 'hebrew'; + break; + case 'en': + $lang_name = 'english'; + break; + case 'en_us': + $lang_name = 'english'; + break; + case 'eo': + $lang_name = 'esperanto'; + break; + case 'es': + $lang_name = 'spanish'; + break; + case 'et': + $lang_name = 'estonian'; + break; + case 'eu': + $lang_name = 'basque'; + break; + case 'fa': + $lang_name = 'persian'; + break; + case 'ff': + $lang_name = 'fulah'; + break; + case 'fi': + $lang_name = 'finnish'; + break; + case 'fj': + $lang_name = 'fijian'; + break; + case 'fo': + $lang_name = 'faroese'; + break; + case 'fr': + $lang_name = 'french'; + break; + case 'fy': + $lang_name = 'frisian'; + break; + case 'ga': + $lang_name = 'irish'; + break; + case 'gd': + $lang_name = 'scottish'; + break; + case 'gl': + $lang_name = 'galician'; + break; + case 'gn': + $lang_name = 'guaraní'; + break; + case 'gu': + $lang_name = 'gujarati'; + break; + case 'gv': + $lang_name = 'manx'; + break; + case 'ha': + $lang_name = 'hausa'; + break; + case 'he': + $lang_name = 'hebrew'; + break; + case 'hi': + $lang_name = 'hindi'; + break; + case 'ho': + $lang_name = 'hiri_motu'; + break; + case 'hr': + $lang_name = 'croatian'; + break; + case 'ht': + $lang_name = 'haitian'; + break; + case 'hu': + $lang_name = 'hungarian'; + break; + case 'hy': + $lang_name = 'armenian'; + break; + case 'hz': + $lang_name = 'herero'; + break; + case 'ia': + $lang_name = 'interlingua'; + break; + case 'id': + $lang_name = 'indonesian'; + break; + case 'ie': + $lang_name = 'interlingue'; + break; + case 'ig': + $lang_name = 'igbo'; + break; + case 'ii': + $lang_name = 'sichuan_yi'; + break; + case 'ik': + $lang_name = 'inupiaq'; + break; + case 'io': + $lang_name = 'ido'; + break; + case 'is': + $lang_name = 'icelandic'; + break; + case 'it': + $lang_name = 'italian'; + break; + case 'iu': + $lang_name = 'inuktitut'; + break; + case 'ja': + $lang_name = 'japanese'; + break; + case 'jv': + $lang_name = 'javanese'; + break; + case 'ka': + $lang_name = 'georgian'; + break; + case 'kg': + $lang_name = 'kongo'; + break; + case 'ki': + $lang_name = 'kikuyu'; + break; + case 'kj': + $lang_name = 'kwanyama'; + break; + case 'kk': + $lang_name = 'kazakh'; + break; + case 'kl': + $lang_name = 'kalaallisut'; + break; + case 'km': + $lang_name = 'khmer'; + break; + case 'kn': + $lang_name = 'kannada'; + break; + case 'ko': + $lang_name = 'korean'; + break; + case 'kr': + $lang_name = 'kanuri'; + break; + case 'ks': + $lang_name = 'kashmiri'; + break; + case 'ku': + $lang_name = 'kurdish'; + break; + case 'kv': + $lang_name = 'komi'; + break; + case 'kw': + $lang_name = 'cornish_kernewek'; + break; + case 'ky': + $lang_name = 'kirghiz'; + break; + case 'la': + $lang_name = 'latin'; + break; + case 'lb': + $lang_name = 'luxembourgish'; + break; + case 'lg': + $lang_name = 'ganda'; + break; + case 'li': + $lang_name = 'limburgish'; + break; + case 'ln': + $lang_name = 'lingala'; + break; + case 'lo': + $lang_name = 'lao'; + break; + case 'lt': + $lang_name = 'lithuanian'; + break; + case 'lu': + $lang_name = 'luba-katanga'; + break; + case 'lv': + $lang_name = 'latvian'; + break; + case 'mg': + $lang_name = 'malagasy'; + break; + case 'mh': + $lang_name = 'marshallese'; + break; + case 'mi': + $lang_name = 'maori'; + break; + case 'mk': + $lang_name = 'macedonian'; + break; + case 'ml': + $lang_name = 'malayalam'; + break; + case 'mn': + $lang_name = 'mongolian'; + break; + case 'mo': + $lang_name = 'moldavian'; + break; + case 'mr': + $lang_name = 'marathi'; + break; + case 'ms': + $lang_name = 'malay'; + break; + case 'mt': + $lang_name = 'maltese'; + break; + case 'my': + $lang_name = 'burmese'; + break; + case 'na': + $lang_name = 'nauruan'; + break; + case 'nb': + $lang_name = 'norwegian'; + break; + case 'nd': + $lang_name = 'ndebele'; + break; + case 'ne': + $lang_name = 'nepali'; + break; + case 'ng': + $lang_name = 'ndonga'; + break; + case 'nl': + $lang_name = 'dutch'; + break; + case 'nn': + $lang_name = 'norwegian_nynorsk'; + break; + case 'no': + $lang_name = 'norwegian'; + break; + case 'nr': + $lang_name = 'southern_ndebele'; + break; + case 'nv': + $lang_name = 'navajo'; + break; + case 'ny': + $lang_name = 'chichewa'; + break; + case 'oc': + $lang_name = 'occitan'; + break; + case 'oj': + $lang_name = 'ojibwa'; + break; + case 'om': + $lang_name = 'oromo'; + break; + case 'or': + $lang_name = 'oriya'; + break; + case 'os': + $lang_name = 'ossetian'; + break; + case 'pa': + $lang_name = 'panjabi'; + break; + case 'pi': + $lang_name = 'pali'; + break; + case 'pl': + $lang_name = 'polish'; + break; + case 'ps': + $lang_name = 'pashto'; + break; + case 'pt': + $lang_name = 'portuguese'; + break; + case 'pt_br': + $lang_name = 'portuguese_brasil'; + break; + case 'qu': + $lang_name = 'quechua'; + break; + case 'rm': + $lang_name = 'romansh'; + break; + case 'rn': + $lang_name = 'kirundi'; + break; + case 'ro': + $lang_name = 'romanian'; + break; + case 'ru': + $lang_name = 'russian'; + break; + case 'rw': + $lang_name = 'kinyarwanda'; + break; + case 'sa': + $lang_name = 'sanskrit'; + break; + case 'sc': + $lang_name = 'sardinian'; + break; + case 'sd': + $lang_name = 'sindhi'; + break; + case 'se': + $lang_name = 'northern_sami'; + break; + case 'sg': + $lang_name = 'sango'; + break; + case 'sh': + $lang_name = 'serbo-croatian'; + break; + case 'si': + $lang_name = 'sinhala'; + break; + case 'sk': + $lang_name = 'slovak'; + break; + case 'sl': + $lang_name = 'slovenian'; + break; + case 'sm': + $lang_name = 'samoan'; + break; + case 'sn': + $lang_name = 'shona'; + break; + case 'so': + $lang_name = 'somali'; + break; + case 'sq': + $lang_name = 'albanian'; + break; + case 'sr': + $lang_name = 'serbian'; + break; + case 'ss': + $lang_name = 'swati'; + break; + case 'st': + $lang_name = 'sotho'; + break; + case 'su': + $lang_name = 'sundanese'; + break; + case 'sv': + $lang_name = 'swedish'; + break; + case 'sw': + $lang_name = 'swahili'; + break; + case 'ta': + $lang_name = 'tamil'; + break; + case 'te': + $lang_name = 'telugu'; + break; + case 'tg': + $lang_name = 'tajik'; + break; + case 'th': + $lang_name = 'thai'; + break; + case 'ti': + $lang_name = 'tigrinya'; + break; + case 'tk': + $lang_name = 'turkmen'; + break; + case 'tl': + $lang_name = 'tagalog'; + break; + case 'tn': + $lang_name = 'tswana'; + break; + case 'to': + $lang_name = 'tonga'; + break; + case 'tr': + $lang_name = 'turkish'; + break; + case 'ts': + $lang_name = 'tsonga'; + break; + case 'tt': + $lang_name = 'tatar'; + break; + case 'tw': + $lang_name = 'twi'; + break; + case 'ty': + $lang_name = 'tahitian'; + break; + case 'ug': + $lang_name = 'uighur'; + break; + case 'uk': + $lang_name = 'ukrainian'; + break; + case 'ur': + $lang_name = 'urdu'; + break; + case 'uz': + $lang_name = 'uzbek'; + break; + case 've': + $lang_name = 'venda'; + break; + case 'vi': + $lang_name = 'vietnamese'; + break; + case 'vo': + $lang_name = 'volapuk'; + break; + case 'wa': + $lang_name = 'walloon'; + break; + case 'wo': + $lang_name = 'wolof'; + break; + case 'xh': + $lang_name = 'xhosa'; + break; + case 'yi': + $lang_name = 'yiddish'; + break; + case 'yo': + $lang_name = 'yoruba'; + break; + case 'za': + $lang_name = 'zhuang'; + break; + case 'zh': + $lang_name = 'chinese'; + break; + case 'zh_cmn_hans': + $lang_name = 'chinese_simplified'; + break; + case 'zh_cmn_hant': + $lang_name = 'chinese_traditional'; + break; + case 'zu': + $lang_name = 'zulu'; + break; + default: + $lang_name = $lang; + break; } - - return $this->keyvalues[$key]; + return $lang_name; } - - /** - * Set option bit field for user options - */ - function optionset($key, $value, $data = false) - { - $var = ($data) ? $data : $this->data['user_options']; - - if ($value && !($var & 1 << $this->keyoptions[$key])) - { - $var += 1 << $this->keyoptions[$key]; - } - else if (!$value && ($var & 1 << $this->keyoptions[$key])) - { - $var -= 1 << $this->keyoptions[$key]; - } - else - { - return ($data) ? $var : false; - } - - if (!$data) - { - $this->data['user_options'] = $var; - return true; - } - else - { - return $var; - } - } - + /** - * encode_lang - * - * This function is used with internal backend to specify xml:lang in overall headers (only two chars are allowed) - * This function can be also used to convert the user_lang oe default_lang to be undestend by tiny_mce like in mx_contact module - * Do not change! + * ucstrreplace * - * 'L_TINY_MCE_LANGUAGE' => $mx_user->encode_lang($board_config['default_lang']), + * $lang_local_name = $user->ucstrreplace($board_config['default_lang']); * * @param unknown_type $lang * @return unknown */ - function encode_lang($lang) + function ucstrreplace($pattern = '%{$regex}%i', $matches = '', $string) { - switch($lang) + /* return with no uppercase if patern not in string */ + if (strpos($string, $pattern) === false) + { + /* known languages */ + switch($string) { - case 'afar': - $lang_name = 'aa'; + case 'aa': + $lang_name = 'afar'; break; - case 'abkhazian': - $lang_name = 'ab'; + case 'ab': + $lang_name = 'abkhazian'; break; - case 'avestan': - $lang_name = 'ae'; + case 'ae': + $lang_name = 'avestan'; break; - case 'afrikaans': - $lang_name = 'af'; + case 'af': + $lang_name = 'afrikaans'; break; - case 'akan': - $lang_name = 'ak'; + case 'ak': + $lang_name = 'akan'; break; - case 'amharic': - $lang_name = 'am'; + case 'am': + $lang_name = 'amharic'; break; - case 'aragonese': - $lang_name = 'an'; + case 'an': + $lang_name = 'aragonese'; break; - case 'arabic': - $lang_name = 'ar'; + case 'ar': + $lang_name = 'arabic'; break; - case 'assamese': - $lang_name = 'as'; + case 'as': + $lang_name = 'assamese'; break; - case 'avaric': - $lang_name = 'av'; + case 'av': + $lang_name = 'avaric'; break; - case 'aymara': - $lang_name = 'ay'; + case 'ay': + $lang_name = 'aymara'; break; - case 'azerbaijani': - $lang_name = 'az'; + case 'az': + $lang_name = 'azerbaijani'; break; - case 'bashkir': - $lang_name = 'ba'; + case 'ba': + $lang_name = 'bashkir'; break; - case 'belarusian': - $lang_name = 'be'; + case 'be': + $lang_name = 'belarusian'; break; - case 'bulgarian': - $lang_name = 'bg'; + case 'bg': + $lang_name = 'bulgarian'; break; - case 'bihari': - $lang_name = 'bh'; + case 'bh': + $lang_name = 'bihari'; break; - case 'bislama': - $lang_name = 'bi'; + case 'bi': + $lang_name = 'bislama'; break; - case 'bambara': - $lang_name = 'bm'; + case 'bm': + $lang_name = 'bambara'; break; - case 'bengali': - $lang_name = 'bn'; + case 'bn': + $lang_name = 'bengali'; break; - case 'tibetan': - $lang_name = 'bo'; + case 'bo': + $lang_name = 'tibetan'; break; - case 'breton': - $lang_name = 'br'; + case 'br': + $lang_name = 'breton'; break; - case 'bosnian': - $lang_name = 'bs'; + case 'bs': + $lang_name = 'bosnian'; break; - case 'catalan': - $lang_name = 'ca'; + case 'ca': + $lang_name = 'catalan'; break; - case 'chechen': - $lang_name = 'ce'; + case 'ce': + $lang_name = 'chechen'; break; - case 'chamorro': - $lang_name = 'ch'; + case 'ch': + $lang_name = 'chamorro'; break; - case 'corsican': - $lang_name = 'co'; + case 'co': + $lang_name = 'corsican'; break; - case 'cree': - $lang_name = 'cr'; + case 'cr': + $lang_name = 'cree'; break; - case 'czech': - $lang_name = 'cs'; + case 'cs': + $lang_name = 'czech'; break; - case 'slavonic': - $lang_name = 'cu'; + case 'cu': + $lang_name = 'slavonic'; break; - case 'chuvash': - $lang_name = 'cv'; + case 'cv': + $lang_name = 'chuvash'; break; - case 'welsh_cymraeg': - $lang_name = 'cy'; + case 'cy': + $lang_name = 'welsh_cymraeg'; break; - case 'danish': - $lang_name = 'da'; + case 'da': + $lang_name = 'danish'; break; - case 'german': - $lang_name = 'de'; + case 'de': + $lang_name = 'german'; break; - case 'divehi': - $lang_name = 'dv'; + case 'dv': + $lang_name = 'divehi'; break; - case 'dzongkha': - $lang_name = 'dz'; + case 'dz': + $lang_name = 'dzongkha'; break; - case 'ewe': - $lang_name = 'ee'; + case 'ee': + $lang_name = 'ewe'; break; - case 'greek': - $lang_name = 'el'; + case 'el': + $lang_name = 'greek'; break; - case 'hebrew': - $lang_name = 'he'; + case 'he': + $lang_name = 'hebrew'; break; - case 'english': - $lang_name = 'en'; + case '{LANG}': + $lang_name = 'english'; break; - case 'english_us': - $lang_name = 'en_us'; + case 'en_us': + $lang_name = 'english'; break; - case 'esperanto': - $lang_name = 'eo'; + case 'eo': + $lang_name = 'esperanto'; break; - case 'spanish': - $lang_name = 'es'; + case 'es': + $lang_name = 'spanish'; break; - case 'estonian': - $lang_name = 'et'; + case 'et': + $lang_name = 'estonian'; break; - case 'basque': - $lang_name = 'eu'; + case 'eu': + $lang_name = 'basque'; break; - case 'persian': - $lang_name = 'fa'; + case 'fa': + $lang_name = 'persian'; break; - case 'fulah': - $lang_name = 'ff'; + case 'ff': + $lang_name = 'fulah'; break; - case 'finnish': - $lang_name = 'fi'; + case 'fi': + $lang_name = 'finnish'; break; - case 'fijian': - $lang_name = 'fj'; + case 'fj': + $lang_name = 'fijian'; break; - case 'faroese': - $lang_name = 'fo'; + case 'fo': + $lang_name = 'faroese'; break; - case 'french': - $lang_name = 'fr'; + case 'fr': + $lang_name = 'french'; break; - case 'frisian': - $lang_name = 'fy'; + case 'fy': + $lang_name = 'frisian'; break; - case 'irish': - $lang_name = 'ga'; + case 'ga': + $lang_name = 'irish'; break; - case 'scottish': - $lang_name = 'gd'; + case 'gd': + $lang_name = 'scottish'; break; - case 'galician': - $lang_name = 'gl'; + case 'gl': + $lang_name = 'galician'; break; - case 'guaraní': - $lang_name = 'gn'; + case 'gn': + $lang_name = 'guaraní'; break; - case 'gujarati': - $lang_name = 'gu'; + case 'gu': + $lang_name = 'gujarati'; break; - case 'manx': - $lang_name = 'gv'; + case 'gv': + $lang_name = 'manx'; break; - case 'hausa': - $lang_name = 'ha'; + case 'ha': + $lang_name = 'hausa'; break; - case 'hebrew': - $lang_name = 'he'; + case 'he': + $lang_name = 'hebrew'; break; - case 'hindi': - $lang_name = 'hi'; + case 'hi': + $lang_name = 'hindi'; break; - case 'hiri_motu': - $lang_name = 'ho'; + case 'ho': + $lang_name = 'hiri_motu'; break; - case 'croatian': - $lang_name = 'hr'; + case 'hr': + $lang_name = 'croatian'; break; - case 'haitian': - $lang_name = 'ht'; + case 'ht': + $lang_name = 'haitian'; break; - case 'hungarian': - $lang_name = 'hu'; + case 'hu': + $lang_name = 'hungarian'; break; - case 'armenian': - $lang_name = 'hy'; + case 'hy': + $lang_name = 'armenian'; break; - case 'herero': - $lang_name = 'hz'; + case 'hz': + $lang_name = 'herero'; break; - case 'interlingua': - $lang_name = 'ia'; + case 'ia': + $lang_name = 'interlingua'; break; - case 'indonesian': - $lang_name = 'id'; + case 'id': + $lang_name = 'indonesian'; break; - case 'interlingue': - $lang_name = 'ie'; + case 'ie': + $lang_name = 'interlingue'; break; - case 'igbo': - $lang_name = 'ig'; + case 'ig': + $lang_name = 'igbo'; break; - case 'sichuan_yi': - $lang_name = 'ii'; + case 'ii': + $lang_name = 'sichuan_yi'; break; - case 'inupiaq': - $lang_name = 'ik'; + case 'ik': + $lang_name = 'inupiaq'; break; - case 'ido': - $lang_name = 'io'; + case 'io': + $lang_name = 'ido'; break; - case 'icelandic': - $lang_name = 'is'; + case 'is': + $lang_name = 'icelandic'; break; - case 'italian': - $lang_name = 'it'; + case 'it': + $lang_name = 'italian'; break; - case 'inuktitut': - $lang_name = 'iu'; + case 'iu': + $lang_name = 'inuktitut'; break; - case 'japanese': - $lang_name = 'ja'; + case 'ja': + $lang_name = 'japanese'; break; - case 'javanese': - $lang_name = 'jv'; + case 'jv': + $lang_name = 'javanese'; break; - case 'georgian': - $lang_name = 'ka'; + case 'ka': + $lang_name = 'georgian'; break; - case 'kongo': - $lang_name = 'kg'; + case 'kg': + $lang_name = 'kongo'; break; - case 'kikuyu': - $lang_name = 'ki'; + case 'ki': + $lang_name = 'kikuyu'; break; - case 'kwanyama': - $lang_name = 'kj'; + case 'kj': + $lang_name = 'kwanyama'; break; - case 'kazakh': - $lang_name = 'kk'; + case 'kk': + $lang_name = 'kazakh'; break; - case 'kalaallisut': - $lang_name = 'kl'; + case 'kl': + $lang_name = 'kalaallisut'; break; - case 'khmer': - $lang_name = 'km'; + case 'km': + $lang_name = 'khmer'; break; - case 'kannada': - $lang_name = 'kn'; + case 'kn': + $lang_name = 'kannada'; break; - case 'korean': - $lang_name = 'ko'; + case 'ko': + $lang_name = 'korean'; break; - case 'kanuri': - $lang_name = 'kr'; + case 'kr': + $lang_name = 'kanuri'; break; - case 'kashmiri': - $lang_name = 'ks'; + case 'ks': + $lang_name = 'kashmiri'; break; - case 'kurdish': - $lang_name = 'ku'; + case 'ku': + $lang_name = 'kurdish'; break; case 'kv': $lang_name = 'komi'; break; - case 'cornish_kernewek': - $lang_name = 'kw'; + case 'kw': + $lang_name = 'cornish_kernewek'; break; - case 'kirghiz': - $lang_name = 'ky'; + case 'ky': + $lang_name = 'kirghiz'; break; - case 'latin': - $lang_name = 'la'; + case 'la': + $lang_name = 'latin'; break; - case 'luxembourgish': - $lang_name = 'lb'; + case 'lb': + $lang_name = 'luxembourgish'; break; - case 'ganda': - $lang_name = 'lg'; + case 'lg': + $lang_name = 'ganda'; break; - case 'limburgish': - $lang_name = 'li'; + case 'li': + $lang_name = 'limburgish'; break; - case 'lingala': - $lang_name = 'ln'; + case 'ln': + $lang_name = 'lingala'; break; - case 'lao': - $lang_name = 'lo'; + case 'lo': + $lang_name = 'lao'; break; - case 'lithuanian': - $lang_name = 'lt'; + case 'lt': + $lang_name = 'lithuanian'; break; - case 'luba-katanga': - $lang_name = 'lu'; + case 'lu': + $lang_name = 'luba-katanga'; break; - case 'latvian': - $lang_name = 'lv'; + case 'lv': + $lang_name = 'latvian'; break; - case 'malagasy': - $lang_name = 'mg'; + case 'mg': + $lang_name = 'malagasy'; break; - case 'marshallese': - $lang_name = 'mh'; + case 'mh': + $lang_name = 'marshallese'; break; - case 'maori': - $lang_name = 'mi'; + case 'mi': + $lang_name = 'maori'; break; - case 'macedonian': - $lang_name = 'mk'; + case 'mk': + $lang_name = 'macedonian'; break; - case 'malayalam': - $lang_name = 'ml'; + case 'ml': + $lang_name = 'malayalam'; break; - case 'mongolian': - $lang_name = 'mn'; + case 'mn': + $lang_name = 'mongolian'; break; - case 'moldavian': - $lang_name = 'mo'; + case 'mo': + $lang_name = 'moldavian'; break; - case 'marathi': - $lang_name = 'mr'; + case 'mr': + $lang_name = 'marathi'; break; - case 'malay': - $lang_name = 'ms'; + case 'ms': + $lang_name = 'malay'; break; - case 'maltese': - $lang_name = 'mt'; + case 'mt': + $lang_name = 'maltese'; break; - case 'burmese': - $lang_name = 'my'; + case 'my': + $lang_name = 'burmese'; break; - case 'nauruan': - $lang_name = 'na'; + case 'na': + $lang_name = 'nauruan'; break; - case 'norwegian': - $lang_name = 'nb'; + case 'nb': + $lang_name = 'norwegian'; break; - case 'ndebele': - $lang_name = 'nd'; + case 'nd': + $lang_name = 'ndebele'; break; - case 'nepali': - $lang_name = 'ne'; + case 'ne': + $lang_name = 'nepali'; break; - case 'ndonga': - $lang_name = 'ng'; + case 'ng': + $lang_name = 'ndonga'; break; - case 'dutch': - $lang_name = 'nl'; + case 'nl': + $lang_name = 'dutch'; break; - case 'norwegian_nynorsk': - $lang_name = 'nn'; + case 'nn': + $lang_name = 'norwegian_nynorsk'; break; - case 'norwegian': - $lang_name = 'no'; + case 'no': + $lang_name = 'norwegian'; break; - case 'southern_ndebele': - $lang_name = 'nr'; + case 'nr': + $lang_name = 'southern_ndebele'; break; - case 'navajo': - $lang_name = 'nv'; + case 'nv': + $lang_name = 'navajo'; break; - case 'chichewa': - $lang_name = 'ny'; + case 'ny': + $lang_name = 'chichewa'; break; - case 'occitan': - $lang_name = 'oc'; + case 'oc': + $lang_name = 'occitan'; break; - case 'ojibwa': - $lang_name = 'oj'; + case 'oj': + $lang_name = 'ojibwa'; break; - case 'oromo': - $lang_name = 'om'; + case 'om': + $lang_name = 'oromo'; break; - case 'oriya': - $lang_name = 'or'; + case 'or': + $lang_name = 'oriya'; break; - case 'ossetian': - $lang_name = 'os'; + case 'os': + $lang_name = 'ossetian'; break; - case 'panjabi': - $lang_name = 'pa'; + case 'pa': + $lang_name = 'panjabi'; break; - case 'pali': - $lang_name = 'pi'; + case 'pi': + $lang_name = 'pali'; break; - case 'polish': - $lang_name = 'pl'; + case 'pl': + $lang_name = 'polish'; break; - case 'pashto': - $lang_name = 'ps'; + case 'ps': + $lang_name = 'pashto'; break; - case 'portuguese': - $lang_name = 'pt'; + case 'pt': + $lang_name = 'portuguese'; break; - case 'portuguese_brasil': - $lang_name = 'pt_br'; + case 'pt_br': + $lang_name = 'portuguese_brasil'; break; - case 'quechua': - $lang_name = 'qu'; + case 'qu': + $lang_name = 'quechua'; break; - case 'romansh': - $lang_name = 'rm'; + case 'rm': + $lang_name = 'romansh'; break; - case 'kirundi': - $lang_name = 'rn'; + case 'rn': + $lang_name = 'kirundi'; break; - case 'romanian': - $lang_name = 'ro'; + case 'ro': + $lang_name = 'romanian'; break; - case 'russian': - $lang_name = 'ru'; + case 'ru': + $lang_name = 'russian'; break; - case 'kinyarwanda': - $lang_name = 'rw'; + case 'rw': + $lang_name = 'kinyarwanda'; break; - case 'sanskrit': - $lang_name = 'sa'; + case 'sa': + $lang_name = 'sanskrit'; break; - case 'sardinian': - $lang_name = 'sc'; + case 'sc': + $lang_name = 'sardinian'; break; - case 'sindhi': - $lang_name = 'sd'; + case 'sd': + $lang_name = 'sindhi'; break; - case 'northern_sami': - $lang_name = 'se'; + case 'se': + $lang_name = 'northern_sami'; break; - case 'sango': - $lang_name = 'sg'; + case 'sg': + $lang_name = 'sango'; break; - case 'serbo-croatian': - $lang_name = 'sh'; + case 'sh': + $lang_name = 'serbo-croatian'; break; - case 'sinhala': - $lang_name = 'si'; + case 'si': + $lang_name = 'sinhala'; break; - case 'slovak': - $lang_name = 'sk'; + case 'sk': + $lang_name = 'slovak'; break; - case 'slovenian': - $lang_name = 'sl'; + case 'sl': + $lang_name = 'slovenian'; break; - case 'samoan': - $lang_name = 'sm'; + case 'sm': + $lang_name = 'samoan'; break; - case 'shona': - $lang_name = 'sn'; + case 'sn': + $lang_name = 'shona'; break; - case 'somali': - $lang_name = 'so'; + case 'so': + $lang_name = 'somali'; break; - case 'albanian': - $lang_name = 'sq'; + case 'sq': + $lang_name = 'albanian'; break; - case 'serbian': - $lang_name = 'sr'; + case 'sr': + $lang_name = 'serbian'; break; - case 'swati': - $lang_name = 'ss'; + case 'ss': + $lang_name = 'swati'; break; - case 'sotho': - $lang_name = 'st'; + case 'st': + $lang_name = 'sotho'; break; - case 'sundanese': - $lang_name = 'su'; + case 'su': + $lang_name = 'sundanese'; break; - case 'swedish': - $lang_name = 'sv'; + case 'sv': + $lang_name = 'swedish'; break; - case 'swahili': - $lang_name = 'sw'; + case 'sw': + $lang_name = 'swahili'; break; - case 'tamil': - $lang_name = 'ta'; + case 'ta': + $lang_name = 'tamil'; break; - case 'telugu': - $lang_name = 'te'; + case 'te': + $lang_name = 'telugu'; break; - case 'tajik': - $lang_name = 'tg'; + case 'tg': + $lang_name = 'tajik'; break; - case 'thai': - $lang_name = 'th'; + case 'th': + $lang_name = 'thai'; break; - case 'tigrinya': - $lang_name = 'ti'; + case 'ti': + $lang_name = 'tigrinya'; break; - case 'turkmen': - $lang_name = 'tk'; + case 'tk': + $lang_name = 'turkmen'; break; - case 'tagalog': - $lang_name = 'tl'; + case 'tl': + $lang_name = 'tagalog'; break; - case 'tswana': - $lang_name = 'tn'; + case 'tn': + $lang_name = 'tswana'; break; - case 'tonga': - $lang_name = 'to'; + case 'to': + $lang_name = 'tonga'; break; - case 'turkish': - $lang_name = 'tr'; + case 'tr': + $lang_name = 'turkish'; break; - case 'tsonga': - $lang_name = 'ts'; + case 'ts': + $lang_name = 'tsonga'; break; - case 'tatar': - $lang_name = 'tt'; + case 'tt': + $lang_name = 'tatar'; break; - case 'twi': - $lang_name = 'tw'; + case 'tw': + $lang_name = 'twi'; break; - case 'tahitian': - $lang_name = 'ty'; + case 'ty': + $lang_name = 'tahitian'; break; - case 'uighur': - $lang_name = 'ug'; + case 'ug': + $lang_name = 'uighur'; break; - case 'ukrainian': - $lang_name = 'uk'; + case 'uk': + $lang_name = 'ukrainian'; break; - case 'urdu': - $lang_name = 'ur'; + case 'ur': + $lang_name = 'urdu'; break; - case 'uzbek': - $lang_name = 'uz'; + case 'uz': + $lang_name = 'uzbek'; break; - case 'venda': - $lang_name = 've'; + case 've': + $lang_name = 'venda'; break; - case 'vietnamese': - $lang_name = 'vi'; + case 'vi': + $lang_name = 'vietnamese'; break; - case 'volapuk': - $lang_name = 'vo'; + case 'vo': + $lang_name = 'volapuk'; break; - case 'walloon': - $lang_name = 'wa'; + case 'wa': + $lang_name = 'walloon'; break; - case 'wolof': - $lang_name = 'wo'; + case 'wo': + $lang_name = 'wolof'; break; - case 'xhosa': - $lang_name = 'xh'; + case 'xh': + $lang_name = 'xhosa'; break; - case 'yiddish': - $lang_name = 'yi'; + case 'yi': + $lang_name = 'yiddish'; break; - case 'yoruba': - $lang_name = 'yo'; + case 'yo': + $lang_name = 'yoruba'; break; - case 'zhuang': - $lang_name = 'za'; + case 'za': + $lang_name = 'zhuang'; break; - case 'chinese': - $lang_name = 'zh'; + case 'zh': + $lang_name = 'chinese'; break; - case 'chinese_simplified': - $lang_name = 'zh_cmn_hans'; + case 'zh_cmn_hans': + $lang_name = 'chinese_simplified'; break; - case 'chinese_traditional': - $lang_name = 'zh_cmn_hant'; + case 'zh_cmn_hant': + $lang_name = 'chinese_traditional'; break; - case 'zulu': - $lang_name = 'zu'; + case 'zu': + $lang_name = 'zulu'; break; default: - $lang_name = $lang; - break; - } - return $lang_name; - } - - /** - * decode_lang - * - * $default_lang = $mx_user->decode_lang($board_config['default_lang']); - * - * @param unknown_type $lang - * @return unknown - */ - function decode_lang($lang) - { - return $lang; - } -} + $lang_name = (strlen($string) > 2) ? ucfirst(str_replace($pattern, '', $string)) : $string; + break; + } + return ucwords(str_replace(array(" ","-","_"), ' ', $lang_name)); + } + return ucwords(str_replace(array(" ","-","_"), ' ', str_replace($pattern, '', $string))); + } +} // -// Append $SID to a url. Borrowed from phplib and modified. This is an -// extra routine utilised by the session code above and acts as a wrapper -// around every single URL and form action. If you replace the session -// code you must include this routine, even if it's empty. +//Moved to functions.php +//This file is sometime included for this function +//and so we keep it here for phpBB2 backend // -function append_sid($url, $non_html_amp = false) +if (!function_exists('append_sid')) { - global $SID; - - if ( !empty($SID) && !preg_match('#sid=#', $url) ) + // + // Append $SID to a url. Borrowed from phplib and modified. This is an + // extra routine utilised by the session code above and acts as a wrapper + // around every single URL and form action. If you replace the session + // code you must include this routine, even if it's empty. + // + function phpbb_append_sid($url, $non_html_amp = false) { - $url .= ( ( strpos($url, '?') !== false ) ? ( ( $non_html_amp ) ? '&' : '&' ) : '?' ) . $SID; - } + global $SID; - return $url; + if ( !empty($SID) && !preg_match('#sid=#', $url) ) + { + $url .= ((strpos($url, '?') !== false) ? (($non_html_amp) ? '&' : '&') : '?') . $SID; + } + + return $url; + } } ?> \ No newline at end of file diff --git a/includes/sessions/mybb/CVS/Entries b/includes/sessions/mybb/CVS/Entries new file mode 100644 index 00000000..17848105 --- /dev/null +++ b/includes/sessions/mybb/CVS/Entries @@ -0,0 +1 @@ +D diff --git a/includes/sessions/mybb/CVS/Entries.Extra b/includes/sessions/mybb/CVS/Entries.Extra new file mode 100644 index 00000000..e69de29b diff --git a/includes/sessions/mybb/CVS/Entries.Extra.Old b/includes/sessions/mybb/CVS/Entries.Extra.Old new file mode 100644 index 00000000..e69de29b diff --git a/includes/sessions/mybb/CVS/Entries.Old b/includes/sessions/mybb/CVS/Entries.Old new file mode 100644 index 00000000..e69de29b diff --git a/includes/sessions/mybb/CVS/Repository b/includes/sessions/mybb/CVS/Repository new file mode 100644 index 00000000..a0c756df --- /dev/null +++ b/includes/sessions/mybb/CVS/Repository @@ -0,0 +1 @@ +core/includes/sessions/mybb diff --git a/includes/sessions/mybb/CVS/Root b/includes/sessions/mybb/CVS/Root new file mode 100644 index 00000000..6ab1483d --- /dev/null +++ b/includes/sessions/mybb/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@mxbb.cvs.sourceforge.net:/cvsroot/mxbb diff --git a/includes/sessions/olympus/core.php b/includes/sessions/olympus/core.php index 7d7f8eb6..3fcfb837 100644 --- a/includes/sessions/olympus/core.php +++ b/includes/sessions/olympus/core.php @@ -194,7 +194,7 @@ function validate_backend() global $table_prefix, $phpEx, $tplEx; $table_prefix = false; - + $tplEx = 'html'; // Define relative path to phpBB, and validate $phpbb_root_path = $mx_root_path . $portal_config['portal_backend_path']; str_replace("//", "/", $phpbb_root_path); @@ -206,9 +206,6 @@ function validate_backend() die('Configuration file (config) ' . $phpbb_root_path . "config.$phpEx" . ' couldn\'t be opened.'); } - // Define backend template extension - $tplEx = 'html'; - // Validate db connection for backend $_result = $db->sql_query("SELECT config_value from " . $table_prefix . "config WHERE config_name = 'cookie_domain'"); $portal_backend_valid_db = $db->sql_numrows($_result) != 0; @@ -246,7 +243,10 @@ function setup_backend() $server_url_phpbb = $server_protocol . $server_name . $server_port . $script_name_phpbb; define('PHPBB_URL', $server_url_phpbb); - + + // Define backend template extension + $tplEx = 'html'; + if (!defined('TPL_EXT')) define('TPL_EXT', $tplEx); // // Now sync Configs // In phpBB mode, we rely on native phpBB configs, thus we need to sync mxp and phpbb settings @@ -707,64 +707,286 @@ function page_tail($mode = false) } } + /** - * Enter description here... + * obtain_phpbb_config * * @access public * @param boolean $use_cache * @return unknown */ - function obtain_phpbb_config($use_cache = true) + public function obtain_forum_config() { - global $db, $phpbb_root_path, $table_prefix, $mx_cache, $phpEx; - - if (($config = $mx_cache->get('phpbb_config')) && ($use_cache) ) + global $db, $mx_cache, $phpEx; + + if (!defined('CONFIG_TABLE')) { - return $config; + global $table_prefix, $mx_root_path; + + require $mx_root_path. "includes/sessions/phpbb2/constants.$phpEx"; + } + + if (($mx_cache->get('phpbb_config')) === false) + { + $config = $cached_config = array(); + + $sql = 'SELECT config_name, config_value, is_dynamic + FROM ' . CONFIG_TABLE; + if (!($result = $db->sql_query($sql))) + { + if (!function_exists('mx_message_die')) + { + die("Couldnt query config information, Allso this hosting or server is using a cache optimizer not compatible with MX-Publisher or just lost connection to database wile query."); + } + else + { + mx_message_die( GENERAL_ERROR, 'Couldnt query config information', '', __LINE__, __FILE__, $sql ); + } + } + + while ($row = $db->sql_fetchrow($result)) + { + if (!$row['is_dynamic']) + { + $cached_config[$row['config_name']] = $row['config_value']; + } + + $config[$row['config_name']] = $row['config_value']; + } + $db->sql_freeresult($result); + + $mx_cache->put('phpbb_config', $cached_config); } else - { - if (!defined('CONFIG_TABLE')) + { + $sql = 'SELECT config_name, config_value + FROM ' . CONFIG_TABLE . ' + WHERE is_dynamic = 1'; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) { - global $table_prefix, $mx_root_path; - - require $mx_root_path. "includes/sessions/phpbb3/constants.$phpEx"; + $config[$row['config_name']] = $row['config_value']; } + $db->sql_freeresult($result); + } + + return $config; + } + + /** + * Set phpbb config values + * + * @param unknown_type $config_name + * @param unknown_type $config_value + */ + public function set_forum_config($key, $new_value, $use_cache = false) + { + global $db, $mx_cache, $phpEx; + + if (!defined('CONFIG_TABLE')) + { + global $table_prefix, $mx_root_path; + + require $mx_root_path. "includes/sessions/phpbb2/constants.$phpEx"; + } + + // Read out config values + $config = $this->obtain_phpbb_config(); + $old_value = !isset($config[$key]) ? $config[$key] : false; + $use_cache = (($key == 'comments_pagination') || ($key == 'pagination')) ? true : false; + + $sql = 'UPDATE ' . CONFIG_TABLE . " + SET config_value = '" . $db->sql_escape($new_value) . "' + WHERE config_name = '" . $db->sql_escape($key) . "'"; + + if ($old_value !== false) + { + $sql .= " AND config_value = '" . $db->sql_escape($old_value) . "'"; + } + + $db->sql_query($sql); + + if (!$db->sql_affectedrows() && isset($config[$key])) + { + return false; + } + + if (!isset($config[$key])) + { + $sql = 'INSERT INTO ' . CONFIG_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'config_name' => $key, + 'config_value' => $new_value)), + 'is_dynamic' => ($use_cache) ? 0 : 1)); + $db->sql_query($sql); + } + + $config[$key] = $new_value; + + + if ($use_cache) + { + $mx_cache->destroy('config'); + $mx_cache->put('config', $config); + } + + return true; + } + + /** + * Get MX-Publisher config data + * + * @access public + * @return unknown + */ + public function obtain_portal_config($use_cache = true) + { + global $db, $mx_cache; + if ( ($portal_config = $mx_cache->get('mx_config')) && ($use_cache) ) + { + return $portal_config; + } + else + { $sql = "SELECT * - FROM " . CONFIG_TABLE; + FROM " . PORTAL_TABLE . " + WHERE portal_id = '1'"; - if ( !( $result = $db->sql_query( $sql ) ) ) + if ( !($result = $db->sql_query($sql)) ) { if (!function_exists('mx_message_die')) { - die("Couldnt query config information, Allso this hosting or server is using a cache optimizer not compatible with MX-Publisher or just lost connection to database wile query."); + die("Couldnt query portal configuration, Allso this hosting or server is using a cache optimizer not compatible with MX-Publisher or just lost connection to database wile query."); } else { - mx_message_die( GENERAL_ERROR, 'Couldnt query config information', '', __LINE__, __FILE__, $sql ); + mx_message_die( GENERAL_ERROR, 'Couldnt query portal configuration', '', __LINE__, __FILE__, $sql ); } } - - while ( $row = $db->sql_fetchrow($result) ) + $row = $db->sql_fetchrow($result); + foreach ($row as $config_name => $config_value) { - $config[$row['config_name']] = $row['config_value']; + $portal_config[$config_name] = trim($config_value); } $db->sql_freeresult($result); + $mx_cache->put('mx_config', $portal_config); + + return ($portal_config); + } + } + + /** + * Set config value. Creates missing config entry. + * + */ + function set_portal_config($key, $new_value) + { + global $db, $mx_cache, $portal_config; + + // Read out config values + $portal_config = $this->obtain_portal_config(); + + $new[$key] = $new_value; + + $sql = "UPDATE " . PORTAL_TABLE . " SET " . $db->sql_build_array('UPDATE', utf8_normalize_nfc($new)); + + if( !($db->sql_query($sql)) ) + { + mx_message_die(GENERAL_ERROR, "Failed to update portal configuration ", "", __LINE__, __FILE__, $sql); + } + + if (!$db->sql_affectedrows() && !isset($portal_config[$key])) + { + $sql = 'INSERT INTO ' . PORTAL_TABLE . ' ' . $db->sql_build_array('INSERT', array( + $db->sql_escape($key) => $db->sql_escape($new_value))); + $db->sql_query($sql); + } + + $portal_config[$key] = $new_value; + + $mx_cache->destroy('mx_config'); + } + + /** + * Get userdata + * + * Get Userdata, $mx_user can be username or user_id. If force_str is true, the username will be forced. + * Cached sql, since this function is used for every block. + * + * @param unknown_type $mx_user id or name + * @param boolean $force_str force clean_username + * @return array + */ + function get_userdata($mxuser, $force_str = false) + { + global $db, $phpBB2; + + if (!is_numeric($mxuser) || $force_str) + { + $mx_user = $phpBB2->phpbb_clean_username($mxuser); + } + else + { + $mx_user = intval($mxuser); + } - if ($use_cache) + $sql = "SELECT * + FROM " . USERS_TABLE . " + WHERE "; + $sql .= ((is_integer($mxuser)) ? "user_id = $mxuser" : "username = '" . str_replace("\'", "''", $mxuser) . "'" ) . " AND user_id <> " . ANONYMOUS; + if (!($result = $db->sql_query($sql, 120))) + { + if (!function_exists('mx_message_die')) { - $mx_cache->put('phpbb_config', $config); + die("Tried obtaining data for a non-existent user. Function mx_backend->get_userdata()"); } + else + { + mx_message_die(GENERAL_ERROR, 'Tried obtaining data for a non-existent user', '', __LINE__, __FILE__, $sql); + } + } + $return = ($row = $db->sql_fetchrow($result)) ? $row : false; + /* + foreach ($row as $user_key => $user_value) + { + $userdata[$user_key] = trim($user_value); + } + */ + $db->sql_freeresult($result); + //return ($userdata); + return $return; + } + + /** + * Set user data value. + * + */ + function set_userdata($key, $new_value) + { + global $db, $mx_user; + + $new[$key] = $new_value; - return ( $config ); + $sql = "UPDATE " . USERS_TABLE . " SET " . $db->sql_build_array('UPDATE', utf8_normalize_nfc($new)); + + if( !($db->sql_query($sql)) ) + { + mx_message_die(GENERAL_ERROR, "Failed to update portal configuration ", "", __LINE__, __FILE__, $sql); + } + + if (!$db->sql_affectedrows() && !isset($mx_user->data[$key])) + { + mx_message_die(GENERAL_ERROR, "Wrong Backend? Adding missing entry key to update MXP configuration is not supported ATM.", "", __LINE__, __FILE__, $sql); } - } + $mx_user->data[$key] = $new_value; + } + /** * Obtain ranks */ - function obtain_ranks() + public function obtain_ranks() { global $mx_cache; diff --git a/includes/sessions/olympus/functions.php b/includes/sessions/olympus/functions.php index 6826cb7d..444bb1f0 100644 --- a/includes/sessions/olympus/functions.php +++ b/includes/sessions/olympus/functions.php @@ -228,6 +228,7 @@ function mx_get_username_string($mode, $user_id, $username, $username_colour = ' switch ($mode) { + case 'profile_url': case 'profile': return $profile_url; break; diff --git a/includes/sessions/phpbb2/CVS/Entries b/includes/sessions/phpbb2/CVS/Entries new file mode 100644 index 00000000..7db222b4 --- /dev/null +++ b/includes/sessions/phpbb2/CVS/Entries @@ -0,0 +1,9 @@ +/auth.php/1.4/Fri Jun 28 15:33:47 2013// +/bbcode.php/1.4/Fri Jun 28 15:33:47 2013// +/constants.php/1.6/Fri Jun 28 15:33:47 2013// +/core.php/1.29/Fri May 16 18:02:23 2014// +/functions.php/1.2/Fri Jun 28 15:33:47 2013// +/index.htm/1.1/Wed Feb 13 21:43:19 2008// +/login.php/1.9/Fri Jun 28 15:33:47 2013// +/session.php/1.18/Fri May 9 07:52:03 2014// +D diff --git a/includes/sessions/phpbb2/CVS/Entries.Extra b/includes/sessions/phpbb2/CVS/Entries.Extra new file mode 100644 index 00000000..1e3b89e7 --- /dev/null +++ b/includes/sessions/phpbb2/CVS/Entries.Extra @@ -0,0 +1,8 @@ +/auth.php////*//// +/bbcode.php////*//// +/constants.php////*//// +/core.php////*//// +/functions.php////*//// +/index.htm////*//// +/login.php////*//// +/session.php////*//// diff --git a/includes/sessions/phpbb2/CVS/Entries.Extra.Old b/includes/sessions/phpbb2/CVS/Entries.Extra.Old new file mode 100644 index 00000000..e69de29b diff --git a/includes/sessions/phpbb2/CVS/Entries.Old b/includes/sessions/phpbb2/CVS/Entries.Old new file mode 100644 index 00000000..e69de29b diff --git a/includes/sessions/phpbb2/CVS/Repository b/includes/sessions/phpbb2/CVS/Repository new file mode 100644 index 00000000..a8b39a04 --- /dev/null +++ b/includes/sessions/phpbb2/CVS/Repository @@ -0,0 +1 @@ +core/includes/sessions/phpbb2 diff --git a/includes/sessions/phpbb2/CVS/Root b/includes/sessions/phpbb2/CVS/Root new file mode 100644 index 00000000..6ab1483d --- /dev/null +++ b/includes/sessions/phpbb2/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@mxbb.cvs.sourceforge.net:/cvsroot/mxbb diff --git a/includes/sessions/phpbb2/bbcode.php b/includes/sessions/phpbb2/bbcode.php index 5ec1ab4c..121c9d38 100644 --- a/includes/sessions/phpbb2/bbcode.php +++ b/includes/sessions/phpbb2/bbcode.php @@ -2,7 +2,7 @@ /** * * @package Functions_phpBB -* @version $Id: bbcode.php,v 1.4 2013/06/28 15:33:47 orynider Exp $ +* @version $Id: bbcode.php,v 1.5 2013/09/04 04:32:35 orynider Exp $ * @copyright (c) 2002-2008 MX-Publisher Project Team * @license http://opensource.org/licenses/gpl-license.php GNU General Public License v2 * @link http://mxpcms.sourceforge.net/ @@ -19,6 +19,7 @@ // include_once($mx_root_path . 'includes/mx_functions_bbcode.' . $phpEx); // BBCode associated functions + /** * MXP BBcodes * @package MX-Publisher @@ -69,21 +70,47 @@ function mx_bbcode($bitfield = '') * @param boolean $smilies_on * @return string */ - function decode($bbtext, $bbcode_uid, $smilies_on = true) + function decode($mytext, $bbcode_uid, $smilies_on = true, $bbcode_bitfield = false) { global $mx_root_path, $phpbb_root_path, $phpEx, $mx_page; - - $mytext = stripslashes($bbtext); + + if (!$mytext) + { + return ''; + } + + $mytext = mx_censor_text($mytext); + + //Do some checks + $phpbb3_text = $bbcode_bitfield ? true : false; + $bbcode_bitfield = ($bbcode_bitfield && (strlen($bbcode_bitfield) < 2)) ? false : $bbcode_bitfield; + if (!empty($bbcode_uid)) { - $mytext = $this->bbencode_second_pass($mytext, $bbcode_uid); + $mytext = $this->bbencode_second_pass($mytext, $bbcode_uid, $bbcode_bitfield); } - if ($smilies_on) + + $mytext = str_replace(array("\n", "\r"), array('
', "\n"), $mytext); + $mytext = $this->bbcode_nl2br($mytext); + + //$mytext = smiley_text($mytext, !($flags & OPTION_FLAG_SMILIES)); + if ($smilies_on && $phpbb3_text) + { + $mytext = $this->smilies3_pass($mytext); + } + else if ($smilies_on) { $mytext = $this->smilies_pass($mytext); } - $mytext = str_replace("\n", "\n
\n", $mytext); - return $this->make_clickable($mytext); + + //$mytext = str_replace("\n", "\n
\n", $mytext); + + if ($mytext != '') + { + $mytext = $this->make_clickable($mytext); + } + + return $mytext; } // @@ -92,8 +119,15 @@ function decode($bbtext, $bbcode_uid, $smilies_on = true) // function prepare_message($message, $html_on, $bbcode_on, $smile_on, $bbcode_uid = 0) { - global $board_config, $html_entities_match, $html_entities_replace; + global $board_config, $mx_bbcode, $mx_root_path, $phpEx, $html_entities_match, $html_entities_replace; + // + // Instantiate the mx_text class + // + include_once($mx_root_path . 'includes/mx_functions_tools.'.$phpEx); + $mx_text = new mx_text(); + $mx_text->init($html_on, $bbcode_on, $smile_on); + // // Clean up the message // @@ -116,7 +150,7 @@ function prepare_message($message, $html_on, $bbcode_on, $smile_on, $bbcode_uid foreach ($message_split as $part) { $tag = array(array_shift($matches[0]), array_shift($matches[1]), array_shift($matches[2])); - $message .= preg_replace($html_entities_match, $html_entities_replace, $part) . clean_html($tag); + $message .= preg_replace($html_entities_match, $html_entities_replace, $part) . $mx_text->clean_html($tag); } $message = addslashes($message); @@ -134,7 +168,818 @@ function prepare_message($message, $html_on, $bbcode_on, $smile_on, $bbcode_uid return $message; } + + /** + * Second pass bbcodes + */ + function bbcode_second_pass(&$message, $bbcode_uid = '', $bbcode_bitfield = false) + { + if ($bbcode_uid) + { + $this->bbcode_uid = $bbcode_uid; + } + + if ($bbcode_bitfield !== false) + { + //$this->bbcode_bitfield = $bbcode_bitfield; + + // Init those added with a new bbcode_bitfield (already stored codes will not get parsed again) + $this->bbcode_cache_init(); + } + + //We are called from a Core block or non phpBB3, this should never be riched only when function is called direct + if (!$this->bbcode_bitfield) + { + // Remove the uid from tags that have not been transformed into HTML + /* + if ($this->bbcode_uid) + { + $message = str_replace(':' . $this->bbcode_uid, '', $message); + } + */ + return; + } + + $str = array('search' => array(), 'replace' => array()); + $preg = array('search' => array(), 'replace' => array()); + + $bitfield = new bitfield($this->bbcode_bitfield); + $bbcodes_set = $bitfield->get_all_set(); + + $undid_bbcode_specialchars = false; + foreach ($bbcodes_set as $bbcode_id) + { + if (!empty($this->bbcode_cache[$bbcode_id])) + { + foreach ($this->bbcode_cache[$bbcode_id] as $type => $array) + { + foreach ($array as $search => $replace) + { + ${$type}['search'][] = str_replace('$uid', $this->bbcode_uid, $search); + ${$type}['replace'][] = $replace; + } + + if (sizeof($str['search'])) + { + $message = str_replace($str['search'], $str['replace'], $message); + $str = array('search' => array(), 'replace' => array()); + } + + if (sizeof($preg['search'])) + { + // we need to turn the entities back into their original form to allow the + // search patterns to work properly + if (!$undid_bbcode_specialchars) + { + $message = str_replace(array(':', '.'), array(':', '.'), $message); + $undid_bbcode_specialchars = true; + } + + $message = preg_replace($preg['search'], $preg['replace'], $message); + $preg = array('search' => array(), 'replace' => array()); + } + } + } + } + + // Remove the uid from tags that have not been transformed into HTML + $message = str_replace(':' . $this->bbcode_uid, '', $message); + } + + /** + * Return bbcode template + */ + function bbcode_tpl($tpl_name, $bbcode_id = -1, $skip_bitfield_check = false) + { + static $bbcode_hardtpl = array(); + if (empty($bbcode_hardtpl)) + { + global $mx_user; + + $bbcode_hardtpl = array( + 'b_open' => '', + 'b_close' => '', + 'i_open' => '', + 'i_close' => '', + 'ipaper_open' => '', + 'ipaper_close' => '', + 'u_open' => '', + 'u_close' => '', + 'img' => '', + 'size' => '$2', + 'color' => '$2', + 'email' => '$2', + 'table' => ' ', + 'tr' => '{TEXT}
{TEXT} ', + 'th' => '{TEXT} ', + 'td' => '{TEXT} ', + 'thead' => '{TEXT}', + 'tbody' => '{TEXT}', + 'center' => '{TEXT}', + 'align' => '{TEXT}', + 'float' => '{TEXT}', + 'fa' => '', + ); + } + + if ($bbcode_id != -1 && !$skip_bitfield_check && !$this->template_bitfield->get($bbcode_id)) + { + return (isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false; + } + + if (empty($this->bbcode_template)) + { + if (($tpl = file_get_contents($this->template_filename)) === false) + { + trigger_error('Could not load bbcode template', E_USER_ERROR); + } + + // replace \ with \\ and then ' with \'. + $tpl = str_replace('\\', '\\\\', $tpl); + $tpl = str_replace("'", "\'", $tpl); + + // strip newlines and indent + $tpl = preg_replace("/\n[\n\r\s\t]*/", '', $tpl); + + // Turn template blocks into PHP assignment statements for the values of $bbcode_tpl.. + $this->bbcode_template = array(); + + $matches = preg_match_all('#(.*?)#', $tpl, $match); + + for ($i = 0; $i < $matches; $i++) + { + if (empty($match[1][$i])) + { + continue; + } + + $this->bbcode_template[$match[1][$i]] = $this->bbcode_tpl_replace($match[1][$i], $match[2][$i]); + } + } + + + return (isset($this->bbcode_template[$tpl_name])) ? $this->bbcode_template[$tpl_name] : ((isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false); + } + + /** + * Return bbcode template replacement + */ + function bbcode_tpl_replace($tpl_name, $tpl) + { + global $mx_user; + + static $replacements = array( + 'quote_username_open' => array('{USERNAME}' => '$1'), + 'color' => array('{COLOR}' => '$1', '{TEXT}' => '$2'), + 'size' => array('{SIZE}' => '$1', '{TEXT}' => '$2'), + 'img' => array('{WIDTH}' => '$1', '{HEIGHT}' => '$2', '{URL}' => '$3'), + 'scribd' => array('{URL}' => '$1'), + 'flash' => array('{WIDTH}' => '$1', '{HEIGHT}' => '$2', '{SCRIBDURL}' => '$3'), + 'youtube' => array('{YOUTUBEID}' => '$1', '{YOUTUBELINK}' => '$2', '{WIDTH}' => '$3', '{HEIGHT}' => '$4'), + 'ipaper' => array('{IPAPERID}' => '$1', '{IPAPERKEY}' => '$2', '{WIDTH}' => '$3', '{HEIGHT}' => '$4', '{IPAPERLINK}' => '$5'), + 'ipaper_open' => array('{IPAPERCODE}' => '$1'), + 'url' => array('{URL}' => '$1', '{DESCRIPTION}' => '$2'), + 'web' => array('{URL}' => '$1', '{DESCRIPTION}' => '$2'), + 'size' => array('{ID}' => '$1', '{TEXT}' => '$2'), + 'email' => array('{EMAIL}' => '$1', '{DESCRIPTION}' => '$2'), + 'table' => array('{NUMBER}' => '$1', '{TEXT}' => '$2'), + 'tr' => array('{TEXT}' => '$1'), + 'th' => array('{NUMBER}' => '$1', '{TEXT}' => '$2'), + 'td' => array('{NUMBER}' => '$1', '{TEXT}' => '$2'), + 'thead' => array('{TEXT}' => '$1'), + 'tbody' => array('{TEXT}' => '$1'), + 'center' => array('{TEXT}' => '$1'), + 'align' => array('{TEXT}' => '$1'), + 'float' => array('{TEXT}' => '$1'), + 'fa' => array('{TEXT}' => '$1') + ); + + $tpl = preg_replace_callback('/{L_([A-Z0-9_]+)}/', function ($match) use ($mx_user) { + return (!empty($mx_user->lang[$match[1]])) ? $mx_user->lang($match[1]) : ucwords(strtolower(str_replace('_', ' ', $match[1]))); + }, $tpl); + + if (!empty($replacements[$tpl_name])) + { + $tpl = strtr($tpl, $replacements[$tpl_name]); + } + + return trim($tpl); + } + + + /** + * Second parse list bbcode + * / + function bbcode_list($type) + { + if ($type == '') + { + $tpl = 'ulist_open_default'; + $type = 'default'; + } + else if ($type == 'i') + { + $tpl = 'olist_open'; + $type = 'lower-roman'; + } + else if ($type == 'I') + { + $tpl = 'olist_open'; + $type = 'upper-roman'; + } + else if (preg_match('#^(disc|circle|square|radical)$#i', $type)) + { + $tpl = 'ulist_open'; + $type = strtolower($type); + } + else if (preg_match('#^[a-z]$#', $type)) + { + $tpl = 'olist_open'; + $type = 'lower-alpha'; + } + else if (preg_match('#[A-Z]#', $type)) + { + $tpl = 'olist_open'; + $type = 'upper-alpha'; + } + else if (is_numeric($type)) + { + $tpl = 'olist_open'; + $type = 'arabic-numbers'; + } + else + { + $tpl = 'olist_open'; + $type = 'arabic-numbers'; + } + + return str_replace('{LIST_TYPE}', $type, $this->bbcode_tpl($tpl)); + } + + /** + * Init bbcode cache + * + * requires: $this->bbcode_bitfield + * sets: $this->bbcode_cache with bbcode templates needed for bbcode_bitfield + */ + function bbcode_cache_init() + { + global $mx_user, $mx_root_path; + + if (empty($this->template_filename)) + { + $this->template_bitfield = new bitfield(isset($mx_user->theme['bbcode_bitfield']) ? $mx_user->theme['bbcode_bitfield'] : 'kNg='); + + if (file_exists($mx_root_path . 'templates/' . $mx_user->template_name . '/template/bbcode.html')) + { + $this->template_filename = $mx_root_path . 'templates/' . $mx_user->template_name . '/template/bbcode.html'; + } + elseif (file_exists($mx_root_path . 'templates/' . $mx_user->template_name . '/template/bbcode.tpl')) + { + $this->template_filename = $mx_root_path . 'templates/' . $mx_user->template_name . '/template/bbcode.tpl'; + } + if (file_exists($mx_root_path . 'templates/' . $mx_user->template_name . '/bbcode.tpl')) + { + $this->template_filename = $mx_root_path . 'templates/' . $mx_user->template_name . '/bbcode.tpl'; + } + elseif (file_exists($mx_root_path . 'templates/' . $mx_user->template_name . '/bbcode.html')) + { + $this->template_filename = $mx_root_path . 'templates/' . $mx_user->template_name . '/bbcode.html'; + } + $this->template_filename2 = substr_count($this->template_filename, 'html') ? str_replace(".html", ".tpl", $this->template_filename) : str_replace(".tpl", ".html", $this->template_filename); + if (!@file_exists($this->template_filename)) + { + if (!@file_exists($this->template_filename2)) + { + global $template; + + $this->template_filename = $template->make_filename('bbcode.tpl', false); + $this->template_filename2 = $template->make_filename('bbcode.html', false); + //trigger_error('The file "' . $this->template_filename . '", and The file "' . $this->template_filename2 . '" are missing.', E_USER_ERROR); + } + else + { + $this->template_filename = $this->template_filename2; + } + } + } + + $bbcode_ids = $rowset = $sql = array(); + + $bitfield = new bitfield($this->bbcode_bitfield); + $bbcodes_set = $bitfield->get_all_set(); + + foreach ($bbcodes_set as $bbcode_id) + { + if (isset($this->bbcode_cache[$bbcode_id])) + { + // do not try to re-cache it if it's already in + continue; + } + $bbcode_ids[] = $bbcode_id; + + if ($bbcode_id > NUM_CORE_BBCODES) + { + $sql[] = $bbcode_id; + } + } + + if (sizeof($sql)) + { + global $db; + + $sql = 'SELECT * + FROM ' . BBCODES_TABLE . ' + WHERE ' . $db->sql_in_set('bbcode_id', $sql); + $result = $db->sql_query($sql, 3600); + + while ($row = $db->sql_fetchrow($result)) + { + // To circumvent replacing newlines with
for the generated html, + // we use carriage returns here. They are later changed back to newlines + $row['bbcode_tpl'] = str_replace("\n", "\r", $row['bbcode_tpl']); + $row['second_pass_replace'] = str_replace("\n", "\r", $row['second_pass_replace']); + + $rowset[$row['bbcode_id']] = $row; + } + $db->sql_freeresult($result); + } + $bbcode_ids = $rowset; + foreach ($bbcode_ids as $bbcode_id) + { + switch ($bbcode_id) + { + case 0: + $this->bbcode_cache[$bbcode_id] = array( + 'str' => array( + '[/quote:$uid]' => $this->bbcode_tpl('quote_close', $bbcode_id) + ), + 'preg' => array( + '#\[quote(?:="(.*?)")?:$uid\]((?!\[quote(?:=".*?")?:$uid\]).)?#ise' => "\$this->bbcode_second_pass_quote('\$1', '\$2')" + ) + ); + break; + + case 1: + $this->bbcode_cache[$bbcode_id] = array( + 'str' => array( + '[b:$uid]' => $this->bbcode_tpl('b_open', $bbcode_id), + '[/b:$uid]' => $this->bbcode_tpl('b_close', $bbcode_id), + ) + ); + break; + + case 2: + $this->bbcode_cache[$bbcode_id] = array( + 'str' => array( + '[i:$uid]' => $this->bbcode_tpl('i_open', $bbcode_id), + '[/i:$uid]' => $this->bbcode_tpl('i_close', $bbcode_id), + ) + ); + break; + + case 3: + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[url:$uid\]((.*?))\[/url:$uid\]#s' => $this->bbcode_tpl('url', $bbcode_id), + '#\[url=([^\[]+?):$uid\](.*?)\[/url:$uid\]#s' => $this->bbcode_tpl('url', $bbcode_id), + ) + ); + break; + + case 4: + if ($mx_user->optionget('viewimg')) + { + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[img:$uid\](.*?)\[/img:$uid\]#s' => $this->bbcode_tpl('img', $bbcode_id), + ) + ); + } + else + { + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[img:$uid\](.*?)\[/img:$uid\]#s' => str_replace('$2', '[ img ]', $this->bbcode_tpl('url', $bbcode_id, true)), + ) + ); + } + break; + + case 5: + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[size=([\-\+]?\d+):$uid\](.*?)\[/size:$uid\]#s' => $this->bbcode_tpl('size', $bbcode_id), + ) + ); + break; + + case 6: + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '!\[color=(#[0-9a-f]{6}|[a-z\-]+):$uid\](.*?)\[/color:$uid\]!is' => $this->bbcode_tpl('color', $bbcode_id), + ) + ); + break; + + case 7: + $this->bbcode_cache[$bbcode_id] = array( + 'str' => array( + '[u:$uid]' => $this->bbcode_tpl('u_open', $bbcode_id), + '[/u:$uid]' => $this->bbcode_tpl('u_close', $bbcode_id), + ) + ); + break; + + case 8: + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[code(?:=([a-z]+))?:$uid\](.*?)\[/code:$uid\]#ise' => "\$this->bbcode_second_pass_code('\$1', '\$2')", + ) + ); + break; + + case 9: + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#(\[\/?(list|\*):[mou]?:?$uid\])[\n]{1}#' => "\$1", + '#(\[list=([^\[]+):$uid\])[\n]{1}#' => "\$1", + '#\[list=([^\[]+):$uid\]#e' => "\$this->bbcode_list('\$1')", + ), + 'str' => array( + '[list:$uid]' => $this->bbcode_tpl('ulist_open_default', $bbcode_id), + '[/list:u:$uid]' => $this->bbcode_tpl('ulist_close', $bbcode_id), + '[/list:o:$uid]' => $this->bbcode_tpl('olist_close', $bbcode_id), + '[*:$uid]' => $this->bbcode_tpl('listitem', $bbcode_id), + '[/*:$uid]' => $this->bbcode_tpl('listitem_close', $bbcode_id), + '[/*:m:$uid]' => $this->bbcode_tpl('listitem_close', $bbcode_id) + ), + ); + break; + + case 10: + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[email:$uid\]((.*?))\[/email:$uid\]#is' => $this->bbcode_tpl('email', $bbcode_id), + '#\[email=([^\[]+):$uid\](.*?)\[/email:$uid\]#is' => $this->bbcode_tpl('email', $bbcode_id) + ) + ); + break; + + case 11: + if ($mx_user->optionget('viewflash')) + { + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#' => $this->bbcode_tpl('flash', $bbcode_id), + ) + ); + } + else + { + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#' => str_replace('$1', '$3', str_replace('$2', '[ flash ]', $this->bbcode_tpl('url', $bbcode_id, true))) + ) + ); + } + break; + + case 12: + $this->bbcode_cache[$bbcode_id] = array( + 'str' => array( + '[/attachment:$uid]' => $this->bbcode_tpl('inline_attachment_close', $bbcode_id) + ), + 'preg' => array( + '#\[attachment=([0-9]+):$uid\]#' => $this->bbcode_tpl('inline_attachment_open', $bbcode_id) + ) + ); + break; + + + default: + if (isset($rowset[$bbcode_id])) + { + if ($this->template_bitfield->get($bbcode_id)) + { + // The bbcode requires a custom template to be loaded + if (!$bbcode_tpl = $this->bbcode_tpl($rowset[$bbcode_id]['bbcode_tag'], $bbcode_id)) + { + // For some reason, the required template seems not to be available, use the default template + $bbcode_tpl = (!empty($rowset[$bbcode_id]['second_pass_replace'])) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl']; + } + else + { + // In order to use templates with custom bbcodes we need + // to replace all {VARS} to corresponding backreferences + // Note that backreferences are numbered from bbcode_match + if (preg_match_all('/\{(URL|LOCAL_URL|WEB|IPAPERLINK|RAM|EMAIL|TEXT|SIMPLETEXT|IDENTIFIER|COLOR|NUMBER)[0-9]*\}/', $rowset[$bbcode_id]['bbcode_match'], $m)) + { + foreach ($m[0] as $i => $tok) + { + $bbcode_tpl = str_replace($tok, '$' . ($i + 1), $bbcode_tpl); + } + } + } + } + else + { + // Default template + $bbcode_tpl = ($rowset[$bbcode_id]['second_pass_replace']) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl']; + } + + // Replace {L_*} lang strings + $bbcode_tpl = preg_replace('/{L_([A-Z_]+)}/e', "(!empty(\$mx_user->lang['\$1'])) ? \$mx_user->lang['\$1'] : ucwords(strtolower(str_replace('_', ' ', '\$1')))", $bbcode_tpl); + + if (!empty($rowset[$bbcode_id]['second_pass_replace'])) + { + // The custom BBCode requires second-pass pattern replacements + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl) + ); + } + else + { + $this->bbcode_cache[$bbcode_id] = array( + 'str' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl) + ); + } + } + else + { + $this->bbcode_cache[$bbcode_id] = false; + } + break; + } + } + } + + /** + * Does second-pass bbencoding. This should be used before displaying the message in + * a thread. Assumes the message is already first-pass encoded, and we are given the + * correct UID as used in first-pass encoding. + * This a temporary function + + Creating an BBcode List with a custom bullet character. + For example to list your favorite colors you could use: + + [list=square] + [*]Red + [*]Blue + [*]Yellow + [/list] + + The question is how to specify a custom list’s bullet such as [b]?[/b] for a Features BBcode List ? + + [b]?[/b][color=#FF0000]Red[/color] + [b]?[/b][color=#0040FF]Blue[/color] + [b]?[/b][color=#FFFF00]Yellow[/color] + */ + function bbencode_second_pass($text, $uid = '', $bitfield = false) + { + global $lang, $bbcode_tpl; + + if ($uid) + { + $this->bbcode_uid = $uid; + } + + if ($bitfield !== false) + { + $this->bbcode_bitfield = $bitfield; + + // Init those added with a new bbcode_bitfield (already stored codes will not get parsed again) + $this->bbcode_cache_init(); + } + + //Check if it's a phpBB3 block + if ($bitfield) + { + $this->bbcode_second_pass($text, $uid, $bitfield); + } + + $text = str_replace(array("\n", "\r"), array('
', "\n"), $text); + $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text); + + // pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0). + // This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it. + $text = " " . $text; + + // First: If there isn't a "[" and a "]" in the message, don't bother. + if (! (strpos($text, "[") && strpos($text, "]")) ) + { + // Remove padding, return. + $text = substr($text, 1); + return $text; + } + + // Only load the templates ONCE.. + if (!defined("BBCODE_TPL_READY")) + { + // load templates from file into array. + $bbcode_tpl = $this->load_bbcode_template(); + + // prepare array for use in regexps. + $bbcode_tpl = $this->prepare_bbcode_template($bbcode_tpl); + } + + // [CODE] and [/CODE] for posting code (HTML, PHP, C etc etc) in your posts. + $text = $this->bbencode_second_pass_code($text, $uid, $bbcode_tpl); + + // [IPAPER] and [/IPAPER] for posting iPaper in your posts. + $text = $this->bbencode_ipaper_pass_render($text, $uid, $bbcode_tpl); + + // [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff. + $text = str_replace("[quote:$uid]", $bbcode_tpl['quote_open'], $text); + $text = str_replace("[/quote:$uid]", $bbcode_tpl['quote_close'], $text); + + // New one liner to deal with opening quotes with usernames... + // replaces the two line version that I had here before.. + $text = preg_replace("/\[quote:$uid=\"(.*?)\"\]/si", $bbcode_tpl['quote_username_open'], $text); + + // [list] and [list=x] for (un)ordered lists. + // unordered lists + $text = str_replace("[list:$uid]", $bbcode_tpl['ulist_open'], $text); + // li tags + $text = str_replace("[*:$uid]", $bbcode_tpl['listitem'], $text); + // ending tags + $text = str_replace("[/list:u:$uid]", $bbcode_tpl['ulist_close'], $text); + $text = str_replace("[/list:o:$uid]", $bbcode_tpl['olist_close'], $text); + //$text = str_replace("[/list:m:$uid]", $bbcode_tpl['mlist_close'], $text); + // Ordered lists + $text = preg_replace("/\[list=([a1]):$uid\]/si", $bbcode_tpl['olist_open'], $text); + //$text = preg_replace("/\[list=([disc]):$uid\]/si", $bbcode_tpl['olist_open'], $text); + //$text = preg_replace("/\[list=([circle]):$uid\]/si", $bbcode_tpl['olist_open'], $text); + //$text = preg_replace("/\[list=([square]):$uid\]/si", $bbcode_tpl['olist_open'], $text); + //$text = preg_replace("/\[list=([radical]):$uid\]/si", $bbcode_tpl['olist_open'], $text); + //$text = preg_replace("/\[list=([none]):$uid\]/si", $bbcode_tpl['olist_open'], $text); + //$text = preg_replace("/\[list=([^\[]+):$uid\][\n]/si", $bbcode_tpl['mlist_open'], $text); + + // colours + $text = preg_replace("/\[color=(\#[0-9A-F]{6}|[a-z]+):$uid\]/si", $bbcode_tpl['color_open'], $text); + $text = str_replace("[/color:$uid]", $bbcode_tpl['color_close'], $text); + // size + $text = preg_replace("/\[size=([1-2]?[0-9]):$uid\]/si", $bbcode_tpl['size_open'], $text); + $text = str_replace("[/size:$uid]", $bbcode_tpl['size_close'], $text); + + // [b] and [/b] for bolding text. + $text = str_replace("[b:$uid]", $bbcode_tpl['b_open'], $text); + $text = str_replace("[/b:$uid]", $bbcode_tpl['b_close'], $text); + + // [u] and [/u] for underlining text. + $text = str_replace("[u:$uid]", $bbcode_tpl['u_open'], $text); + $text = str_replace("[/u:$uid]", $bbcode_tpl['u_close'], $text); + + // [i] and [/i] for italicizing text. + $text = str_replace("[i:$uid]", $bbcode_tpl['i_open'], $text); + $text = str_replace("[/i:$uid]", $bbcode_tpl['i_close'], $text); + + //$text = str_replace('url:' . $uid, 'url', $text); + + // Patterns and replacements for URL and email tags.. + $patterns = array(); + $replacements = array(); + + // [img]image_url_here[/img] code.. + // This one gets first-passed.. + $patterns[] = "#\[img:$uid\]([^?](?:[^\[]+|\[(?!url))*?)\[/img:$uid\]#i"; + $replacements[] = $bbcode_tpl['img']; + + // matches a [url]xxxx://www.phpbb.com[/url] code.. + $patterns[] = "#\[url\]([\w]+?://([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is"; + $replacements[] = $bbcode_tpl['url1']; + + // [url]www.phpbb.com[/url] code.. (no xxxx:// prefix). + $patterns[] = "#\[url\]((www|ftp)\.([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is"; + $replacements[] = $bbcode_tpl['url2']; + + // [url=xxxx://www.phpbb.com]phpBB[/url] code.. + $patterns[] = "#\[url=([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is"; + $replacements[] = $bbcode_tpl['url3']; + + // [url=www.phpbb.com]phpBB[/url] code.. (no xxxx:// prefix). + $patterns[] = "#\[url=((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is"; + $replacements[] = $bbcode_tpl['url4']; + + // [email]user@domain.tld[/email] code.. + $patterns[] = "#\[email\]([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si"; + $replacements[] = $bbcode_tpl['email']; + // real + $patterns[] = "#\[ram:$uid\](.*?)\[/ram:$uid\]#si"; + $replacements[] = $bbcode_tpl['ram']; + // [stream]Sound URL[/stream] code.. + $patterns[] = "#\[stream:$uid\](.*?)\[/stream:$uid\]#si"; + $replacements[] = $bbcode_tpl['stream']; + //web + $patterns[] = "#\[web:$uid\](.*?)\[/web:$uid\]#si"; + $replacements[] = $bbcode_tpl['web']; + // [flash width= height= loop= ] and [/flash] code.. + $patterns[] = "#\[flash width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-9]?[0-9]):$uid\](.*?)\[/flash:$uid\]#si"; + $replacements[] = $bbcode_tpl['flash']; + // [flash width= height= loop= ] and [/flash] code.. + $patterns[10] = "#\[video width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-9]?[0-9]):$uid\](.*?)\[/video:$uid\]#si"; + $replacements[10] = $bbcode_tpl['video']; + + // [flash width=X height=X]Flash URL[/flash] code.. + $patterns[] = "#\[flash width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-9]?[0-9]):$uid\](.*?)\[/flash:$uid\]#si"; + $replacements[] = $bbcode_tpl['flash']; + + // [video width=X height=X]Video URL[/video] code.. + $patterns[] = "#\[video width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-9]?[0-9]):$uid\](.*?)\[/video:$uid\]#si"; + $replacements[] = $bbcode_tpl['video']; + + // [GVideo]GVideo URL[/GVideo] code.. + $patterns[] = "#\[GVideo\]http://video.google.[A-Za-z0-9.]{2,5}/videoplay\?docid=([0-9A-Za-z-_]*)[^[]*\[/GVideo\]#is"; + $replacements[] = $bbcode_tpl['GVideo']; + + // [youtube]www.youtube.com[/youtube] + $patterns[] = "#\[youtube\]http://(?:www\.)?youtube.com/watch\?v=([0-9A-Za-z-_]{11})[^[]*\[/youtube\]#is"; + $replacements[] = $bbcode_tpl['youtube']; + + // [youtube=xxxx://www.youtube.com]Youtube[/youtube] code.. + //$patterns[] = "#\[youtube=http://(?:www\.)?youtube.com/watch\?v=([0-9A-Za-z-_]{11})]([^?\n\r\t].*?)\[/youtube\]#is"; + //$replacements[] = $bbcode_tpl['youtube']; + + // [scribd]Scribd URL[/scribd] code.. + $patterns[] = "#\[scribd\]http://(?:d\.)?scribd.com/ScribdViewer.swf\?document_id=([0-9A-Za-z-_]*)[^[]*\[/scribd\]#is"; + $replacements[] = $bbcode_tpl['scribd']; + + // [scribd]Scribd URL[/scribd] code.. + $patterns[] = "#\[scribd id=([0-9A-Za-z-_]{8}) key=([0-9A-Za-z-_]{24})\](.*?)\[/scribd\]#is"; + $replacements[] = $bbcode_tpl['scribd']; + + // [ipaper]Scribd URL[/ipaper] code.. + $patterns[] = "#\[ipaper\]http://(?:d\.)?scribd.com/ScribdViewer.swf\?document_id=([0-9A-Za-z-_]*)\&access_key=([0-9A-Za-z-_]*)[^[]*\[/ipaper\]#is"; + $replacements[] = $bbcode_tpl['ipaper']; + + //Strat more bbcode + $text = preg_replace($patterns, $replacements, $text); + // align + $text = preg_replace("/\[align=(left|right|center|justify):$uid\]/si", $bbcode_tpl['align_open'], $text); + $text = str_replace("[/align:$uid]", $bbcode_tpl['align_close'], $text); + // marquee + $text = preg_replace("/\[marq=(left|right|up|down):$uid\]/si", $bbcode_tpl['marq_open'], $text); + $text = str_replace("[/marq:$uid]", $bbcode_tpl['marq_close'], $text); + // table + $text = $this->bbencode_second_pass_html($text, $uid, $bbcode_tpl); + // tr + $text = str_replace("[tr:$uid]", $bbcode_tpl['tr_open'], $text); + $text = str_replace("[/tr:$uid]", $bbcode_tpl['tr_close'], $text); + // th + $text = preg_replace("[th:$uid]", $bbcode_tpl['th_open'], $text); + $text = str_replace("[/th:$uid]", $bbcode_tpl['th_close'], $text); + // td + $text = preg_replace("[td:$uid]", $bbcode_tpl['td_open'], $text); + $text = str_replace("[/td:$uid]", $bbcode_tpl['td_close'], $text); + // cell + $text = preg_replace("/\[cell=(.*?):$uid\]/si", $bbcode_tpl['cell_open'], $text); + $text = str_replace("[/cell:$uid]", $bbcode_tpl['cell_close'], $text); + // thead + $text = preg_replace("[thead:$uid]", $bbcode_tpl['thead_open'], $text); + $text = str_replace("[/thead:$uid]", $bbcode_tpl['thead_close'], $text); + // tbody + $text = preg_replace("[tbody:$uid]", $bbcode_tpl['tbody_open'], $text); + $text = str_replace("[/tbody:$uid]", $bbcode_tpl['tbody_close'], $text); + // center + $text = preg_replace("/\[center:$uid\]/si", $bbcode_tpl['center_open'], $text); + $text = str_replace("[/center:$uid]", $bbcode_tpl['center_close'], $text); + + // float + $text = preg_replace("/\[float:$uid\]/si", $bbcode_tpl['float_open'], $text); + $text = str_replace("[/float:$uid]", $bbcode_tpl['float_close'], $text); + // font + $text = preg_replace("/\[font=(.*?):$uid\]/si", $bbcode_tpl['font_open'], $text); + $text = str_replace("[/font:$uid]", $bbcode_tpl['font_close'], $text); + // poet + $text = preg_replace("/\[poet(.*?):$uid\]/si", $bbcode_tpl['poet_open'], $text); + $text = str_replace("[/poet:$uid]", $bbcode_tpl['poet_close'], $text); + //[hr] + $text = str_replace("[hr:$uid]", $bbcode_tpl['hr'], $text); + // bbcode_box Mod + // [fade] and [/fade] for faded text. + $text = str_replace("[fade:$uid]", $bbcode_tpl['fade_open'], $text); + $text = str_replace("[/fade:$uid]", $bbcode_tpl['fade_close'], $text); + + $text = str_replace("[fa:$uid]", $bbcode_tpl['fa_open'], $text); + $text = str_replace("[/fa:$uid]", $bbcode_tpl['fa_close'], $text); + + $text = str_replace("[fa_logo:$uid]", $bbcode_tpl['fa_logo_open'], $text); + $text = str_replace("[/fa_logo:$uid]", $bbcode_tpl['fa_logo_close'], $text); + + //Stop more bbcode + $text = preg_replace($patterns, $replacements, $text); + + // Remove the uid from tags that have not been transformed into HTML + $text = str_replace(':' . $uid, '', $text); + + // Remove our padding from the string.. + $text = substr($text, 1); + + return $text; + + } // bbencode_second_pass() + /** * phpBB Smilies pass. * @@ -183,6 +1028,27 @@ function smilies_pass($message) return $message; } + /** + * phpBB Smilies pass. + * + * Hacking smilies_pass from phpbb/includes/bbcode.php + * + * NOTE: This is only kept for reference - not used. + * + * @param string $message + * @return string + */ + function mx_smilies_pass_old($message) + { + global $mx_page, $board_config, $phpbb_root_path, $phpEx; + + $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; + } + /** * Generate smilies. * diff --git a/includes/sessions/phpbb2/constants.php b/includes/sessions/phpbb2/constants.php index c4bc8e05..88abd8d6 100644 --- a/includes/sessions/phpbb2/constants.php +++ b/includes/sessions/phpbb2/constants.php @@ -32,6 +32,11 @@ @define('ADMIN', 1); @define('MOD', 2); +@define('USER_NORMAL', 0); +@define('USER_INACTIVE', 1); +@define('USER_IGNORE', 2); +@define('USER_FOUNDER', 3); + // User related @define('USER_ACTIVATION_NONE', 0); @define('USER_ACTIVATION_SELF', 1); diff --git a/includes/sessions/phpbb2/core.php b/includes/sessions/phpbb2/core.php index e5e93641..5ad4bbb8 100644 --- a/includes/sessions/phpbb2/core.php +++ b/includes/sessions/phpbb2/core.php @@ -19,7 +19,8 @@ // Note: These functions will later be accessible wrapped as phpBBX::orig_functionname() // include_once($mx_root_path . 'includes/shared/phpbb2/includes/functions.' . $phpEx); -include_once($mx_root_path . 'includes/shared/phpbb3/includes/functions.' . $phpEx); + + // // Finally, load some backend specific functions @@ -39,6 +40,675 @@ */ class phpbb_auth extends phpbb_auth_base { + var $acl = array(); + var $mx_cache = array(); + var $acl_options = array(); + var $acl_forum_ids = false; + + /** + * Init permissions + */ + function acl(&$userdata) + { + global $db, $mx_cache; + + $this->acl = $this->cache = $this->acl_options = array(); + $this->acl_forum_ids = false; + + if (($this->acl_options = $mx_cache->get('_acl_options')) === false) + { + $this->acl_options = array ( + 'local' => array ( + 'f_' => 0, + 'f_announce' => 1, + 'f_announce_global' => 2, + 'f_attach' => 3, + 'f_bbcode' => 4, + 'f_bump' => 5, + 'f_delete' => 6, + 'f_download' => 7, + 'f_edit' => 8, + 'f_email' => 9, + 'f_flash' => 10, + 'f_icons' => 11, + 'f_ignoreflood' => 12, + 'f_img' => 13, + 'f_list' => 14, + 'f_list_topics' => 15, + 'f_noapprove' => 16, + 'f_poll' => 17, + 'f_post' => 18, + 'f_postcount' => 19, + 'f_print' => 20, + 'f_read' => 21, + 'f_reply' => 22, + 'f_report' => 23, + 'f_search' => 24, + 'f_sigs' => 25, + 'f_smilies' => 26, + 'f_sticky' => 27, + 'f_subscribe' => 28, + 'f_user_lock' => 29, + 'f_vote' => 30, + 'f_votechg' => 31, + 'f_softdelete' => 32, + 'm_' => 33, + 'm_approve' => 34, + 'm_chgposter' => 35, + 'm_delete' => 36, + 'm_edit' => 37, + 'm_info' => 38, + 'm_lock' => 39, + 'm_merge' => 40, + 'm_move' => 41, + 'm_report' => 42, + 'm_split' => 43, + 'm_softdelete' => 44 + ), + 'id' => array ( + 'f_' => 1, + 'f_announce' => 2, + 'f_announce_global' => 3, + 'f_attach' => 4, + 'f_bbcode' => 5, + 'f_bump' => 6, + 'f_delete' => 7, + 'f_download' => 8, + 'f_edit' => 9, + 'f_email' => 10, + 'f_flash' => 11, + 'f_icons' => 12, + 'f_ignoreflood' => 13, + 'f_img' => 14, + 'f_list' => 15, + 'f_list_topics' => 16, + 'f_noapprove' => 17, + 'f_poll' => 18, + 'f_post' => 19, + 'f_postcount' => 20, + 'f_print' => 21, + 'f_read' => 22, + 'f_reply' => 23, + 'f_report' => 24, + 'f_search' => 25, + 'f_sigs' => 26, + 'f_smilies' => 27, + 'f_sticky' => 28, + 'f_subscribe' => 29, + 'f_user_lock' => 30, + 'f_vote' => 31, + 'f_votechg' => 32, + 'f_softdelete' => 33, + 'm_' => 34, + 'm_approve' => 35, + 'm_chgposter' => 36, + 'm_delete' => 37, + 'm_edit' => 38, + 'm_info' => 39, + 'm_lock' => 40, + 'm_merge' => 41, + 'm_move' => 42, + 'm_report' => 43, + 'm_split' => 44, + 'm_softdelete' => 45, + 'm_ban' => 46, + 'm_pm_report' => 47, + 'm_warn' => 48, + 'a_' => 49, + 'a_aauth' => 50, + 'a_attach' => 51, + 'a_authgroups' => 52, + 'a_authusers' => 53, + 'a_backup' => 54, + 'a_ban' => 55, + 'a_bbcode' => 56, + 'a_board' => 57, + 'a_bots' => 58, + 'a_clearlogs' => 59, + 'a_email' => 60, + 'a_extensions' => 61, + 'a_fauth' => 62, + 'a_forum' => 63, + 'a_forumadd' => 64, + 'a_forumdel' => 65, + 'a_group' => 66, + 'a_groupadd' => 67, + 'a_groupdel' => 68, + 'a_icons' => 69, + 'a_jabber' => 70, + 'a_language' => 71, + 'a_mauth' => 72, + 'a_modules' => 73, + 'a_names' => 74, + 'a_phpinfo' => 75, + 'a_profile' => 76, + 'a_prune' => 77, + 'a_ranks' => 78, + 'a_reasons' => 79, + 'a_roles' => 80, + 'a_search' => 81, + 'a_server' => 82, + 'a_storage' => 83, + 'a_styles' => 84, + 'a_switchperm' => 85, + 'a_uauth' => 86, + 'a_user' => 87, + 'a_userdel' => 88, + 'a_viewauth' => 89, + 'a_viewlogs' => 90, + 'a_words' => 91, + 'u_' => 92, + 'u_attach' => 93, + 'u_chgavatar' => 94, + 'u_chgcensors' => 95, + 'u_chgemail' => 96, + 'u_chggrp' => 97, + 'u_chgname' => 98, + 'u_chgpasswd' => 99, + 'u_chgprofileinfo' => 100, + 'u_download' => 101, + 'u_hideonline' => 102, + 'u_ignoreflood' => 103, + 'u_masspm' => 104, + 'u_masspm_group' => 105, + 'u_pm_attach' => 106, + 'u_pm_bbcode' => 107, + 'u_pm_delete' => 108, + 'u_pm_download' => 109, + 'u_pm_edit' => 110, + 'u_pm_emailpm' => 111, + 'u_pm_flash' => 112, + 'u_pm_forward' => 113, + 'u_pm_img' => 114, + 'u_pm_printpm' => 115, + 'u_pm_smilies' => 116, + 'u_readpm' => 117, + 'u_savedrafts' => 118, + 'u_search' => 119, + 'u_sendemail' => 120, + 'u_sendim' => 121, + 'u_sendpm' => 122, + 'u_sig' => 123, + 'u_viewonline' => 124, + 'u_viewprofile' => 125, + 'u_dae_user' => 142, + 'a_dae_admin' => 143 + ), + 'option' => array ( + '1' => 'f_', + '2' => 'f_announce', + '3' => 'f_announce_global', + '4' => 'f_attach', + '5' => 'f_bbcode', + '6' => 'f_bump', + '7' => 'f_delete', + '8' => 'f_download', + '9' => 'f_edit', + '10' => 'f_email', + '11' => 'f_flash', + '12' => 'f_icons', + '13' => 'f_ignoreflood', + '14' => 'f_img', + '15' => 'f_list', + '16' => 'f_list_topics', + '17' => 'f_noapprove', + '18' => 'f_poll', + '19' => 'f_post', + '20' => 'f_postcount', + '21' => 'f_print', + '22' => 'f_read', + '23' => 'f_reply', + '24' => 'f_report', + '25' => 'f_search', + '26' => 'f_sigs', + '27' => 'f_smilies', + '28' => 'f_sticky', + '29' => 'f_subscribe', + '30' => 'f_user_lock', + '31' => 'f_vote', + '32' => 'f_votechg', + '33' => 'f_softdelete', + '34' => 'm_', + '35' => 'm_approve', + '36' => 'm_chgposter', + '37' => 'm_delete', + '38' => 'm_edit', + '39' => 'm_info', + '40' => 'm_lock', + '41' => 'm_merge', + '42' => 'm_move', + '43' => 'm_report', + '44' => 'm_split', + '45' => 'm_softdelete', + '46' => 'm_ban', + '47' => 'm_pm_report', + '48' => 'm_warn', + '49' => 'a_', + '50' => 'a_aauth', + '51' => 'a_attach', + '52' => 'a_authgroups', + '53' => 'a_authusers', + '54' => 'a_backup', + '55' => 'a_ban', + '56' => 'a_bbcode', + '57' => 'a_board', + '58' => 'a_bots', + '59' => 'a_clearlogs', + '60' => 'a_email', + '61' => 'a_extensions', + '62' => 'a_fauth', + '63' => 'a_forum', + '64' => 'a_forumadd', + '65' => 'a_forumdel', + '66' => 'a_group', + '67' => 'a_groupadd', + '68' => 'a_groupdel', + '69' => 'a_icons', + '70' => 'a_jabber', + '71' => 'a_language', + '72' => 'a_mauth', + '73' => 'a_modules', + '74' => 'a_names', + '75' => 'a_phpinfo', + '76' => 'a_profile', + '77' => 'a_prune', + '78' => 'a_ranks', + '79' => 'a_reasons', + '80' => 'a_roles', + '81' => 'a_search', + '82' => 'a_server', + '83' => 'a_storage', + '84' => 'a_styles', + '85' => 'a_switchperm', + '86' => 'a_uauth', + '87' => 'a_user', + '88' => 'a_userdel', + '89' => 'a_viewauth', + '90' => 'a_viewlogs', + '91' => 'a_words', + '92' => 'u_', + '93' => 'u_attach', + '94' => 'u_chgavatar', + '95' => 'u_chgcensors', + '96' => 'u_chgemail', + '97' => 'u_chggrp', + '98' => 'u_chgname', + '99' => 'u_chgpasswd', + '100' => 'u_chgprofileinfo', + '101' => 'u_download', + '102' => 'u_hideonline', + '103' => 'u_ignoreflood', + '104' => 'u_masspm', + '105' => 'u_masspm_group', + '106' => 'u_pm_attach', + '107' => 'u_pm_bbcode', + '108' => 'u_pm_delete', + '109' => 'u_pm_download', + '110' => 'u_pm_edit', + '111' => 'u_pm_emailpm', + '112' => 'u_pm_flash', + '113' => 'u_pm_forward', + '114' => 'u_pm_img', + '115' => 'u_pm_printpm', + '116' => 'u_pm_smilies', + '117' => 'u_readpm', + '118' => 'u_savedrafts', + '119' => 'u_search', + '120' => 'u_sendemail', + '121' => 'u_sendim', + '122' => 'u_sendpm', + '123' => 'u_sig', + '124' => 'u_viewonline', + '125' => 'u_viewprofile', + '142' => 'u_dae_user', + '143' => 'a_dae_admin' + ), + 'global' => array ( + 'm_' => 0, + 'm_approve' => 1, + 'm_chgposter' => 2, + 'm_delete' => 3, + 'm_edit' => 4, + 'm_info' => 5, + 'm_lock' => 6, + 'm_merge' => 7, + 'm_move' => 8, + 'm_report' => 9, + 'm_split' => 10, + 'm_softdelete' => 11, + 'm_ban' => 12, + 'm_pm_report' => 13, + 'm_warn' => 14, + 'a_' => 15, + 'a_aauth' => 16, + 'a_attach' => 17, + 'a_authgroups' => 18, + 'a_authusers' => 19, + 'a_backup' => 20, + 'a_ban' => 21, + 'a_bbcode' => 22, + 'a_board' => 23, + 'a_bots' => 24, + 'a_clearlogs' => 25, + 'a_email' => 26, + 'a_extensions' => 27, + 'a_fauth' => 28, + 'a_forum' => 29, + 'a_forumadd' => 30, + 'a_forumdel' => 31, + 'a_group' => 32, + 'a_groupadd' => 33, + 'a_groupdel' => 34, + 'a_icons' => 35, + 'a_jabber' => 36, + 'a_language' => 37, + 'a_mauth' => 38, + 'a_modules' => 39, + 'a_names' => 40, + 'a_phpinfo' => 41, + 'a_profile' => 42, + 'a_prune' => 43, + 'a_ranks' => 44, + 'a_reasons' => 45, + 'a_roles' => 46, + 'a_search' => 47, + 'a_server' => 48, + 'a_storage' => 49, + 'a_styles' => 50, + 'a_switchperm' => 51, + 'a_uauth' => 52, + 'a_user' => 53, + 'a_userdel' => 54, + 'a_viewauth' => 55, + 'a_viewlogs' => 56, + 'a_words' => 57, + 'u_' => 58, + 'u_attach' => 59, + 'u_chgavatar' => 60, + 'u_chgcensors' => 61, + 'u_chgemail' => 62, + 'u_chggrp' => 63, + 'u_chgname' => 64, + 'u_chgpasswd' => 65, + 'u_chgprofileinfo' => 66, + 'u_download' => 67, + 'u_hideonline' => 68, + 'u_ignoreflood' => 69, + 'u_masspm' => 70, + 'u_masspm_group' => 71, + 'u_pm_attach' => 72, + 'u_pm_bbcode' => 73, + 'u_pm_delete' => 74, + 'u_pm_download' => 75, + 'u_pm_edit' => 76, + 'u_pm_emailpm' => 77, + 'u_pm_flash' => 78, + 'u_pm_forward' => 79, + 'u_pm_img' => 80, + 'u_pm_printpm' => 81, + 'u_pm_smilies' => 82, + 'u_readpm' => 83, + 'u_savedrafts' => 84, + 'u_search' => 85, + 'u_sendemail' => 86, + 'u_sendim' => 87, + 'u_sendpm' => 88, + 'u_sig' => 89, + 'u_viewonline' => 90, + 'u_viewprofile' => 91, + 'u_dae_user' => 92, + 'a_dae_admin' => 93 + ) + ); + + $mx_cache->put('_acl_options', $this->acl_options); + } + + if (!isset($userdata['user_permissions']) || !trim($userdata['user_permissions'])) + { + $this->acl_cache($userdata); + } + + // Fill ACL array + $this->_fill_acl($userdata['user_permissions']); + + // Verify bitstring length with options provided... + $renew = false; + $global_length = count($this->acl_options['global']); + $local_length = count($this->acl_options['local']); + + // Specify comparing length (bitstring is padded to 31 bits) + $global_length = ($global_length % 31) ? ($global_length - ($global_length % 31) + 31) : $global_length; + $local_length = ($local_length % 31) ? ($local_length - ($local_length % 31) + 31) : $local_length; + + // You thought we are finished now? Noooo... now compare them. + foreach ($this->acl as $forum_id => $bitstring) + { + if (($forum_id && strlen($bitstring) != $local_length) || (!$forum_id && strlen($bitstring) != $global_length)) + { + $renew = true; + break; + } + } + + // If a bitstring within the list does not match the options, we have a user with incorrect permissions set and need to renew them + if ($renew) + { + $this->acl_cache($userdata); + $this->_fill_acl($userdata['user_permissions']); + } + + return; + } + + /** + * Build bitstring from permission set + */ + function build_bitstring(&$hold_ary) + { + $hold_str = ''; + + if (count($hold_ary)) + { + ksort($hold_ary); + + $last_f = 0; + + foreach ($hold_ary as $f => $auth_ary) + { + $ary_key = (!$f) ? 'global' : 'local'; + + $bitstring = array(); + foreach ($this->acl_options[$ary_key] as $opt => $id) + { + if (isset($auth_ary[$this->acl_options['id'][$opt]])) + { + $bitstring[$id] = $auth_ary[$this->acl_options['id'][$opt]]; + + $option_key = substr($opt, 0, strpos($opt, '_') + 1); + + // If one option is allowed, the global permission for this option has to be allowed too + // example: if the user has the a_ permission this means he has one or more a_* permissions + if ($auth_ary[$this->acl_options['id'][$opt]] == ACL_YES && (!isset($bitstring[$this->acl_options[$ary_key][$option_key]]) || $bitstring[$this->acl_options[$ary_key][$option_key]] == ACL_NEVER)) + { + $bitstring[$this->acl_options[$ary_key][$option_key]] = ACL_YES; + } + } + else + { + $bitstring[$id] = ACL_NEVER; + } + } + + // Now this bitstring defines the permission setting for the current forum $f (or global setting) + $bitstring = implode('', $bitstring); + + // The line number indicates the id, therefore we have to add empty lines for those ids not present + $hold_str .= str_repeat("\n", $f - $last_f); + + // Convert bitstring for storage - we do not use binary/bytes because PHP's string functions are not fully binary safe + for ($i = 0, $bit_length = strlen($bitstring); $i < $bit_length; $i += 31) + { + $hold_str .= str_pad(base_convert(str_pad(substr($bitstring, $i, 31), 31, 0, STR_PAD_RIGHT), 2, 36), 6, 0, STR_PAD_LEFT); + } + + $last_f = $f; + } + unset($bitstring); + + $hold_str = rtrim($hold_str); + } + + return $hold_str; + } + + /** + * Cache data to user_permissions row + */ + function acl_cache(&$userdata) + { + global $db; + + // Empty user_permissions + $userdata['user_permissions'] = ''; + + $hold_ary = $this->acl_raw_data_single_user($userdata['user_id']); + + // Key 0 in $hold_ary are global options, all others are forum_ids + + // If this user is founder we're going to force fill the admin options ... + if ($userdata['user_level'] == ADMIN) + { + foreach ($this->acl_options['global'] as $opt => $id) + { + if (strpos($opt, 'a_') === 0) + { + $hold_ary[0][$this->acl_options['id'][$opt]] = ACL_YES; + } + } + } + + $hold_str = $this->build_bitstring($hold_ary); + + if ($hold_str) + { + $userdata['user_permissions'] = $hold_str; + + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_permissions = '" . $db->sql_escape($userdata['user_permissions']) . "', + user_perm_from = 0 + WHERE user_id = " . $userdata['user_id']; + if (!($db->sql_query($sql))) + { + // If the column exists we change it, else we add it ;) + $table = USERS_TABLE; + + $column_data = $userdata; + + if (!class_exists('phpbb_db_tools') && !class_exists('tools')) + { + global $phpbb_root_path, $phpEx; + require($phpbb_root_path . 'includes/db/tools.' . $phpEx); + } + + if (class_exists('phpbb_db_tools')) + { + $db_tools = new phpbb_db_tools($db); + } + elseif (class_exists('tools')) + { + $db_tools = new tools($db); + } + + if (is_object($db_tools)) + { + if ($db_tools->sql_column_exists($table, 'user_perm_from')) + { + $result = true; + } + else + { + $column_name = 'user_perm_from'; + + $column_data['column_type_sql'] = 'TEXT'; + $column_data['user_perm_from'] = '0'; + + $result = $db_tools->sql_column_add($table, $column_name, $column_data, true); + + if (!$result) + { + $after = (!empty($column_data['after'])) ? ' AFTER ' . $column_data['after'] : ''; + $sql = 'ALTER TABLE `' . $table . '` ADD `' . $column_name . '` ' . (($column_data['column_type_sql'] = 'NULL') ? 'TEXT' : $column_data['column_type_sql']) . ' ' . (!empty($column_data[$column_name]) ? $column_data[$column_name] : 'NULL') . ' DEFAULT NULL' . $after; + + // We could add error handling here... + $result = $db->sql_query($sql); + if (!($result)) + { + mx_message_die(CRITICAL_ERROR, "Could not info", '', __LINE__, __FILE__, $sql); + } + } + } + + if ($db_tools->sql_column_exists($table, 'user_permissions')) + { + $result = true; + } + else + { + $column_name = 'user_permissions'; + + $column_data['column_type_sql'] = 'TEXT'; + $column_data['user_permissions'] = 'NULL'; + + $result = $db_tools->sql_column_add($table, $column_name, $column_data, true); + + if (!$result) + { + $after = (!empty($column_data['after'])) ? ' AFTER ' . $column_data['after'] : ''; + $sql = 'ALTER TABLE `' . $table . '` ADD `' . $column_name . '` ' . (($column_data['column_type_sql'] = 'NULL') ? 'TEXT' : $column_data['column_type_sql']) . ' ' . (!empty($column_data[$column_name]) ? $column_data[$column_name] : 'NULL') . ' DEFAULT NULL' . $after; + + // We could add error handling here... + $result = $db->sql_query($sql); + if (!($result)) + { + mx_message_die(CRITICAL_ERROR, "Could not info", '', __LINE__, __FILE__, $sql); + } + } + } + + if ($db_tools->sql_column_exists($table, 'user_birthday')) + { + $result = true; + } + else + { + $column_name = 'user_birthday'; + + $column_data['column_type_sql'] = 'TEXT'; + $column_data['user_birthday'] = 'NULL'; + + $result = $db_tools->sql_column_add($table, $column_name, $column_data, true); + + if (!$result) + { + $after = (!empty($column_data['after'])) ? ' AFTER ' . $column_data['after'] : ''; + $statements[] = 'ALTER TABLE `' . $table . '` ADD `' . $column_name . '` ' . (($column_data['column_type_sql'] = 'NULL') ? 'TEXT' : $column_data['column_type_sql']) . ' ' . (!empty($column_data[$column_name]) ? $column_data[$column_name] : 'NULL') . ' DEFAULT NULL' . $after; + + // We could add error handling here... + $result = $db->sql_query($sql); + if (!($result)) + { + mx_message_die(CRITICAL_ERROR, "Could not info", '', __LINE__, __FILE__, $sql); + } + } + } + } + } + } + + return; + } + /** * get_auth_forum * @@ -158,6 +828,335 @@ function acl_getfignore($auth_level_read, $ignore_forum_ids) $ignore_forum_ids = ($ignore_forum_ids) ? $ignore_forum_ids : -1; return $ignore_forum_ids; } + + /** + * Retrieves data wanted by acl function from the database for the + * specified user. + * + * @param int $user_id User ID + * @return array User attributes + */ + public function obtain_user_data($user_id) + { + global $db; + + $sql = 'SELECT u.user_id, u.username, u.user_permissions, u.user_type, u.user_id as user_colour, u.user_level as user_type, u.user_avatar as avatar, u.user_avatar_type as avatar_type + FROM ' . USERS_TABLE . ' u + WHERE user_id = ' . $user_id; + if (!($result = $db->sql_query($sql))) + { + mx_message_die(CRITICAL_ERROR, 'Could not query user info'); + } + $user_data = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + return $user_data; + } + + /** + * Fill ACL array with relevant bitstrings from user_permissions column + * @access private + */ + function _fill_acl($user_permissions) + { + $seq_cache = array(); + $this->acl = array(); + $user_permissions = explode("\n", $user_permissions); + + foreach ($user_permissions as $f => $seq) + { + if ($seq) + { + $i = 0; + + if (!isset($this->acl[$f])) + { + $this->acl[$f] = ''; + } + + while ($subseq = substr($seq, $i, 6)) + { + if (isset($seq_cache[$subseq])) + { + $converted = $seq_cache[$subseq]; + } + else + { + $converted = $seq_cache[$subseq] = str_pad(base_convert($subseq, 36, 2), 31, 0, STR_PAD_LEFT); + } + + // We put the original bitstring into the acl array + $this->acl[$f] .= $converted; + $i += 6; + } + } + } + } + + /** + * Look up an option + * if the option is prefixed with !, then the result becomes negated + * + * If a forum id is specified the local option will be combined with a global option if one exist. + * If a forum id is not specified, only the global option will be checked. + */ + function acl_get($opt, $f = 0) + { + global $mx_user; + + $negate = false; + + if (strpos($opt, '!') === 0) + { + $negate = true; + $opt = substr($opt, 1); + } + + if (!isset($this->cache[$f][$opt])) + { + // We combine the global/local option with an OR because some options are global and local. + // If the user has the global permission the local one is true too and vice versa + $this->cache[$f][$opt] = false; + + // Is this option a global permission setting? + if (isset($this->acl_options['global'][$opt])) + { + if (isset($this->acl[0])) + { + $this->cache[$f][$opt] = $this->acl[0][$this->acl_options['global'][$opt]]; + } + } + + // Is this option a local permission setting? + // But if we check for a global option only, we won't combine the options... + if (($f != 0) && isset($this->acl_options['local'][$opt])) + { + if (isset($this->acl[$f]) && isset($this->acl[$f][$this->acl_options['local'][$opt]])) + { + $this->cache[$f][$opt] |= $this->acl[$f][$this->acl_options['local'][$opt]]; + } + } + } + + //'124' => 'u_viewonline', + //'125' => 'u_viewprofile', + if (strpos($opt, 'u_view') === 0) + { + $this->cache[$f][$opt] = ($mx_user->data['user_id'] != ANONYMOUS) ? true : false; + } + + //'89' => 'a_viewauth', + //'90' => 'a_viewlogs', + if (strpos($opt, 'a_view') === 0) + { + $this->cache[$f][$opt] = ($mx_user->data['user_level'] == ADMIN) ? true : false; + } + + // Founder always has all global options set to true... + return ($negate) ? !$this->cache[$f][$opt] : $this->cache[$f][$opt]; + } + + /** + * Get forums with the specified permission setting + * if the option is prefixed with !, then the result becomes nagated + * + * @param bool $clean set to true if only values needs to be returned which are set/unset + */ + function acl_getf($opt, $clean = false) + { + $acl_f = array(); + $negate = false; + + if (strpos($opt, '!') === 0) + { + $negate = true; + $opt = substr($opt, 1); + } + + // If we retrieve a list of forums not having permissions in, we need to get every forum_id + if ($negate) + { + if ($this->acl_forum_ids === false) + { + global $db; + + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE; + + if (sizeof($this->acl)) + { + $sql .= ' WHERE ' . $db->sql_in_set('forum_id', array_keys($this->acl), true); + } + $result = $db->sql_query($sql); + + $this->acl_forum_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $this->acl_forum_ids[] = $row['forum_id']; + } + $db->sql_freeresult($result); + } + } + + if (isset($this->acl_options['local'][$opt])) + { + foreach ($this->acl as $f => $bitstring) + { + // Skip global settings + if (!$f) + { + continue; + } + + $allowed = (!isset($this->cache[$f][$opt])) ? $this->acl_get($opt, $f) : $this->cache[$f][$opt]; + + if (!$clean) + { + $acl_f[$f][$opt] = ($negate) ? !$allowed : $allowed; + } + else + { + if (($negate && !$allowed) || (!$negate && $allowed)) + { + $acl_f[$f][$opt] = 1; + } + } + } + } + + // If we get forum_ids not having this permission, we need to fill the remaining parts + if ($negate && sizeof($this->acl_forum_ids)) + { + foreach ($this->acl_forum_ids as $f) + { + $acl_f[$f][$opt] = 1; + } + } + + return $acl_f; + } + + /** + * Get local permission state for any forum. + * + * Returns true if user has the permission in one or more forums, false if in no forum. + * If global option is checked it returns the global state (same as acl_get($opt)) + * Local option has precedence... + */ + function acl_getf_global($opt) + { + if (is_array($opt)) + { + // evaluates to true as soon as acl_getf_global is true for one option + foreach ($opt as $check_option) + { + if ($this->acl_getf_global($check_option)) + { + return true; + } + } + + return false; + } + + if (isset($this->acl_options['local'][$opt])) + { + foreach ($this->acl as $f => $bitstring) + { + // Skip global settings + if (!$f) + { + continue; + } + + // as soon as the user has any permission we're done so return true + if ((!isset($this->cache[$f][$opt])) ? $this->acl_get($opt, $f) : $this->cache[$f][$opt]) + { + return true; + } + } + } + else if (isset($this->acl_options['global'][$opt])) + { + return $this->acl_get($opt); + } + + return false; + } + + /** + * Get permission settings (more than one) + */ + function acl_gets() + { + $args = func_get_args(); + $f = array_pop($args); + + if (!is_numeric($f)) + { + $args[] = $f; + $f = 0; + } + + // alternate syntax: acl_gets(array('m_', 'a_'), $forum_id) + if (is_array($args[0])) + { + $args = $args[0]; + } + + $acl = 0; + foreach ($args as $opt) + { + $acl |= $this->acl_get($opt, $f); + } + + return $acl; + } + + /** + * Get permission listing based on user_id/options/forum_ids + */ + function acl_get_list($user_id = false, $opts = false, $forum_id = false) + { + if ($user_id !== false && !is_array($user_id) && $opts === false && $forum_id === false) + { + $hold_ary = array($user_id => $this->acl_raw_data_single_user($user_id)); + } + else + { + $hold_ary = $this->acl_raw_data($user_id, $opts, $forum_id); + } + + $auth_ary = array(); + foreach ($hold_ary as $user_id => $forum_ary) + { + foreach ($forum_ary as $forum_id => $auth_option_ary) + { + foreach ($auth_option_ary as $auth_option => $auth_setting) + { + if ($auth_setting) + { + $auth_ary[$forum_id][$auth_option][] = $user_id; + } + } + } + } + + return $auth_ary; + } + + /** + * Get raw acl data based on user for caching user_permissions + * This function returns the same data as acl_raw_data(), but without the user id as the first key within the array. + */ + function acl_raw_data_single_user($user_id) + { + global $db, $mx_cache, $user; + + $hold_ary = array(); + $hold_ary = $this->auth(AUTH_VIEW, AUTH_LIST_ALL, $user->data); + return $hold_ary; + } + } // @@ -175,7 +1174,25 @@ class mx_backend // XS Template - use backend db settings // var $edit_db = true; - + var $page_id = 1; + var $user_ip = 'ffffff'; + + /***/ + function mx_backend() + { + // Obtain and encode users IP + // from MXP 2.7.x common + // I'm removing HTTP_X_FORWARDED_FOR ... this may well cause other problems such as + // private range IP's appearing instead of the guilty routable IP, tough, don't + // even bother complaining ... go scream and shout at the idiots out there who feel + // "clever" is doing harm rather than good ... karma is a great thing ... :) + // + $this->client_ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ( ( !empty($_ENV['REMOTE_ADDR']) ) ? $_ENV['REMOTE_ADDR'] : getenv('REMOTE_ADDR') ); + $ip_sep = explode('.', $this->client_ip); + $this->user_ip = sprintf('%02x%02x%02x%02x', $ip_sep[0], $ip_sep[1], $ip_sep[2], $ip_sep[3]); + } + /***/ + /** * Validate backend * @@ -189,38 +1206,71 @@ function validate_backend() global $table_prefix, $phpEx, $tplEx; $table_prefix = ''; - + // + // Define backend template extension + // + $tplEx = 'tpl'; + // // Define relative path to phpBB, and validate // - $phpbb_root_path = $mx_root_path . $portal_config['portal_backend_path']; + $phpbb_root_path = $phpbb_root_path ? $phpbb_root_path : $mx_root_path . $portal_config['portal_backend_path']; str_replace("//", "/", $phpbb_root_path); $portal_backend_valid_file = @file_exists($phpbb_root_path . "modcp.$phpEx"); // // Load phpbb config.php (to get table prefix) - // - if ((include $phpbb_root_path . "config.$phpEx") === false) - { - die('Configuration file (config) ' . $phpbb_root_path . "/config.$phpEx" . ' couldn\'t be opened.'); + // If this fails MXP2 will not work + // + if ((file_exists($phpbb_root_path . "config.$phpEx") === true)) + { + $backend_info = $this->get_phpbb_info($phpbb_root_path . "config.$phpEx"); + + // phpBB 2.x auto-generated config file + // Do not change anything in this file! + + $dbms = $backend_info['dbms']; + + $dbhost = $backend_info['dbhost']; + $dbname = $backend_info['dbname']; + $dbuser = $backend_info['dbuser']; + $dbpasswd = $backend_info['dbpasswd']; + + $table_prefix = $backend_info['table_prefix']; + + if( !isset($backend_info['dbms']) || $backend_info['dbms'] != $dbms || $backend_info['dbhost'] != $dbhost || $backend_info['dbname'] != $dbname || $backend_info['dbuser'] != $dbuser || $backend_info['dbpasswd'] != $dbpasswd || $backend_info['table_prefix'] != $table_prefix ) + { + if ((include $phpbb_root_path . "config.$phpEx") === false) + { + print('Configuration file (config) ' . $phpbb_root_path . "/config.$phpEx" . ' couldn\'t be opened.'); + } + } + + // + // Validate db connection for backend + // + $_result = $db->sql_query( "SELECT config_value from " . $table_prefix . "config WHERE config_name = 'cookie_domain'" ); + $portal_backend_valid_db = $db->sql_numrows($_result) != 0; } + else + { + print('Configuration file (config) ' . $phpbb_root_path . "config.$phpEx" . ' couldn\'t be opened.'); - // - // Define backend template extension - // - $tplEx = 'tpl'; - - // - // Validate db connection for backend - // - $_result = $db->sql_query( "SELECT config_value from " . $table_prefix . "config WHERE config_name = 'cookie_domain'" ); - $portal_backend_valid_db = $db->sql_numrows( $_result ) != 0; - + if ((include $mx_root_path . "config.$phpEx") === false) + { + print('Configuration file (config) ' . $phpbb_root_path . "/config.$phpEx" . ' couldn\'t be opened.'); + } + // + // Validate db connection for backend + // + $_result = $db->sql_query( "SELECT config_value from " . $table_prefix . "config WHERE config_name = 'cookie_domain'" ); + $portal_backend_valid_db = $db->sql_numrows($_result) != 0; + } return $portal_backend_valid_file && !empty($table_prefix) && $portal_backend_valid_db; } /** - * setup_backend + * $mx_backend->setup_backend() * * Define some general backend definitions * PORTAL_URL, PHPBB_URL, PORTAL_VERSION & $board_config @@ -228,30 +1278,89 @@ function validate_backend() */ function setup_backend() { - global $portal_config, $board_config, $phpbb_root_path, $phpEx; + global $mx_cache, $portal_config, $board_config, $mx_root_path, $phpbb_root_path, $phpEx; $script_name = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($portal_config['script_path'])); $server_name = trim($portal_config['server_name']); $server_protocol = ( $portal_config['cookie_secure'] ) ? 'https://' : 'http://'; $server_port = (($portal_config['server_port']) && ($portal_config['server_port'] <> 80)) ? ':' . trim($portal_config['server_port']) . '/' : '/'; - - + $portal_config['portal_phpbb_url'] = str_replace("//", "/", $server_name . $server_port . $script_name . '/'); $server_url = $server_protocol . str_replace("//", "/", $server_name . $server_port . $script_name . '/'); //On some server the slash is not added and this trick will fix it - define('PORTAL_URL', $server_url); - define('PORTAL_VERSION', $portal_config['portal_version']); - // // Grab phpBB global variables, re-cache if necessary // - optional parameter to enable/disable cache for config data. If enabled, remember to refresh the MX-Publisher cache whenever updating phpBB config settings // - true: enable cache, false: disable cache - $board_config = $this->obtain_phpbb_config(false); - - $script_name_phpbb = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($board_config['script_path'])) . '/'; - - $server_url_phpbb = $server_protocol . $server_name . $server_port . $script_name_phpbb; + if (empty($board_config['script_path'])) + { + $board_config = $mx_cache->obtain_phpbb_config(false); + } + + if (empty($portal_config['portal_version'])) + { + $portal_config = $mx_cache->obtain_mxbb_config(false); + } + /** + $this->data = !empty($this->data['user_id']) ? $this->data : $mx_user->session_pagestart($user_ip, $page_id); + + $this->cache = is_object($mx_cache) ? $mx_cache : new base(); + */ + if (preg_match('/bot|crawl|curl|dataprovider|search|get|spider|find|java|majesticsEO|google|yahoo|teoma|contaxe|yandex|libwww-perl|facebookexternalhit/i', $_SERVER['HTTP_USER_AGENT'])) + { + $this->data['is_bot'] = true; + } + else + { + $this->data['is_bot'] = false; + } + + // + // Populate session_id + // + //$this->session_id = $this->data['session_id']; + $this->lang_path = $phpbb_root_path . 'language/'; + + $script_name = !empty($board_config['server_name']) ? preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($board_config['server_name'])) : 'localhost'; + $server_protocol = ( $board_config['cookie_secure'] ) ? 'https://' : 'http://'; + $server_port = (($board_config['server_port']) && ($board_config['server_port'] <> 80)) ? ':' . trim($portal_config['server_port']) . '/' : '/'; + $script_name_phpbb = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($board_config['script_path'])) . '/'; + + if (!empty($portal_config['portal_url'])) + { + $corrected_url = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($portal_config['portal_url'])) . '/'; + } + else + { + $corrected_url = str_replace(array('phpBB/', $script_name_phpbb, str_replace('./../', '', $phpbb_root_path)), '', $portal_config['portal_phpbb_url'] . '/'); + $corrected_url = (empty($portal_config['portal_phpbb_url']) || preg_match('@^(?:phpbb.com)?([^/]+)@i', $portal_config['portal_phpbb_url'])) ? $server_protocol . str_replace("//", "/", $server_name . $server_port . $script_name . '/') : str_replace(array('https://', 'http://'), $server_protocol, $server_url) ; //On some server the slash is not added and this trick will fix it + } + + $board_url = $server_url; + + define('PORTAL_VERSION', $portal_config['portal_version']); + + $server_url_phpbb = $server_protocol . (isset($server_name) ? $server_name : $script_name) . $server_port . $script_name_phpbb; + + if (empty($portal_config['portal_phpbb_url']) || preg_match('@^(?:phpbb.com)?([^/]+)@i', $portal_config['portal_phpbb_url'])) + { + $portal_config['portal_phpbb_url'] = !empty($portal_config['portal_url']) ? $server_url . $script_name_phpbb : $server_url_phpbb; + } + + $server_url_phpbb = !empty($portal_config['portal_phpbb_url']) ? $server_url . $script_name_phpbb : $server_url_phpbb; + $server_url_phpbb = (empty($portal_config['portal_phpbb_url']) || preg_match('@^(?:phpbb.com)?([^/]+)@i', $portal_config['portal_phpbb_url'])) ? $server_url_phpbb : $portal_config['portal_phpbb_url']; + define('PHPBB_URL', $server_url_phpbb); - + define('PORTAL_URL', $board_url); + define('BOARD_URL', $server_url); + + $web_path = (isset($portal_config['portal_url'])) ? $board_url : $corrected_url; + + // + // Define backend template extension + // + $tplEx = 'tpl'; + if (!defined('TPL_EXT')) define('TPL_EXT', $tplEx); + // // Now sync Configs // In phpBB mode, we rely on native phpBB configs, thus we need to sync mxp and phpbb settings @@ -262,7 +1371,7 @@ function setup_backend() // Dummy include, to make all original phpBB functions available // include_once($phpbb_root_path . 'includes/functions.' . $phpEx); // In case we need old functions... - + include_once($mx_root_path . 'includes/shared/phpbb3/includes/functions.' . $phpEx); // // Is phpBB File Attachment MOD present? // @@ -389,42 +1498,295 @@ function sync_configs() } /** - * load_file + * load_file + * + * @param unknown_type $force_shared + * @access private + */ + function load_file($force_shared) + { + global $mx_root_path, $phpbb_root_path, $phpEx; + + if ($force_shared) + { + $shared = in_array($force_shared, array('internal', 'phpbb2', 'phpbb3')) ? $force_shared : PORTAL_BACKEND; + + switch ($shared) + { + case 'internal': + case 'phpbb2': + $path = $mx_root_path . 'includes/shared/phpbb2/includes/'; + break; + case 'phpbb3': + default: + $path = $mx_root_path . 'includes/shared/phpbb3/includes/'; + break; + } + } + else + { + $path = $phpbb_root_path . 'includes/'; + } + + return $path; + } + + /** + * get_phpbb_info + * + * @param unknown_type $root_path + * @access private + */ + function get_mxp_info($root_path, $backend = 'phpbb2', $phpbbversion = '2.0.24') + { + $phpEx = substr(strrchr(__FILE__, '.'), 1); + + if (strpos($root_path, '.') !== false) + { + // Nested file + $filename_ext = substr(strrchr($root_path, '.'), 1); + $filename = basename($root_path, '.' . $filename_ext); + $current_dir = dirname(realpath($root_path)); + $root_path = dirname($root_path); + } + else + { + $filename_ext = substr(strrchr(__FILE__, '.'), 1); + $filename = "config"; + $current_dir = $root_path; + $root_path = dirname($root_path); + } + + $config = $root_path . "/config.$phpEx"; + + // + if ((@include $config) === false) + { + die('Configuration file ' . $config . ' couldn\'t be opened.'); + } + // + + // Check the prefix length to ensure that index names are not too long and does not contain invalid characters + switch ($backend) + { + case 'internal': + // no break; + case 'phpbb2': + $phpbb_adm_relative_path = 'admin'; + break; + + case 'phpbb3': + case 'olympus': + $phpbb_adm_relative_path = 'adm'; + break; + + case 'ascraeus': + case 'rhea': + case 'proteus': + $phpbb_adm_relative_path = (isset($phpbb_adm_relative_path)) ? $phpbb_adm_relative_path : 'adm/'; + $dbms = get_keys_sufix($dbms); + $acm_type = get_keys_sufix($acm_type); + break; + } + + // If we are on PHP < 5.0.0 we need to force include or we get a blank page + if (version_compare(PHP_VERSION, '5.0.0', '<')) + { + $dbms = str_replace('mysqli', 'mysql4', $dbms); //this version of php does not have mysqli extension and my crash the installer if finds a forum using this + } + + return array( + 'dbms' => $dbms, + 'dbhost' => $dbhost, + 'dbname' => $dbname, + 'dbuser' => $dbuser, + 'dbpasswd' => $dbpasswd, + 'mx_table_prefix' => $mx_table_prefix, + 'table_prefix' => $table_prefix, + 'backend' => $backend, + 'version' => $phpbbversion, + 'acm_type' => isset($acm_type) ? $acm_type : '', + 'phpbb_root_path' => $phpbb_root_path, + 'status' => defined('MX_INSTALLED') ? true : false, + ); + } + + /** + * get_phpbb_info * - * @param unknown_type $force_shared + * @param unknown_type $root_path * @access private */ - function load_file($force_shared) + function get_phpbb_info($root_path, $backend = 'phpbb2', $phpbbversion = '2.0.24') { - global $mx_root_path, $phpbb_root_path, $phpEx; - - if ($force_shared) + $phpEx = substr(strrchr(__FILE__, '.'), 1); + + if (strpos($root_path, '.') !== false) { - $shared = in_array($force_shared, array('internal', 'phpbb2', 'phpbb3')) ? $force_shared : PORTAL_BACKEND; - switch ($shared) + // Nested file + $filename_ext = substr(strrchr($root_path, '.'), 1); + $filename = basename($root_path, '.' . $filename_ext); + $current_dir = dirname(realpath($root_path)); + $root_path = dirname($root_path); + } + else + { + $filename_ext = substr(strrchr(__FILE__, '.'), 1); + $filename = "config"; + $current_dir = $root_path; + $root_path = dirname($root_path); + } + + $config = $root_path . "/config.$phpEx"; + + // + if ((@include $config) === false) + { + die('Configuration file ' . $config . ' couldn\'t be opened.'); + } + // + + if ((@include $root_path . "language/en/install.$phpEx") !== false) + { + $left_piece1 = explode('. You', $lang['CONVERT_COMPLETE_EXPLAIN']); + $left_piece2 = explode('phpBB', $left_piece1[0]); + $phpbbversion = strrchr($left_piece2[1], ' '); + + switch (true) { - case 'internal': - case 'phpbb2': - case 'smf2': - case 'mybb': - $path = $mx_root_path . 'includes/shared/phpbb2/includes/'; + case (preg_match('/3.0/i', $phpbbversion)): + $backend = 'olympus'; break; - - case 'phpbb3': - case 'olympus': - case 'ascraeus': - case 'rhea': - $path = $mx_root_path . 'includes/shared/phpbb3/includes/'; + case (preg_match('/3.1/i', $phpbbversion)): + $backend = 'ascraeus'; + break; + case (preg_match('/3.2/i', $phpbbversion)): + $backend = 'rhea'; + break; + case (preg_match('/3.3/i', $phpbbversion)): + $backend = 'proteus'; + break; + case (preg_match('/4./i', $phpbbversion)): + $backend = 'phpbb4'; break; } + } + + // Check the prefix length to ensure that index names are not too long and does not contain invalid characters + switch ($backend) + { + case 'internal': + // no break; + case 'phpbb2': + $phpbb_adm_relative_path = 'admin'; + break; + + case 'phpbb3': + case 'olympus': + $phpbb_adm_relative_path = 'adm'; + break; + + case 'ascraeus': + case 'rhea': + case 'proteus': + $phpbb_adm_relative_path = (isset($phpbb_adm_relative_path)) ? $phpbb_adm_relative_path : 'adm/'; + $dbms = get_keys_sufix($dbms); + $acm_type = get_keys_sufix($acm_type); + break; } - else + + // If we are on PHP < 5.0.0 we need to force include or we get a blank page + if (version_compare(PHP_VERSION, '5.0.0', '<')) + { + $dbms = str_replace('mysqli', 'mysql4', $dbms); //this version of php does not have mysqli extension and my crash the installer if finds a forum using this + } + + return array( + 'dbms' => $dbms, + 'dbhost' => $dbhost, + 'dbname' => $dbname, + 'dbuser' => $dbuser, + 'dbpasswd' => $dbpasswd, + 'table_prefix' => $table_prefix, + 'backend' => $backend, + 'version' => $phpbbversion, + 'acm_type' => isset($acm_type) ? $acm_type : '', + 'status' => defined('PHPBB_INSTALLED') ? true : false, + ); + } + + /** + * get_smf_info + * + * @param unknown_type $settings + * @access private + * / + function get_smf_info($settings) + { + if ((@include $settings) === false) { - $path = $phpbb_root_path . 'includes/'; + install_die(GENERAL_ERROR, 'Configuration file ' . $settings . ' couldn\'t be opened.'); + } + // If we are on PHP < 5.0.0 we need to force include or we get a blank page + if (version_compare(PHP_VERSION, '5.0.0', '<')) + { + $db_type = str_replace('mysqli', 'mysql4', $db_type); //this version of php does not have mysqli extension and my crash the installer if finds a forum using this } - return $path; + // If the UTF-8 setting was enabled, add it to the table definitions. + if ($db_character_set == 'utf8') + { + $db_type = str_replace('mysql', 'mysql4', $db_type); + } + return array( + 'dbms' => $db_type, // 'mysql' + 'dbhost' => $db_server, // 'localhost'; + 'dbname' => $db_name, // 'smf'; + 'dbuser' => $db_user, // 'root'; + 'dbpasswd' => $db_passwd, // ''; + 'ssi_dbuser' => $ssi_db_user, // ''; + 'ssi_dbpasswd' => $ssi_db_passwd, // ''; + 'table_prefix' => $db_prefix, // 'smf_'; + 'dbpersist' => $db_persist, // 0; + 'dberror_send' => $db_error_send, // 1; + 'dbcharacter_set' => $db_character_set, + 'acm_type' => '', + 'mtitle' => $mtitle, //# Title for the Maintenance Mode message. + 'status' => ($maintenance != 2) ? true : false, # Set to 1 to enable Maintenance Mode, 2 to make the forum untouchable. (you'll have to make it 0 again manually!) + 'mbname' => $mbname, # The name of your forum. + 'language' => $language, // 'english'; # The default language file set for the forum. + 'boardurl' => $boardurl, // 'http://127.0.0.1/smf'; # URL to your forum's folder. (without the trailing /!) + 'webmaster_email' => $webmaster_email, // 'noreply@myserver.com'; # Email address to send emails from. (like noreply@yourdomain.com.) + 'cookiename' => $cookiename, + ); } - + + /** + * get_mybb_info + * + * @param unknown_type $mybb_config + * @access private + * / + function get_mybb_info($mybb_config) + { + $config = array(); + if ((@include $mybb_config) === false) + { + install_die(GENERAL_ERROR, 'Configuration file ' . $mybb_config . ' couldn\'t be opened.'); + } + return array( + 'dbms' => $config['database']['type'], // 'mysqli'; + 'dbname' => $config['database']['database'], // 'mybb'; + 'table_prefix' => $config['database']['table_prefix'], // 'mybb_'; + + 'dbhost' => $config['database']['hostname'], // 'localhost'; + 'dbname' => $config['database']['username'], // 'Admin'; + 'dbpasswd' => $config['database']['password'], + + 'admin_dir' => $config['admin_dir'], + 'dbcharacter_set' => $config['database']['encoding'], + ); + } + /** * dss_rand * @@ -434,28 +1796,25 @@ function load_file($force_shared) function dss_rand() { global $db, $portal_config, $board_config, $dss_seeded; - + $val = $board_config['rand_seed'] . microtime(); $val = md5($val); $board_config['rand_seed'] = md5($board_config['rand_seed'] . $val . 'a'); - + if($dss_seeded !== true) { $sql = "UPDATE " . CONFIG_TABLE . " SET config_value = '" . $board_config['rand_seed'] . "' WHERE config_name = 'rand_seed'"; - - //display an error debuging message only if the portal is installed/upgraded - if(!@$db->sql_query($sql) && @!file_exists('install')) + + if( !$db->sql_query($sql) ) { mx_message_die(GENERAL_ERROR, "Unable to reseed PRNG", "", __LINE__, __FILE__, $sql); } - elseif(!@$db->sql_query($sql) && @file_exists('install')) - { - mx_message_die(GENERAL_ERROR, "Unable to reseed PRNG"."
Please finish upgrading and
". t(isset($lang['Please_remove_install_contrib'])), "", __LINE__, __FILE__, $sql); - } + $dss_seeded = true; } + return substr($val, 4, 16); } @@ -472,7 +1831,7 @@ function make_jumpbox($action, $match_forum_id = 0) ORDER BY c.cat_order"; if ( !($result = $db->sql_query($sql)) ) { - message_die(GENERAL_ERROR, "Couldn't obtain category list.", "", __LINE__, __FILE__, $sql); + mx_message_die(GENERAL_ERROR, "Couldn't obtain category list.", "", __LINE__, __FILE__, $sql); } $category_rows = array(); @@ -488,7 +1847,7 @@ function make_jumpbox($action, $match_forum_id = 0) ORDER BY cat_id, forum_order"; if ( !($result = $db->sql_query($sql)) ) { - message_die(GENERAL_ERROR, 'Could not obtain forums information', '', __LINE__, __FILE__, $sql); + mx_message_die(GENERAL_ERROR, 'Could not obtain forums information', '', __LINE__, __FILE__, $sql); } $boxstring = ''; + } + + // Let the jumpbox work again in sites having additional session id checks. + // if ( !empty($SID) ) + // { + $boxstring .= ''; + // } + + $template->set_filenames(array( + 'jumpbox' => 'jumpbox.tpl') + ); + + $template->assign_vars(array( + 'L_GO' => $lang['Go'], + 'L_JUMP_TO' => $lang['Jump_to'], + 'L_SELECT_FORUM' => $lang['Select_forum'], + + 'S_JUMPBOX_SELECT' => $boxstring, + 'S_JUMPBOX_ACTION' => mx_append_sid($action), + 'S_FORUM_COUNT' => $j) + ); + + $template->assign_var_from_handle('JUMPBOX', 'jumpbox'); + + return; + } + + /** + * Backend specific Page Header data + * + * @param unknown_type $mode + */ + function page_header($mode = false) + { + global $db, $mx_root_path, $phpbb_root_path, $userdata, $mx_user, $lang, $images, $phpEx, $board_config, $gen_simple_header, $layouttemplate, $mx_page; + + switch ($mode) + { + case 'generate_login_logout_stats': + + if ( $mx_user->data['user_id'] != 1 ) + { + $is_logged = true; + $u_login_logout = 'login.'.$phpEx.'?logout=true&sid=' . $mx_user->data['session_id']; + $l_login_logout = $lang['Logout'] . ' [ ' . $mx_user->data['username'] . ' ]'; + } + else + { + $is_logged = false; + $u_login_logout = 'login.'.$phpEx; + $l_login_logout = $lang['Login']; + } + $s_last_visit = ( $mx_user->data['session_logged_in'] ) ? phpBB2::create_date($board_config['default_dateformat'], $mx_user->data['user_lastvisit'], $board_config['board_timezone']) : ''; + + // + // Obtain number of new private messages + // if user is logged in + // + if ( ($mx_user->data['session_logged_in']) && (empty($gen_simple_header)) ) + { + if ( $mx_user->data['user_new_privmsg'] ) + { + $l_message_new = ( $mx_user->data['user_new_privmsg'] == 1 ) ? $lang['New_pm'] : $lang['New_pms']; + $l_privmsgs_text = sprintf($l_message_new, $mx_user->data['user_new_privmsg']); + + if ( $mx_user->data['user_last_privmsg'] > $mx_user->data['user_lastvisit'] ) + { + $sql = "UPDATE " . USERS_TABLE . " + SET user_last_privmsg = " . $mx_user->data['user_lastvisit'] . " + WHERE user_id = " . $mx_user->data['user_id']; + if ( !$db->sql_query($sql) ) + { + mx_message_die(GENERAL_ERROR, 'Could not update private message new/read time for user', '', __LINE__, __FILE__, $sql); + } + + $s_privmsg_new = 1; + $icon_pm = $images['pm_new_msg']; + } + else + { + $s_privmsg_new = 0; + $icon_pm = $images['pm_no_new_msg']; + } + $mx_priv_msg = $lang['Private_Messages'] . ' (' . $mx_user->data['user_new_privmsg'] . ')'; + } + else + { + $l_privmsgs_text = $lang['No_new_pm']; + + $s_privmsg_new = 0; + $icon_pm = $images['pm_no_new_msg']; + $mx_priv_msg = $lang['Private_Messages']; + } + + if ( $mx_user->data['user_unread_privmsg'] ) + { + $l_message_unread = ( $mx_user->data['user_unread_privmsg'] == 1 ) ? $lang['Unread_pm'] : $lang['Unread_pms']; + $l_privmsgs_text_unread = sprintf($l_message_unread, $mx_user->data['user_unread_privmsg']); + } + else + { + $l_privmsgs_text_unread = $lang['No_unread_pm']; + } + } + else + { + $icon_pm = $images['pm_no_new_msg']; + $l_privmsgs_text = $lang['Login_check_pm']; + $l_privmsgs_text_unread = ''; + $s_privmsg_new = 0; + $mx_priv_msg = $lang['Private_Messages']; + } + + $layouttemplate->assign_vars(array( + 'U_LOGIN_LOGOUT' => mx_append_sid(PORTAL_URL . $u_login_logout), + 'L_LOGIN_LOGOUT' => $l_login_logout, + 'LAST_VISIT_DATE' => sprintf($lang['You_last_visit'], $s_last_visit), + 'PRIVATE_MESSAGE_INFO' => $l_privmsgs_text, + 'PRIVATE_MESSAGE_INFO_UNREAD' => $l_privmsgs_text_unread, + 'PRIVATE_MESSAGE_NEW_FLAG' => $s_privmsg_new, + 'PRIVMSG_IMG' => $icon_pm, + 'L_PRIVATEMSGS' => $mx_priv_msg, + + // Backend + 'PHPBB' => true, + + // Show phpbb stats? + 'PHPBB_STATS' => $mx_page->phpbb_stats, + + // Allow autologin? + 'ALLOW_AUTOLOGIN' => !$userdata['session_logged_in'] && (!isset($board_config['allow_autologin']) || $board_config['allow_autologin']), + + // phpBB PM + 'ENABLE_PM_POPUP' => $userdata['session_logged_in'] && !empty($userdata['user_popup_pm']), + )); + + break; + + case 'generate_nav_links': + + $u_register = 'ucp.'.$phpEx.'?mode=register'; + $u_profile = 'ucp.'.$phpEx; + $u_privatemsgs = 'ucp.'.$phpEx.'?i=pm&folder=inbox'; + $u_privatemsgs_popup ='ucp.'.$phpEx.'?i=pm&mode=popup'; + $u_search = 'search.'.$phpEx; + $u_memberlist = 'memberlist.'.$phpEx; + $u_modcp = 'mcp.'.$phpEx; + $u_faq = 'faq.'.$phpEx; + $u_viewonline = 'viewonline.'.$phpEx; + $u_group_cp = 'ucp.'.$phpEx.'?i=167'; + $u_sendpassword = ($board_config['email_enable']) ? mx3_append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=sendpassword') : ''; + + $layouttemplate->assign_vars(array( + 'U_REGISTER' => mx_append_sid(PHPBB_URL . $u_register), + 'U_PROFILE' => mx_append_sid(PHPBB_URL . $u_profile), + 'U_PRIVATEMSGS' => mx_append_sid(PHPBB_URL . $u_privatemsgs), + 'U_PRIVATEMSGS_POPUP' => mx_append_sid(PHPBB_URL . $u_privatemsgs_popup), + 'U_SEARCH' => mx_append_sid(PHPBB_URL . $u_search), + 'U_MEMBERLIST' =>mx_append_sid(PHPBB_URL . $u_memberlist), + 'U_MODCP' => mx_append_sid(PHPBB_URL . $u_modcp), + 'U_FAQ' => mx_append_sid(PHPBB_URL . $u_faq), + 'U_VIEWONLINE' => mx_append_sid(PHPBB_URL . $u_viewonline), + 'U_GROUP_CP' => mx_append_sid(PHPBB_URL . $u_group_cp), + 'U_SEND_PASSWORD' => $u_sendpassword, + )); + + break; + } + } + + /** + * Backend specific Page Tail data + * + * @param unknown_type $mode + */ + function page_tail($mode = false) + { + global $board_config, $userdata, $template; + + switch ($mode) + { + case 'generate_backend_version': + $current_phpbb_version = $board_config['version']; + + $template->assign_vars(array( + 'PHPBB_BACKEND' => true, + 'PHPBB_VERSION' => ($userdata['user_level'] == ADMIN && $userdata['user_id'] != ANONYMOUS) ? $current_phpbb_version : '', + 'U_PHPBB_ROOT_PATH' => PHPBB_URL, + )); + + break; + } + } + + /** + * obtain_phpbb_config + * + * @access public + * @param boolean $use_cache + * @return unknown + */ + public function obtain_forum_config() + { + global $db, $mx_cache, $phpEx; + + if (!defined('CONFIG_TABLE')) + { + global $table_prefix, $mx_root_path; + + require $mx_root_path. "includes/sessions/phpbb2/constants.$phpEx"; + } + + if (($mx_cache->get('phpbb_config')) === false) + { + $config = $cached_config = array(); + + $sql = 'SELECT config_name, config_value, is_dynamic + FROM ' . CONFIG_TABLE; + if (!($result = $db->sql_query($sql))) + { + if (!function_exists('mx_message_die')) + { + die("Couldnt query config information, Allso this hosting or server is using a cache optimizer not compatible with MX-Publisher or just lost connection to database wile query."); + } + else + { + mx_message_die( GENERAL_ERROR, 'Couldnt query config information', '', __LINE__, __FILE__, $sql ); + } + } + + while ($row = $db->sql_fetchrow($result)) + { + if (!$row['is_dynamic']) + { + $cached_config[$row['config_name']] = $row['config_value']; + } + + $config[$row['config_name']] = $row['config_value']; + } + $db->sql_freeresult($result); + + $mx_cache->put('phpbb_config', $cached_config); + } + else + { + $sql = 'SELECT config_name, config_value + FROM ' . CONFIG_TABLE . ' + WHERE is_dynamic = 1'; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $config[$row['config_name']] = $row['config_value']; + } + $db->sql_freeresult($result); + } + + return $config; + } + + /** + * Set phpbb config values + * + * @param unknown_type $config_name + * @param unknown_type $config_value + */ + public function set_forum_config($key, $new_value, $use_cache = false) + { + global $db, $mx_cache, $phpEx; + + if (!defined('CONFIG_TABLE')) + { + global $table_prefix, $mx_root_path; + + require $mx_root_path. "includes/sessions/phpbb2/constants.$phpEx"; + } + + // Read out config values + $config = $this->obtain_phpbb_config(); + $old_value = !isset($config[$key]) ? $config[$key] : false; + $use_cache = (($key == 'comments_pagination') || ($key == 'pagination')) ? true : false; + + $sql = 'UPDATE ' . CONFIG_TABLE . " + SET config_value = '" . $db->sql_escape($new_value) . "' + WHERE config_name = '" . $db->sql_escape($key) . "'"; + + if ($old_value !== false) + { + $sql .= " AND config_value = '" . $db->sql_escape($old_value) . "'"; + } + + $db->sql_query($sql); + + if (!$db->sql_affectedrows() && isset($config[$key])) + { + return false; + } + + if (!isset($config[$key])) + { + $sql = 'INSERT INTO ' . CONFIG_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'config_name' => $key, + 'config_value' => $new_value)), + 'is_dynamic' => ($use_cache) ? 0 : 1)); + $db->sql_query($sql); + } + + $config[$key] = $new_value; + + + if ($use_cache) + { + $mx_cache->destroy('config'); + $mx_cache->put('config', $config); + } + + return true; + } + + /** + * Get MX-Publisher config data + * + * @access public + * @return unknown + */ + public function obtain_portal_config($use_cache = true) + { + global $db, $mx_cache; + + if ( ($portal_config = $mx_cache->get('mx_config')) && ($use_cache) ) + { + return $portal_config; + } + else + { + $sql = "SELECT * + FROM " . PORTAL_TABLE . " + WHERE portal_id = '1'"; + + if ( !($result = $db->sql_query($sql)) ) + { + if (!function_exists('mx_message_die')) + { + die("Couldnt query portal configuration, Allso this hosting or server is using a cache optimizer not compatible with MX-Publisher or just lost connection to database wile query."); + } + else + { + mx_message_die( GENERAL_ERROR, 'Couldnt query portal configuration', '', __LINE__, __FILE__, $sql ); + } + } + $row = $db->sql_fetchrow($result); + foreach ($row as $config_name => $config_value) + { + $portal_config[$config_name] = trim($config_value); + } + $db->sql_freeresult($result); + $mx_cache->put('mx_config', $portal_config); + + return ($portal_config); + } + } + + /** + * Set config value. Creates missing config entry. + * + */ + function set_portal_config($key, $new_value) + { + global $db, $mx_cache, $portal_config; + + // Read out config values + $portal_config = $this->obtain_portal_config(); + + $new[$key] = $new_value; + + $sql = "UPDATE " . PORTAL_TABLE . " SET " . $db->sql_build_array('UPDATE', utf8_normalize_nfc($new)); + + if( !($db->sql_query($sql)) ) + { + mx_message_die(GENERAL_ERROR, "Failed to update portal configuration ", "", __LINE__, __FILE__, $sql); + } + + if (!$db->sql_affectedrows() && !isset($portal_config[$key])) + { + $sql = 'INSERT INTO ' . PORTAL_TABLE . ' ' . $db->sql_build_array('INSERT', array( + $db->sql_escape($key) => $db->sql_escape($new_value))); + $db->sql_query($sql); + } + + $portal_config[$key] = $new_value; + + $mx_cache->destroy('mx_config'); + } + + /** + * Get userdata + * + * Get Userdata, $mx_user can be username or user_id. If force_str is true, the username will be forced. + * Cached sql, since this function is used for every block. + * + * @param unknown_type $mx_user id or name + * @param boolean $force_str force clean_username + * @return array + */ + function get_userdata($mxuser, $force_str = false) + { + global $db, $phpBB2; + + if (!is_numeric($mxuser) || $force_str) + { + $mx_user = $phpBB2->phpbb_clean_username($mxuser); + } + else + { + $mx_user = intval($mxuser); + } + + $sql = "SELECT * + FROM " . USERS_TABLE . " + WHERE "; + $sql .= ((is_integer($mxuser)) ? "user_id = $mxuser" : "username = '" . str_replace("\'", "''", $mxuser) . "'" ) . " AND user_id <> " . ANONYMOUS; + if (!($result = $db->sql_query($sql, 120))) + { + if (!function_exists('mx_message_die')) + { + die("Tried obtaining data for a non-existent user. Function mx_backend->get_userdata()"); + } + else + { + mx_message_die(GENERAL_ERROR, 'Tried obtaining data for a non-existent user', '', __LINE__, __FILE__, $sql); + } + } + $return = ($row = $db->sql_fetchrow($result)) ? $row : false; + /* + foreach ($row as $user_key => $user_value) + { + $userdata[$user_key] = trim($user_value); + } + */ + $db->sql_freeresult($result); + //return ($userdata); + return $return; + } + + /** + * Set user data value. + * + */ + function set_userdata($key, $new_value) + { + global $db, $mx_user; + + $new[$key] = $new_value; + + $sql = "UPDATE " . USERS_TABLE . " + SET " . $db->sql_build_array('UPDATE', utf8_normalize_nfc($new)) . " + WHERE user_id = '" . $mx_user->data['user_id'] . "'"; + if (!($db->sql_query($sql))) + { + mx_message_die(GENERAL_ERROR, "Failed to update portal configuration ", "", __LINE__, __FILE__, $sql); + } + + if (!$db->sql_affectedrows() && !isset($mx_user->data[$key])) + { + mx_message_die(GENERAL_ERROR, "Wrong Backend? Adding missing entry key to update MXP configuration is not supported ATM.", "", __LINE__, __FILE__, $sql); + } + $mx_user->data[$key] = $new_value; + } + + /** + * Obtain ranks + */ + public function obtain_ranks() + { + global $mx_cache; + + if (($ranks = $mx_cache->get('_ranks')) === false) + { + global $db; + + $sql = 'SELECT * + FROM ' . RANKS_TABLE . ' + ORDER BY rank_min DESC'; + $result = $db->sql_query($sql); + + $ranks = array(); + while ($row = $db->sql_fetchrow($result)) + { + if ($row['rank_special']) + { + $ranks['special'][$row['rank_id']] = array( + 'rank_title' => $row['rank_title'], + 'rank_image' => $row['rank_image'] + ); + } + else + { + $ranks['normal'][] = array( + 'rank_title' => $row['rank_title'], + 'rank_min' => $row['rank_min'], + 'rank_image' => $row['rank_image'] + ); + } + } + $db->sql_freeresult($result); + + $mx_cache->put('_ranks', $ranks); + } + + return $ranks; + } + + /** + * Obtain allowed extensions + * + * @param mixed $forum_id If false then check for private messaging, if int then check for forum id. If true, then only return extension informations. + * + * @return array allowed extensions array. + */ + function obtain_attach_extensions($forum_id) + { + global $mx_cache; + + if (($extensions = $mx_cache->get('_extensions')) === false) + { + global $db; + + $extensions = array( + '_allowed_post' => array(), + '_allowed_pm' => array(), + ); + + // The rule is to only allow those extensions defined. ;) + $sql = 'SELECT e.extension, g.* + FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g + WHERE e.group_id = g.group_id + AND (g.allow_group = 1 OR g.allow_in_pm = 1)'; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $extension = strtolower(trim($row['extension'])); + + $extensions[$extension] = array( + 'display_cat' => (int) $row['cat_id'], + 'download_mode' => (int) $row['download_mode'], + 'upload_icon' => trim($row['upload_icon']), + 'max_filesize' => (int) $row['max_filesize'], + 'allow_group' => $row['allow_group'], + 'allow_in_pm' => $row['allow_in_pm'], + ); + + $allowed_forums = ($row['allowed_forums']) ? unserialize(trim($row['allowed_forums'])) : array(); + + // Store allowed extensions forum wise + if ($row['allow_group']) + { + $extensions['_allowed_post'][$extension] = (!sizeof($allowed_forums)) ? 0 : $allowed_forums; + } + + if ($row['allow_in_pm']) + { + $extensions['_allowed_pm'][$extension] = 0; + } + } + $db->sql_freeresult($result); + + $mx_cache->put('_extensions', $extensions); + } + + // Forum post + if ($forum_id === false) + { + // We are checking for private messages, therefore we only need to get the pm extensions... + $return = array('_allowed_' => array()); + + foreach ($extensions['_allowed_pm'] as $extension => $check) + { + $return['_allowed_'][$extension] = 0; + $return[$extension] = $extensions[$extension]; + } + + $extensions = $return; + } + else if ($forum_id === true) + { + return $extensions; + } + else + { + $forum_id = (int) $forum_id; + $return = array('_allowed_' => array()); + + foreach ($extensions['_allowed_post'] as $extension => $check) + { + // Check for allowed forums + if (is_array($check)) + { + $allowed = (!in_array($forum_id, $check)) ? false : true; + } + else + { + $allowed = true; + } + + if ($allowed) + { + $return['_allowed_'][$extension] = 0; + $return[$extension] = $extensions[$extension]; + } + } + + $extensions = $return; + } + + if (!isset($extensions['_allowed_'])) + { + $extensions['_allowed_'] = array(); + } + + return $extensions; + } + + /** + * Obtain active bots + */ + function obtain_bots() + { + global $mx_cache; + + if (($bots = $mx_cache->get('_bots')) === false) + { + global $db; + + switch ($db->sql_layer) + { + case 'mssql': + case 'mssql_odbc': + $sql = 'SELECT user_id, bot_agent, bot_ip + FROM ' . BOTS_TABLE . ' + WHERE bot_active = 1 + ORDER BY LEN(bot_agent) DESC'; + break; + + case 'firebird': + $sql = 'SELECT user_id, bot_agent, bot_ip + FROM ' . BOTS_TABLE . ' + WHERE bot_active = 1 + ORDER BY CHAR_LENGTH(bot_agent) DESC'; + break; + + // LENGTH supported by MySQL, IBM DB2 and Oracle for sure... + default: + $sql = 'SELECT user_id, bot_agent, bot_ip + FROM ' . BOTS_TABLE . ' + WHERE bot_active = 1 + ORDER BY LENGTH(bot_agent) DESC'; + break; + } + $result = $db->sql_query($sql); + + $bots = array(); + while ($row = $db->sql_fetchrow($result)) + { + $bots[] = $row; + } + $db->sql_freeresult($result); + + $mx_cache->put('_bots', $bots); + } + + return $bots; + } + + /** + * Obtain cfg file data + * + * @param unknown_type $theme + * @return unknown + */ + function obtain_cfg_items($theme) + { + global $board_config, $phpbb_root_path, $mx_cache; + + $parsed_items = array( + 'theme' => array(), + 'template' => array(), + 'imageset' => array() + ); + + foreach ($parsed_items as $key => $parsed_array) + { + $parsed_array = $mx_cache->get('_cfg_' . $key . '_' . $theme[$key . '_path']); + + if ($parsed_array === false) + { + $parsed_array = array(); + } + + $reparse = false; + $filename = $phpbb_root_path . 'styles/' . $theme[$key . '_path'] . '/' . $key . '/' . $key . '.cfg'; + + if (!file_exists($filename)) + { + continue; + } + + if (!isset($parsed_array['filetime']) || (($board_config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime']))) + { + $reparse = true; + } + + // Re-parse cfg file + if ($reparse) + { + $parsed_array = mx_parse_cfg_file($filename); + $parsed_array['filetime'] = @filemtime($filename); + + $mx_cache->put('_cfg_' . $key . '_' . $theme[$key . '_path'], $parsed_array); + } + $parsed_items[$key] = $parsed_array; + } + + return $parsed_items; + } + + /** + * Obtain disallowed usernames + */ + function obtain_disallowed_usernames() + { + global $mx_cache; + + if (($usernames = $mx_cache->get('_disallowed_usernames')) === false) + { + global $db; + + $sql = 'SELECT disallow_username + FROM ' . DISALLOW_TABLE; + $result = $db->sql_query($sql); + + $usernames = array(); + while ($row = $db->sql_fetchrow($result)) + { + $usernames[] = str_replace('%', '.*?', preg_quote(utf8_clean_string($row['disallow_username']), '#')); + } + $db->sql_freeresult($result); + + $mx_cache->put('_disallowed_usernames', $usernames); + } + + return $usernames; + } + + /** + * Obtain hooks... + */ + function obtain_hooks() + { + global $phpbb_root_path, $phpEx, $mx_cache; + + if (($hook_files = $mx_cache->get('_hooks')) === false) + { + $hook_files = array(); + + // Now search for hooks... + $dh = @opendir($phpbb_root_path . 'includes/hooks/'); + + if ($dh) + { + while (($file = readdir($dh)) !== false) + { + if (strpos($file, 'hook_') === 0 && substr($file, -(strlen($phpEx) + 1)) === '.' . $phpEx) + { + $hook_files[] = substr($file, 0, -(strlen($phpEx) + 1)); + } + } + closedir($dh); + } + + $mx_cache->put('_hooks', $hook_files); + } + + return $hook_files; + } + + /** + * Enter description here... + * + * @return unknown + */ + function generate_group_select_sql() + { + // Get us all the groups exept bots and guests + $sql = "SELECT g.group_id, g.group_name, g.group_type + FROM " . GROUPS_TABLE . " g + WHERE g.group_name NOT IN ('BOTS', 'GUESTS') + ORDER BY g.group_type ASC, g.group_name"; + return $sql; + } + + /** + * Enter description here... + * + * @return unknown + */ + function generate_session_online_sql($guest = false) + { + if ($guest) + { + $sql = "SELECT u.*, s.*, s.session_page AS user_session_page + FROM " . USERS_TABLE . " u, " . SESSIONS_TABLE . " s + WHERE u.user_id = " . ANONYMOUS . " + AND u.user_id = s.session_user_id + AND s.session_time >= " . ( time() - 300 ) . " + ORDER BY s.session_time DESC"; + } + else + { + $sql = "SELECT u.*, s.*, s.session_time AS user_session_time, s.session_page AS user_session_page + FROM " . USERS_TABLE . " u, " . SESSIONS_TABLE . " s + WHERE u.user_id <> " . ANONYMOUS . " + AND u.user_id = s.session_user_id + AND s.session_time >= " . ( time() - 300 ) . " + ORDER BY s.session_time DESC"; + } + return $sql; + } + + /** + * Enter description here... + * + * @param unknown_type $str_ip + * @return unknown + */ + function decode_ip($str_ip) + { + return $str_ip; + } + + /** + * Enter description here... + * + * @return unknown + */ + function get_phpbb_version() + { + global $board_config; + + return $board_config['version']; + } + + /** + * Enter description here... + * + * @return unknown + */ + function confirm_backend() + { + global $portal_config; + + return PORTAL_BACKEND == $portal_config['portal_backend']; + } + + /** + * Get username details for placing into templates. + * + * @param string $mode Can be profile (for getting an url to the profile), username (for obtaining the username), colour (for obtaining the user colour) or full (for obtaining a html string representing a coloured link to the users profile). + * @param int $user_id The users id + * @param string $username The users name + * @param string $username_colour The users colour + * @param string $guest_username optional parameter to specify the guest username. It will be used in favor of the GUEST language variable then. + * @param string $custom_profile_url optional parameter to specify a profile url. The user id get appended to this url as &u={user_id} + * + * @return string A string consisting of what is wanted based on $mode. + */ + function get_username_string($mode, $user_id, $username = false, $username_colour = '', $guest_username = false, $custom_profile_url = false) + { + global $phpbb_root_path, $mx_root_path, $phpEx, $mx_user, $phpbb_auth; + + $profile_url = ''; + + //Added by OryNider + if (($username == false) || ($username_colour == false)) + { + $this_userdata = mx_get_userdata($user_id, false); + $user_id = $this_userdata['user_id']; + $username = $this_userdata['username']; + $username_colour = $this_userdata['user_colour']; + } + //Added Ends + + $username_colour = ($username_colour) ? '#' . $username_colour : ''; + + if ($guest_username === false) + { + $username = ($username) ? $username : $mx_user->lang['GUEST']; + } + else + { + $username = ($user_id && $user_id != ANONYMOUS) ? $username : ((!empty($guest_username)) ? $guest_username : $mx_user->lang['GUEST']); + } + + // Only show the link if not anonymous + if ($user_id && $user_id != ANONYMOUS) + { + // Do not show the link if the user is already logged in but do not have u_viewprofile permissions (relevant for bots mostly). + // For all others the link leads to a login page or the profile. + if ($mx_user->data['user_id'] != ANONYMOUS && !$phpbb_auth->acl_get('u_viewprofile')) + { + $profile_url = ''; + } + else + { + $profile_url = ($custom_profile_url !== false) ? $custom_profile_url : mx3_append_sid(PHPBB_URL . "memberlist.$phpEx", 'mode=viewprofile'); + $profile_url .= '&u=' . (int) $user_id; + } + } + else + { + $profile_url = ''; + } + + switch ($mode) + { + case 'profile': + return $profile_url; + break; + + case 'username': + return $username; + break; + + case 'colour': + return $username_colour; + break; + + case 'full': + default: + + $tpl = ''; + if (!$profile_url && !$username_colour) + { + $tpl = '{USERNAME}'; + } + else if (!$profile_url && $username_colour) + { + $tpl = '{USERNAME}'; + } + else if ($profile_url && !$username_colour) + { + $tpl = '{USERNAME}'; + } + else if ($profile_url && $username_colour) + { + $tpl = '{USERNAME}'; + } + + return str_replace(array('{PROFILE_URL}', '{USERNAME_COLOUR}', '{USERNAME}'), array($profile_url, $username_colour, $username), $tpl); + break; + } + } + + // + // ACP + // + /** + * Enter description here... + * + */ + function load_phpbb_acp_menu() + { + global $phpbb_root_path, $template, $lang, $phpEx, $userdata, $mx_user; + + $template->assign_block_vars('module_phpbb', array( + 'L_PHPBB' => $lang['Phpbb'], + "L_FORUM_INDEX" => $lang['Main_index'], + "L_PREVIEW_FORUM" => $lang['Preview_forum'], + "U_FORUM_INDEX" => mx_append_sid(PHPBB_URL . "index.$phpEx"), + )); + + $menu_cat_id = 0; + + $template->assign_block_vars('module_phpbb.catrow', array( + //+MOD: DHTML Menu for ACP + 'MENU_CAT_ID' => $menu_cat_id, + 'MENU_CAT_ROWS' => 1, + //-MOD: DHTML Menu for ACP + 'ADMIN_CATEGORY' => 'Olympus adminCP') + ); + + $template->assign_block_vars('module_phpbb.catrow.modulerow', array( + "ROW_COLOR" => "#" . $mx_user->theme['td_color1'], + "ROW_CLASS" => $mx_user->theme['td_class1'], + //+MOD: DHTML Menu for ACP + 'ROW_COUNT' => 0, + //-MOD: DHTML Menu for ACP + "ADMIN_MODULE" => 'Go!', + "U_ADMIN_MODULE" => mx_append_sid($phpbb_root_path . 'adm/index.php?sid='.$mx_user->session_id)) + ); + } + + /** + * Enter description here... + * + */ + function load_forum_stats() + { + global $db, $template, $board_config, $portal_config, $phpbb_root_path, $mx_root_path, $lang, $theme, $mx_user, $userdata; + + $template->assign_block_vars("forum_stats", array()); + // + // Get forum statistics + // + $total_posts = phpBB2::get_db_stat('postcount'); + $total_users = phpBB2::get_db_stat('usercount'); + $total_topics = phpBB2::get_db_stat('topiccount'); + + $start_date = phpBB2::create_date($board_config['default_dateformat'], $board_config['board_startdate'], $board_config['board_timezone']); + + $boarddays = ( time() - $board_config['board_startdate'] ) / 86400; + + $posts_per_day = sprintf("%.2f", $total_posts / $boarddays); + $topics_per_day = sprintf("%.2f", $total_topics / $boarddays); + $users_per_day = sprintf("%.2f", $total_users / $boarddays); + + $avatar_dir_size = 0; + + if ($avatar_dir = @opendir($phpbb_root_path . $board_config['avatar_path']) ) + { + while( $file = @readdir($avatar_dir) ) + { + if( $file != "." && $file != ".." ) + { + $avatar_dir_size += @filesize($phpbb_root_path . $board_config['avatar_path'] . "/" . $file); + } + } + @closedir($avatar_dir); + + // + // This bit of code translates the avatar directory size into human readable format + // Borrowed the code from the PHP.net annoted manual, origanally written by: + // Jesse (jesse@jess.on.ca) + // + if($avatar_dir_size >= 1048576) + { + $avatar_dir_size = round($avatar_dir_size / 1048576 * 100) / 100 . " MB"; + } + else if($avatar_dir_size >= 1024) + { + $avatar_dir_size = round($avatar_dir_size / 1024 * 100) / 100 . " KB"; + } + else + { + $avatar_dir_size = $avatar_dir_size . " Bytes"; + } + } + else + { + // Couldn't open Avatar dir. + $avatar_dir_size = $lang['Not_available']; + } + + if($posts_per_day > $total_posts) + { + $posts_per_day = $total_posts; + } + + if($topics_per_day > $total_topics) + { + $topics_per_day = $total_topics; + } + + if($users_per_day > $total_users) + { + $users_per_day = $total_users; + } + + // + // DB size ... MySQL only + // + // This code is heavily influenced by a similar routine + // in phpMyAdmin 2.2.0 + // + if( preg_match("/^mysql/", SQL_LAYER) ) + { + $sql = "SELECT VERSION() AS mysql_version"; + if($result = $db->sql_query($sql)) + { + $row = $db->sql_fetchrow($result); + $version = $row['mysql_version']; + + if( preg_match("/^(3\.23|4\.|5\.)/", $version) ) + { + static $dbname, $dbsize; + $db_name = ( preg_match("/^(3\.23\.[6-9])|(3\.23\.[1-9][1-9])|(4\.)|(5\.)/", $version) ) ? "`$dbname`" : $dbname; + + $sql = "SHOW TABLE STATUS + FROM " . $db_name; + if($result = $db->sql_query($sql)) + { + $tabledata_ary = $db->sql_fetchrowset($result); + + $dbsize = 0; + for($i = 0; $i < count($tabledata_ary); $i++) + { + if( $tabledata_ary[$i]['Type'] != "MRG_MyISAM" ) + { + if( $table_prefix != "" ) + { + if( strstr($tabledata_ary[$i]['Name'], $table_prefix) ) + { + $dbsize += $tabledata_ary[$i]['Data_length'] + $tabledata_ary[$i]['Index_length']; + } + } + else + { + $dbsize += $tabledata_ary[$i]['Data_length'] + $tabledata_ary[$i]['Index_length']; + } + } + } + } // Else we couldn't get the table status. + } + else + { + $dbsize = $lang['Not_available']; + } + } + else + { + $dbsize = $lang['Not_available']; + } + $db->sql_freeresult($result); + } + else if( preg_match("/^mssql/", SQL_LAYER) ) + { + $sql = "SELECT ((SUM(size) * 8.0) * 1024.0) as dbsize + FROM sysfiles"; + if( $result = $db->sql_query($sql) ) + { + $dbsize = ( $row = $db->sql_fetchrow($result) ) ? intval($row['dbsize']) : $lang['Not_available']; + } + else + { + $dbsize = $lang['Not_available']; + } + $db->sql_freeresult($result); + } + else + { + $dbsize = $lang['Not_available']; + } + + if ( is_integer($dbsize) ) + { + if( $dbsize >= 1048576 ) + { + $dbsize = sprintf("%.2f MB", ( $dbsize / 1048576 )); + } + else if( $dbsize >= 1024 ) + { + $dbsize = sprintf("%.2f KB", ( $dbsize / 1024 )); + } + else + { + $dbsize = sprintf("%.2f Bytes", $dbsize); + } + } + + $template->assign_vars(array( + "NUMBER_OF_POSTS" => $total_posts, + "NUMBER_OF_TOPICS" => $total_topics, + "NUMBER_OF_USERS" => $total_users, + "START_DATE" => $start_date, + "POSTS_PER_DAY" => $posts_per_day, + "TOPICS_PER_DAY" => $topics_per_day, + "USERS_PER_DAY" => $users_per_day, + "AVATAR_DIR_SIZE" => $avatar_dir_size, + "DB_SIZE" => $dbsize, + "GZIP_COMPRESSION" => ( $board_config['gzip_compress'] ) ? $lang['ON'] : $lang['OFF']) + ); + } + + /** + * Enter description here... + * + * @return unknown + */ + function phpbb_version_check($force_update = false, $warn_fail = false, $ttl = 86400) + { + global $mx_cache, $board_config, $lang, $phpbb_version_info; + + $errno = 0; + $errstr = $phpbb_version_info = ''; + $phpbb_version_info = $mx_cache->get('versioncheck'); + + if ($fsock = @fsockopen('www.phpbb.com', 80, $errno, $errstr, 10)) + { + //$phpbb_version_info = mx_get_remote_file('www.phpbb.com', '/updatecheck', ((defined('PHPBB_QA')) ? '30x_qa.txt' : '30x.txt'), $errstr, $errno); + if ($phpbb_version_info === false || $force_update) + { + $errstr = ''; + $errno = 0; + + $phpbb_version_info = mx_get_remote_file('version.phpbb.com', '/phpbb', + ((defined('PHPBB_QA')) ? '30x_qa.txt' : '30x.txt'), $errstr, $errno); + } + + if (empty($phpbb_version_info)) + { + $mx_cache->destroy('versioncheck'); + if ($warn_fail) + { + trigger_error($errstr, E_USER_WARNING); + } + return false; + } + + $mx_cache->put('versioncheck', $phpbb_version_info, $ttl); + + $phpbb_version_info = explode("\n", $phpbb_version_info); + //$latest_version = trim($phpbb_version_info[0]); + //$update_link = append_sid($phpbb_root_path . 'install/index.' . $phpEx, 'mode=update'); + $latest_phpbb_head_revision = $version1 = strtolower(trim($phpbb_version_info[0])); + $latest_phpbb_minor_revision = trim($phpbb_version_info[2]); + $latest_phpbb_version = trim($phpbb_version_info[0]) . '.' . trim($phpbb_version_info[1]) . '.' . trim($phpbb_version_info[2]); + $version2 = strtolower($board_config['version']); + $current_phpbb_version = explode(".", $board_config['version']); + $minor_phpbb_revision = $current_phpbb_version[2]; + $operator = '<='; + if (version_compare($version1, $version2, $operator)) + { + $phpbb_version_info = '' . $lang['Version_up_to_date'] . '
'; + } + else + { + $phpbb_version_info = '' . $lang['Version_not_up_to_date']; + $phpbb_version_info .= '
'; + } + } + else + { + if ($errstr) + { + $phpbb_version_info = '
' . sprintf($lang['Latest_version_info'], $latest_phpbb_version) . sprintf($lang['Current_version_info'], $board_config['version']) . '' . sprintf($lang['Connect_socket_error'], $errstr) . '
'; + } + else + { + $phpbb_version_info = '' . $lang['Socket_functions_disabled'] . '
'; + } + } + + $phpbb_version_info .= '' . $lang['Mailing_list_subscribe_reminder'] . '
'; + + return $phpbb_version_info; + } +} + +// +// Now load some bbcodes, to be extended for this backend (see below) +// +include_once($mx_root_path . 'includes/sessions/ascraeus/bbcode.' . $phpEx); // BBCode associated functions + +?> \ No newline at end of file diff --git a/includes/sessions/proteus/functions.php b/includes/sessions/proteus/functions.php new file mode 100644 index 00000000..ef8c96cb --- /dev/null +++ b/includes/sessions/proteus/functions.php @@ -0,0 +1,278 @@ + (empty($mx_user->data)) ? ANONYMOUS : $mx_user->data['user_id'], + 'log_ip' => $mx_user->ip, + 'log_time' => time(), + 'log_operation' => $action, + 'log_data' => $data, + ); + + switch ($mode) + { + case 'admin': + $sql_ary['log_type'] = LOG_ADMIN; + break; + + case 'mod': + $sql_ary += array( + 'log_type' => LOG_MOD, + 'forum_id' => $forum_id, + 'topic_id' => $topic_id + ); + break; + + case 'user': + $sql_ary += array( + 'log_type' => LOG_USERS, + 'reportee_id' => $reportee_id + ); + break; + + case 'critical': + $sql_ary['log_type'] = LOG_CRITICAL; + break; + + default: + return false; + } + + $db->sql_query('INSERT INTO ' . LOG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); + + return $db->sql_nextid(); +} + +/** +* Generate sort selection fields +*/ +function mx_gen_sort_selects(&$limit_days, &$sort_by_text, &$sort_days, &$sort_key, &$sort_dir, &$s_limit_days, &$s_sort_key, &$s_sort_dir, &$u_sort_param) +{ + global $mx_user; + + $sort_dir_text = array('a' => $mx_user->lang['ASCENDING'], 'd' => $mx_user->lang['DESCENDING']); + + // Check if the key is selectable. If not, we reset to the first key found. + // This ensures the values are always valid. + if (!isset($limit_days[$sort_days])) + { + @reset($limit_days); + $sort_days = key($limit_days); + } + + if (!isset($sort_by_text[$sort_key])) + { + @reset($sort_by_text); + $sort_key = key($sort_by_text); + } + + if (!isset($sort_dir_text[$sort_dir])) + { + @reset($sort_dir_text); + $sort_dir = key($sort_dir_text); + } + + $s_limit_days = ''; + + $s_sort_key = ''; + + $s_sort_dir = ''; + + $u_sort_param = "st=$sort_days&sk=$sort_key&sd=$sort_dir"; + + return; +} + +/** +* Get username details for placing into templates. +* +* @param string $mode Can be profile (for getting an url to the profile), username (for obtaining the username), colour (for obtaining the user colour) or full (for obtaining a html string representing a coloured link to the users profile). +* @param int $user_id The users id +* @param string $username The users name +* @param string $username_colour The users colour +* @param string $guest_username optional parameter to specify the guest username. It will be used in favor of the GUEST language variable then. +* @param string $custom_profile_url optional parameter to specify a profile url. The user id get appended to this url as &u={user_id} +* +* @return string A string consisting of what is wanted based on $mode. +*/ +function mx_get_username_string($mode, $user_id, $username, $username_colour = '', $guest_username = false, $custom_profile_url = false) +{ + global $phpbb_root_path, $phpEx, $mx_user, $phpbb_auth; + + $profile_url = ''; + $username_colour = ($username_colour) ? '#' . $username_colour : ''; + + if ($guest_username === false) + { + $username = ($username) ? $username : $mx_user->lang['GUEST']; + } + else + { + $username = ($user_id && $user_id != ANONYMOUS) ? $username : ((!empty($guest_username)) ? $guest_username : $mx_user->lang['GUEST']); + } + + // Only show the link if not anonymous + if ($user_id && $user_id != ANONYMOUS) + { + // Do not show the link if the user is already logged in but do not have u_viewprofile permissions (relevant for bots mostly). + // For all others the link leads to a login page or the profile. + if ($mx_user->data['user_id'] != ANONYMOUS && !$phpbb_auth->acl_get('u_viewprofile')) + { + $profile_url = ''; + } + else + { + $profile_url = ($custom_profile_url !== false) ? $custom_profile_url : mx3_append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile'); + $profile_url .= '&u=' . (int) $user_id; + } + } + else + { + $profile_url = ''; + } + + switch ($mode) + { + case 'profile_url': + case 'profile': + return $profile_url; + break; + + case 'username': + return $username; + break; + + case 'colour': + return $username_colour; + break; + + case 'full': + default: + + $tpl = ''; + if (!$profile_url && !$username_colour) + { + $tpl = '{USERNAME}'; + } + else if (!$profile_url && $username_colour) + { + $tpl = '{USERNAME}'; + } + else if ($profile_url && !$username_colour) + { + $tpl = '{USERNAME}'; + } + else if ($profile_url && $username_colour) + { + $tpl = '{USERNAME}'; + } + + return str_replace(array('{PROFILE_URL}', '{USERNAME_COLOUR}', '{USERNAME}'), array($profile_url, $username_colour, $username), $tpl); + break; + } +} +?> \ No newline at end of file diff --git a/includes/sessions/proteus/index.htm b/includes/sessions/proteus/index.htm new file mode 100644 index 00000000..ee1f723a --- /dev/null +++ b/includes/sessions/proteus/index.htm @@ -0,0 +1,10 @@ + + ++ + + + + + + diff --git a/includes/sessions/proteus/login.php b/includes/sessions/proteus/login.php new file mode 100644 index 00000000..3433bf07 --- /dev/null +++ b/includes/sessions/proteus/login.php @@ -0,0 +1,256 @@ +is_request('login') && ($userdata['user_id'] == ANONYMOUS || $mx_request_vars->is_post('admin')) ) +{ + $username = utf8_clean_string($mx_request_vars->post('username', MX_TYPE_NO_TAGS, '')); + $password = $mx_request_vars->post('password', MX_TYPE_NO_TAGS); + $viewonline = $mx_request_vars->post('viewonline', MX_TYPE_INT, 0); + + $sql = "SELECT * + FROM " . USERS_TABLE . " + WHERE username = '" . str_replace("\\'", "''", $username) . "' + OR username_clean = '" . str_replace("\\'", "''", $username) . "'"; + + if ( !($result = $db->sql_query($sql) ) ) + { + mx_message_die(GENERAL_ERROR, 'Error in obtaining userdata', '', __LINE__, __FILE__, $sql); + } + + if( $row = $db->sql_fetchrow($result) ) + { + //$user_type = $row['user_level']; // phpBB2 + $user_type = $row['user_type']; // phpBB3 + + if( $user_type != ADMIN && $board_config['board_disable'] ) + { + mx_redirect(mx3_append_sid("index.$phpEx", false)); + } + else + { + $user_login_attempts = $row['user_login_attempts']; + + if ( $user_login_attempts && $board_config['login_reset_time'] ) + { + $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_login_attempts = 0 WHERE user_id = ' . $row['user_id']); + $row['user_last_login_try'] = $row['user_login_tries'] = 0; + } + + // Check to see if user is allowed to login again... if his tries are exceeded + if ($user_login_attempt && $board_config['login_reset_time'] && $board_config['max_login_attempts'] && $user_login_attempts >= $board_config['max_login_attempts'] && $userdata['user_level'] != ADMIN) + { + mx_message_die(GENERAL_MESSAGE, sprintf($lang['Login_attempts_exceeded'], $board_config['max_login_attempts'], $board_config['login_reset_time'])); + } + + // If the password convert flag is set we need to convert it + if ($row['user_pass_convert']) + { + // in phpBB2 passwords were used exactly as they were sent, with addslashes applied + $password_old_format = isset($_REQUEST['password']) ? $_REQUEST['password'] : $password; + $password_old_format = (!STRIP) ? addslashes($password_old_format) : $password_old_format; + $password_new_format = ''; + + phpBB3::set_var($password_new_format, stripslashes($password_old_format), 'string'); + + //mx_message_die(CRITICAL_ERROR, "Couldn't start session : login", $password_new_format, ''); + + if ($password == $password_new_format) + { + if (!function_exists('utf8_to_cp1252')) + { + global $mx_root_path, $phpEx; + include_once($mx_root_path . 'includes/utf/data/recode_basic.' . $phpEx); + } + + // cp1252 is phpBB2's default encoding, characters outside ASCII range might work when converted into that encoding + if (md5($password_old_format) == $row['user_password'] || md5(utf8_to_cp1252($password_old_format)) == $row['user_password']) + { + $hash = phpBB3::phpbb_hash($password_new_format); + + // Update the password in the users table to the new format and remove user_pass_convert flag + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_password = \'' . $db->sql_escape($hash) . '\', + user_pass_convert = 0 + WHERE user_id = ' . $row['user_id']; + $db->sql_query($sql); + + $row['user_pass_convert'] = 0; + $row['user_password'] = $hash; + } + else + { + // Although we weren't able to convert this password we have to + // increase login attempt count to make sure this cannot be exploited + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_login_attempts = user_login_attempts + 1 + WHERE user_id = ' . $row['user_id']; + $db->sql_query($sql); + mx_message_die(GENERAL_MESSAGE, 'We are sorry but password convertion failed, please login direct in forums or rewuest a new activation link.'); + return array( + 'status' => LOGIN_ERROR_PASSWORD_CONVERT, + 'error_msg' => 'LOGIN_ERROR_PASSWORD_CONVERT', + 'user_row' => $row, + ); + } + } + } + else + { + // in phpBB2 passwords were used exactly as they were sent, with addslashes applied + $password_old_format = isset($_REQUEST['password']) ? $_REQUEST['password'] : $password; + $password_old_format = (!STRIP) ? addslashes($password_old_format) : $password_old_format; + $password_new_format = ''; + phpBB3::set_var($password_new_format, stripslashes($password_old_format), 'string'); + //mx_message_die(CRITICAL_ERROR, "Couldn't start session : login", $password_new_format, ''); + + if ($password_new_format == $password_old_format) + { + if (!function_exists('utf8_to_cp1252')) + { + global $mx_root_path, $phpEx; + include_once($mx_root_path . 'includes/utf/data/recode_basic.' . $phpEx); + } + + // cp1252 is phpBB2's default encoding, characters outside ASCII range might work when converted into that encoding + if (md5($password_old_format) == $row['user_password'] || md5($password) == $row['user_password'] || phpBB3::phpbb_check_hash($password, $row['user_password'])) + { + $autologin = $mx_request_vars->is_post('autologin'); + $admin = $mx_request_vars->is_post('admin'); + $mx_user->session_create($row['user_id'], $admin, $autologin, $viewonline = true); + $session_id = $mx_user->session_id; + + + // Reset login tries + //$db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_login_tries = 0, user_last_login_try = 0 WHERE user_id = ' . $row['user_id']); // phpBB2 + $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_login_attempts = 0 WHERE user_id = ' . $row['user_id']); // phpBB3 + + if( $session_id ) + { + $fromurl = ( !empty($HTTP_REFERER) ) ? str_replace('&', '&', htmlspecialchars($HTTP_REFERER)) : "index.$phpEx"; + $url = !$mx_request_vars->is_empty_post('redirect') ? str_replace('&', '&', $mx_request_vars->post('redirect', MX_TYPE_NO_TAGS)) : $fromurl; + mx_redirect(mx3_append_sid($url, false, false, $session_id)); + } + else + { + mx_message_die(CRITICAL_ERROR, "Couldn't start session : login", "", __LINE__, __FILE__); + } + } + else + { + // Although we weren't able to convert this password we have to + // increase login attempt count to make sure this cannot be exploited + $sql = ' UPDATE ' . USERS_TABLE . ' + SET user_login_attempts = user_login_attempts + 1 + WHERE user_id = ' . $row['user_id']; + $db->sql_query($sql); + + $redirect = !$mx_request_vars->is_empty_post('redirect') ? str_replace('&', '&', $mx_request_vars->post('redirect', MX_TYPE_NO_TAGS)) : ''; + $redirect = str_replace('?', '&', $redirect); + + if (strstr(urldecode($redirect), "\n") || strstr(urldecode($redirect), "\r")) + { + mx_message_die(GENERAL_ERROR, 'Tried to redirect to potentially insecure url.'); + } + + $template->assign_vars(array( + 'META' => "") + ); + + $message = $lang['Error_login'] . '
' . sprintf($lang['Click_return_login'], "", '') . '
' . sprintf($lang['Click_return_index'], '', ''); + + mx_message_die(GENERAL_MESSAGE, $message); + } + } + // Check password ... + if (!$row['user_pass_convert'] && phpBB3::phpbb_check_hash($password, $row['user_password'])) + { + if ($row['user_login_attempts'] != 0) + { + // Successful, reset login attempts (the user passed all stages) + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_login_attempts = 0 + WHERE user_id = ' . $row['user_id']; + $db->sql_query($sql); + } + + // User inactive... + if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE) + { + mx_message_die(GENERAL_MESSAGE, 'Inactive User'); + } + + // Successful login... set user_login_attempts to zero... + if( $session_id ) + { + $url = !$mx_request_vars->is_empty_post('redirect') ? str_replace('&', '&', $mx_request_vars->post('redirect', MX_TYPE_NO_TAGS)) : "index.$phpEx"; + mx_redirect(mx3_append_sid($url, false)); + } + else + { + mx_message_die(CRITICAL_ERROR, "Couldn't start session : login", "", __LINE__, __FILE__); + } + } + } + } + } + else + { + $redirect = !$mx_request_vars->is_empty_post('redirect') ? str_replace('&', '&', $mx_request_vars->post('redirect', MX_TYPE_NO_TAGS)) : ''; + $redirect = str_replace("?", "&", $redirect); + + if (strstr(urldecode($redirect), "\n") || strstr(urldecode($redirect), "\r")) + { + mx_message_die(GENERAL_ERROR, 'Tried to redirect to potentially insecure url.'); + } + + $template->assign_vars(array( + 'META' => "") + ); + + $message = $lang['Error_login'] . '
' . sprintf($lang['Click_return_login'], "", '') . '
' . sprintf($lang['Click_return_index'], '', ''); + mx_message_die(GENERAL_MESSAGE, $message); + } +} +else if ($mx_request_vars->is_request('logout') && $userdata['session_logged_in'] ) +{ + // session id check + if ($sid == '' || $sid != $userdata['session_id']) + { + mx_message_die(GENERAL_ERROR, 'Invalid_session' . $userdata['session_id']); + } + + if( $userdata['session_logged_in'] ) + { + $mx_user->session_kill(); + } + + if (!$mx_request_vars->is_empty_request('redirect')) + { + $url = $mx_request_vars->post('redirect', MX_TYPE_NO_TAGS); + $url = str_replace('&', '&', $url); + mx_redirect(mx3_append_sid($url, false)); + } + else + { + mx_redirect(mx3_append_sid("index.$phpEx", false)); + } +} +else +{ + $url = !$mx_request_vars->is_empty_post('redirect') ? str_replace('&', '&', $mx_request_vars->post('redirect', MX_TYPE_NO_TAGS)) : "index.$phpEx"; + mx_redirect(mx3_append_sid($url, false)); +} +?> \ No newline at end of file diff --git a/includes/sessions/proteus/session.php b/includes/sessions/proteus/session.php new file mode 100644 index 00000000..f9a8c654 --- /dev/null +++ b/includes/sessions/proteus/session.php @@ -0,0 +1,3800 @@ + $board_config - by Jon + * - replaced $cache = new mx_nothing(); to disable bots() - by Jon + * - removed '?' in the returned $SID string - by Jon + * - in function setup() + * $auth -> $phpbb_auth - by OryNider + * -new globals: $mx_root_path, $mx_cache - by OryNider + * $this->lang_name was redefined to use in + * worst case the new $board_config['phpbb_lang'] + * wich was defined in mx_functions_style.php + * before lang name is expanded - by OryNider + * $template = new mx_Template(); - by OryNider + * - before $this->add_lang($lang_set); the phpBB common language is included + * if fails with $phpbb_root_path added + * - in function set_lang() + * - if empty $this->lang_path will be redefined + * from $phpbb_root_path and new $board_config['phpbb_lang'] + * wich in this case are set as globals - by OryNider + * (similar check has been added in the phpBB3 version too) + * - added function images() to help redefining $images var + * and indexes were is needed - by OryNider + */ + +/** + * Disable bots + * + */ +class mx_nothing +{ + function obtain_bots() + { + return array(); + } +} + +/** +* Session class +* @package MX-Publisher +*/ +class session +{ + var $cookie_data = array(); + var $page = array(); + var $data = array(); + var $browser = ''; + var $forwarded_for = ''; + var $host = ''; + var $session_id = ''; + var $ip = ''; + var $load = 0; + var $time_now = 0; + var $update_session_page = true; + + var $lang = array(); + var $help = array(); + var $theme = array(); + var $date_format; + var $timezone; + var $dst; + + var $lang_name; + var $lang_id = false; + var $lang_path; + var $img_lang; + var $img_array = array(); + + /** + * Load sessions + * @access public + * + */ + function load() + { + global $board_config, $cache; + + $board_config['auth_method'] = 'db'; + $cache = new mx_nothing(); + //define('NEED_SID', 1); + $this->session_begin(); + + // Redefine some MXP stylish userdata + $session_logged_in = $this->data['session_logged_in'] = $this->data['user_id'] != ANONYMOUS ? 1 : 0; + + //print_r($session_logged_in); + if ( $this->data['user_id'] == ANONYMOUS ) + { + $this->data['user_type'] = -1; + } + + switch ($this->data['user_type']) + { + case 3: + $this->data['user_level'] = 1; + break; + case 0: + $this->data['user_level'] = 2; + break; + default: + $this->data['user_level'] = 0; + break; + } + $this->data['session_id'] = $this->session_id; + $this->data['user_session_page'] = $this->data['session_page']; + } + + /** + * Extract current session page + * + * @param string $root_path current root path (phpbb_root_path) + */ + function extract_current_page($root_path) + { + $page_array = array(); + + // First of all, get the request uri... + $script_name = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF'); + $args = (!empty($_SERVER['QUERY_STRING'])) ? explode('&', $_SERVER['QUERY_STRING']) : explode('&', getenv('QUERY_STRING')); + + // If we are unable to get the script name we use REQUEST_URI as a failover and note it within the page array for easier support... + if (!$script_name) + { + $script_name = (!empty($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : getenv('REQUEST_URI'); + $script_name = (($pos = strpos($script_name, '?')) !== false) ? substr($script_name, 0, $pos) : $script_name; + $page_array['failover'] = 1; + } + + // Replace backslashes and doubled slashes (could happen on some proxy setups) + $script_name = str_replace(array('\\', '//'), '/', $script_name); + + // Now, remove the sid and let us get a clean query string... + foreach ($args as $key => $argument) + { + if (strpos($argument, 'sid=') === 0 || strpos($argument, '_f_=') === 0) + { + unset($args[$key]); + } + } + + // The following examples given are for an request uri of {path to the phpbb directory}/adm/index.php?i=10&b=2 + + // The current query string + $query_string = trim(implode('&', $args)); + + // basenamed page name (for example: index.php) + $page_name = basename($script_name); + $page_name = urlencode(htmlspecialchars($page_name)); + + // current directory within the phpBB root (for example: adm) + $root_dirs = explode('/', str_replace('\\', '/', phpBB2::phpbb_realpath($root_path))); + $page_dirs = explode('/', str_replace('\\', '/', phpBB2::phpbb_realpath('./'))); + $intersection = array_intersect_assoc($root_dirs, $page_dirs); + + $root_dirs = array_diff_assoc($root_dirs, $intersection); + $page_dirs = array_diff_assoc($page_dirs, $intersection); + + $page_dir = str_repeat('../', sizeof($root_dirs)) . implode('/', $page_dirs); + + if ($page_dir && substr($page_dir, -1, 1) == '/') + { + $page_dir = substr($page_dir, 0, -1); + } + + // Current page from phpBB root (for example: adm/index.php?i=10&b=2) + $page = (($page_dir) ? $page_dir . '/' : '') . $page_name . (($query_string) ? "?$query_string" : ''); + + // The script path from the webroot to the current directory (for example: /phpBB3/adm/) : always prefixed with / and ends in / + $script_path = trim(str_replace('\\', '/', dirname($script_name))); + + // The script path from the webroot to the phpBB root (for example: /phpBB3/) + $script_dirs = explode('/', $script_path); + array_splice($script_dirs, -sizeof($page_dirs)); + $root_script_path = implode('/', $script_dirs) . (sizeof($root_dirs) ? '/' . implode('/', $root_dirs) : ''); + + // We are on the base level (phpBB root == webroot), lets adjust the variables a bit... + if (!$root_script_path) + { + $root_script_path = ($page_dir) ? str_replace($page_dir, '', $script_path) : $script_path; + } + + $script_path .= (substr($script_path, -1, 1) == '/') ? '' : '/'; + $root_script_path .= (substr($root_script_path, -1, 1) == '/') ? '' : '/'; + + $page_array += array( + 'page_name' => $page_name, + 'page_dir' => $page_dir, + + 'query_string' => $query_string, + 'script_path' => str_replace(' ', '%20', htmlspecialchars($script_path)), + 'root_script_path' => str_replace(' ', '%20', htmlspecialchars($root_script_path)), + + 'page' => $page + ); + + return $page_array; + } + + /** + * Start session management + * + * This is where all session activity begins. We gather various pieces of + * information from the client and server. We test to see if a session already + * exists. If it does, fine and dandy. If it doesn't we'll go on to create a + * new one ... pretty logical heh? We also examine the system load (if we're + * running on a system which makes such information readily available) and + * halt if it's above an admin definable limit. + * + * @param bool $update_session_page if true the session page gets updated. + * This can be set to circumvent certain scripts to update the users last visited page. + */ + function session_begin($update_session_page = true) + { + global $phpEx, $SID, $_SID, $_EXTRA_URL, $db, $board_config, $mx_root_path, $phpbb_root_path, $page_id; + + // Give us some basic information + $this->time_now = time(); + $this->cookie_data = array('u' => 0, 'k' => ''); + $this->update_session_page = $update_session_page; + $this->browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT']) : ''; + $this->referer = (!empty($_SERVER['HTTP_REFERER'])) ? htmlspecialchars((string) $_SERVER['HTTP_REFERER']) : ''; + $this->forwarded_for = (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) ? (string) $_SERVER['HTTP_X_FORWARDED_FOR'] : ''; + $this->host = (!empty($_SERVER['HTTP_HOST'])) ? (string) $_SERVER['HTTP_HOST'] : 'localhost'; + $this->page = $this->extract_current_page($phpbb_root_path); + + // if the forwarded for header shall be checked we have to validate its contents + if ($board_config['forwarded_for_check']) + { + $this->forwarded_for = preg_replace('#, +#', ', ', $this->forwarded_for); + + // Whoa these look impressive! + // The code to generate the following two regular expressions which match valid IPv4/IPv6 addresses + // can be found in the develop directory + $ipv4 = phpBB3::get_preg_expression('ipv4'); //'#^(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$#'; + $ipv6 = phpBB3::get_preg_expression('ipv6'); //'#^(?:(?:(?:[\dA-F]{1,4}:){6}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:::(?:[\dA-F]{1,4}:){5}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:):(?:[\dA-F]{1,4}:){4}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,2}:(?:[\dA-F]{1,4}:){3}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,3}:(?:[\dA-F]{1,4}:){2}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,4}:(?:[\dA-F]{1,4}:)(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,5}:(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,6}:[\dA-F]{1,4})|(?:(?:[\dA-F]{1,4}:){1,7}:))$#i'; + + // split the list of IPs + $ips = explode(', ', $this->forwarded_for); + foreach ($ips as $ip) + { + // check IPv4 first, the IPv6 is hopefully only going to be used very seldomly + if (!empty($ip) && !preg_match($ipv4, $ip) && !preg_match($ipv6, $ip)) + { + // contains invalid data, don't use the forwarded for header + $this->forwarded_for = ''; + break; + } + } + } + else + { + $this->forwarded_for = ''; + } + + // Add forum to the page for tracking online users - also adding a "x" to the end to properly identify the number + $this->page['page'] .= (isset($_REQUEST['f'])) ? ((strpos($this->page['page'], '?') !== false) ? '&' : '?') . '_f_=' . (int) $_REQUEST['f'] . 'x' : ''; + + if (isset($_COOKIE[$board_config['cookie_name'] . '_sid']) || isset($_COOKIE[$board_config['cookie_name'] . '_u'])) + { + $this->cookie_data['u'] = phpBB3::request_var($board_config['cookie_name'] . '_u', 0, false, true); + $this->cookie_data['k'] = phpBB3::request_var($board_config['cookie_name'] . '_k', '', false, true); + $this->session_id = phpBB3::request_var($board_config['cookie_name'] . '_sid', '', false, true); + + // original code: $SID = (defined('NEED_SID')) ? 'sid=' . $this->session_id : 'sid='; + $SID = (defined('NEED_SID')) ? 'sid=' . $this->session_id : ''; + $_SID = (defined('NEED_SID')) ? $this->session_id : ''; + + if (empty($this->session_id)) + { + $this->session_id = $_SID = phpBB3::request_var('sid', ''); + $SID = 'sid=' . $this->session_id; + $this->cookie_data = array('u' => 0, 'k' => ''); + } + } + else + { + $this->session_id = $_SID = phpBB3::request_var('sid', ''); + $SID = 'sid=' . $this->session_id; + } + + $_EXTRA_URL = array(); + + // Why no forwarded_for et al? Well, too easily spoofed. With the results of my recent requests + // it's pretty clear that in the majority of cases you'll at least be left with a proxy/cache ip. + $this->ip = (!empty($_SERVER['REMOTE_ADDR'])) ? htmlspecialchars($_SERVER['REMOTE_ADDR']) : ''; + $this->ip = preg_replace('#[ ]{2,}#', ' ', str_replace(array(',', ' '), ' ', $this->ip)); + + // split the list of IPs + $ips = explode(' ', $this->ip); + + // Default IP if REMOTE_ADDR is invalid + $this->ip = '127.0.0.1'; + + foreach ($ips as $ip) + { + // check IPv4 first, the IPv6 is hopefully only going to be used very seldomly + if (!empty($ip) && !preg_match(phpBB3::get_preg_expression('ipv4'), $ip) && !preg_match(phpBB3::get_preg_expression('ipv6'), $ip)) + { + // Just break + break; + } + + // Quick check for IPv4-mapped address in IPv6 + if (stripos($ip, '::ffff:') === 0) + { + $ipv4 = substr($ip, 7); + + if (preg_match(phpBB3::get_preg_expression('ipv4'), $ipv4)) + { + $ip = $ipv4; + } + } + + // Use the last in chain + $this->ip = $ip; + } + + $this->load = false; + + // Load limit check (if applicable) + if ($board_config['limit_load'] || $board_config['limit_search_load']) + { + if ($load = @file_get_contents('/proc/loadavg')) + { + $this->load = array_slice(explode(' ', $load), 0, 1); + $this->load = floatval($this->load[0]); + } + else + { + set_config('limit_load', '0'); + set_config('limit_search_load', '0'); + } + } + + // Is session_id is set or session_id is set and matches the url param if required + if (!empty($this->session_id) && (!defined('NEED_SID') || (isset($_GET['sid']) && $this->session_id === $_GET['sid'])) ) + { + $sql = 'SELECT u.*, s.* + FROM ' . SESSIONS_TABLE . ' s, ' . USERS_TABLE . " u + WHERE s.session_id = '" . $db->sql_escape($this->session_id) . "' + AND u.user_id = s.session_user_id"; + $result = $db->sql_query($sql); + $this->data = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + // Did the session exist in the DB? + if (isset($this->data['user_id'])) + { + // Validate IP length according to admin ... enforces an IP + // check on bots if admin requires this + //$quadcheck = ($board_config['ip_check_bot'] && $this->data['user_type'] & USER_BOT) ? 4 : $board_config['ip_check']; + + if (strpos($this->ip, ':') !== false && strpos($this->data['session_ip'], ':') !== false) + { + $s_ip = short_ipv6($this->data['session_ip'], $board_config['ip_check']); + $u_ip = short_ipv6($this->ip, $board_config['ip_check']); + } + else + { + $s_ip = implode('.', array_slice(explode('.', $this->data['session_ip']), 0, $board_config['ip_check'])); + $u_ip = implode('.', array_slice(explode('.', $this->ip), 0, $board_config['ip_check'])); + } + + $s_browser = ($board_config['browser_check']) ? strtolower(substr($this->data['session_browser'], 0, 149)) : ''; + $u_browser = ($board_config['browser_check']) ? strtolower(substr($this->browser, 0, 149)) : ''; + + $s_forwarded_for = ($board_config['forwarded_for_check']) ? substr($this->data['session_forwarded_for'], 0, 254) : ''; + $u_forwarded_for = ($board_config['forwarded_for_check']) ? substr($this->forwarded_for, 0, 254) : ''; + + // referer checks + // The @ before $config['referer_validation'] suppresses notices present while running the updater + $check_referer_path = (@$board_config['referer_validation'] == REFERER_VALIDATE_PATH); + $referer_valid = true; + + // we assume HEAD and TRACE to be foul play and thus only whitelist GET + if (@$board_config['referer_validation'] && isset($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) !== 'get') + { + $referer_valid = $this->validate_referer($check_referer_path); + } + + if ($u_ip === $s_ip && $s_browser === $u_browser && $s_forwarded_for === $u_forwarded_for) + { + $session_expired = false; + + // Check whether the session is still valid if we have one + $method = basename(trim($board_config['auth_method'])); + + if ((@include_once $mx_root_path . "includes/shared/phpbb3/includes/auth/auth_" . $method . ".$phpEx") === false) + { + if ((@include_once $mx_root_path . "includes/shared/phpbb3/includes/auth/auth_" . $method . ".$phpEx") === false) + { + mx_message_die(CRITICAL_ERROR, 'File(s1) ' . $mx_root_path . "includes/shared/phpbb3/includes/auth/auth/auth_" . $method . ".$phpEx" . ' couldn\'t be opened.'); + } + } + + $method = 'validate_session_' . $method; + if (function_exists($method)) + { + if (!$method($this->data)) + { + $session_expired = true; + } + } + + if (!$session_expired) + { + // Check the session length timeframe if autologin is not enabled. + // Else check the autologin length... and also removing those having autologin enabled but no longer allowed board-wide. + if (!$this->data['session_autologin']) + { + if ($this->data['session_time'] < $this->time_now - ($board_config['session_length'] + 60)) + { + $session_expired = true; + } + } + else if (!$board_config['allow_autologin'] || ($board_config['max_autologin_time'] && $this->data['session_time'] < $this->time_now - (86400 * (int) $board_config['max_autologin_time']) + 60)) + { + $session_expired = true; + } + } + + if (!$session_expired) + { + // Only update session DB a minute or so after last update or if page changes + if ($this->time_now - $this->data['session_time'] > 60 || ($this->update_session_page && $this->data['session_page'] != $this->page['page'])) + { + $sql_ary = array('session_time' => $this->time_now); + + if ($this->update_session_page) + { + $sql_ary['session_page'] = substr($this->page['page'], 0, 199); + $sql_ary['session_forum_id'] = !empty($this->page['forum']) ? $this->page['forum'] : $page_id; //Added for phpBB 3.0.2 by Ory + } + + $db->sql_return_on_error(true); + + $sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE session_id = '" . $db->sql_escape($this->session_id) . "'"; + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + // If the database is not yet updated, there will be an error due to the session_forum_id + // @todo REMOVE for 3.0.2 + if ($result === false) + { + unset($sql_ary['session_forum_id']); + + $sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE session_id = '" . $db->sql_escape($this->session_id) . "'"; + $db->sql_query($sql); + } + + if ($this->data['user_id'] != ANONYMOUS && !empty($board_config['new_member_post_limit']) && $this->data['user_new'] && $board_config['new_member_post_limit'] <= $this->data['user_posts']) + { + $this->leave_newly_registered(); + } + } + + $this->data['is_registered'] = ($this->data['user_id'] != ANONYMOUS && ($this->data['user_type'] == USER_NORMAL || $this->data['user_type'] == USER_FOUNDER)) ? true : false; + $this->data['is_bot'] = (!$this->data['is_registered'] && $this->data['user_id'] != ANONYMOUS) ? true : false; + $this->data['user_lang'] = basename($this->data['user_lang']); + + return true; + } + } + else + { + // Added logging temporarly to help debug bugs... + if (defined('DEBUG_EXTRA') && $this->data['user_id'] != ANONYMOUS) + { + if ($referer_valid) + { + mx_add_log('critical', 'LOG_IP_BROWSER_FORWARDED_CHECK', $u_ip, $s_ip, $u_browser, $s_browser, htmlspecialchars($u_forwarded_for), htmlspecialchars($s_forwarded_for)); + } + else + { + mx_add_log('critical', 'LOG_REFERER_INVALID', $this->referer); + } + } + } + } + } + // If we reach here then no (valid) session exists. So we'll create a new one + return $this->session_create(); + } + + /** + * Create a new session + * + * If upon trying to start a session we discover there is nothing existing we + * jump here. Additionally this method is called directly during login to regenerate + * the session for the specific user. In this method we carry out a number of tasks; + * garbage collection, (search)bot checking, banned user comparison. Basically + * though this method will result in a new session for a specific user. + */ + function session_create($user_id = false, $set_admin = false, $persist_login = false, $viewonline = true) + { + global $SID, $_SID, $db, $board_config, $cache, $mx_root_path, $phpbb_root_path, $phpEx, $mx_backend; + + $this->data = array(); + + /* Garbage collection ... remove old sessions updating user information + // if necessary. It means (potentially) 11 queries but only infrequently + if ($this->time_now > $board_config['session_last_gc'] + $board_config['session_gc']) + { + $this->session_gc(); + }*/ + + // Do we allow autologin on this board? No? Then override anything + // that may be requested here + if (!$board_config['allow_autologin']) + { + $this->cookie_data['k'] = $persist_login = false; + } + + /** + * Here we do a bot check, oh er saucy! No, not that kind of bot + * check. We loop through the list of bots defined by the admin and + * see if we have any useragent and/or IP matches. If we do, this is a + * bot, act accordingly + */ + $bot = false; + $active_bots = $mx_backend->obtain_bots(); + + foreach ($active_bots as $row) + { + if ($row['bot_agent'] && preg_match('#' . str_replace('\*', '.*?', preg_quote($row['bot_agent'], '#')) . '#i', $this->browser)) + { + $bot = $row['user_id']; + } + + // If ip is supplied, we will make sure the ip is matching too... + if ($row['bot_ip'] && ($bot || !$row['bot_agent'])) + { + // Set bot to false, then we only have to set it to true if it is matching + $bot = false; + + foreach (explode(',', $row['bot_ip']) as $bot_ip) + { + $bot_ip = trim($bot_ip); + + if (!$bot_ip) + { + continue; + } + if (strpos($this->ip, $bot_ip) === 0) + { + $bot = (int) $row['user_id']; + break; + } + } + } + if ($bot) + { + break; + } + } + $method = basename(trim($board_config['auth_method'])); + if ((@include_once $mx_root_path . "includes/shared/phpbb3/includes/auth/auth_" . $method . ".$phpEx") === false) + { + if ((@include_once $mx_root_path . "includes/shared/phpbb3/includes/auth/auth_" . $method . ".$phpEx") === false) + { + mx_message_die(CRITICAL_ERROR, 'File(s2) ' . $mx_root_path . "includes/shared/phpbb3/includes/auth/auth_" . $method . ".$phpEx" . ' couldn\'t be opened.'); + } + } + //$provider = $phpbb_container->get('auth.provider.' . $method); + $method = 'autologin_' . $method; + if (function_exists($method)) + { + $this->data = $method(); + + if (sizeof($this->data)) + { + $this->cookie_data['k'] = ''; + $this->cookie_data['u'] = $this->data['user_id']; + } + } + + // If we're presented with an autologin key we'll join against it. + // Else if we've been passed a user_id we'll grab data based on that + if (isset($this->cookie_data['k']) && $this->cookie_data['k'] && $this->cookie_data['u'] && !sizeof($this->data)) + { + $sql = 'SELECT u.* + FROM ' . USERS_TABLE . ' u, ' . SESSIONS_KEYS_TABLE . ' k + WHERE u.user_id = ' . (int) $this->cookie_data['u'] . ' + AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ") + AND k.user_id = u.user_id + AND k.key_id = '" . $db->sql_escape(md5($this->cookie_data['k'])) . "'"; + $result = $db->sql_query($sql); + $this->data = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + $bot = false; + } + else if ($user_id !== false && !sizeof($this->data)) + { + $this->cookie_data['k'] = ''; + $this->cookie_data['u'] = $user_id; + + $sql = 'SELECT * + FROM ' . USERS_TABLE . ' + WHERE user_id = ' . (int) $this->cookie_data['u'] . ' + AND user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')'; + $result = $db->sql_query($sql); + $this->data = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + $bot = false; + } + + // If no data was returned one or more of the following occurred: + // Key didn't match one in the DB + // User does not exist + // User is inactive + // User is bot + if (!sizeof($this->data) || !is_array($this->data)) + { + $this->cookie_data['k'] = ''; + $this->cookie_data['u'] = ($bot) ? $bot : ANONYMOUS; + + if (!$bot) + { + $sql = 'SELECT * + FROM ' . USERS_TABLE . ' + WHERE user_id = ' . (int) $this->cookie_data['u']; + } + else + { + // We give bots always the same session if it is not yet expired. + $sql = 'SELECT u.*, s.* + FROM ' . USERS_TABLE . ' u + LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id) + WHERE u.user_id = ' . (int) $bot; + } + + $result = $db->sql_query($sql); + $this->data = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + } + + if ($this->data['user_id'] != ANONYMOUS && !$bot) + { + $this->data['session_last_visit'] = (isset($this->data['session_time']) && $this->data['session_time']) ? $this->data['session_time'] : (($this->data['user_lastvisit']) ? $this->data['user_lastvisit'] : time()); + } + else + { + $this->data['session_last_visit'] = $this->time_now; + } + + // Force user id to be integer... + $this->data['user_id'] = (int) $this->data['user_id']; + + // At this stage we should have a filled data array, defined cookie u and k data. + // data array should contain recent session info if we're a real user and a recent + // session exists in which case session_id will also be set + + // Is user banned? Are they excluded? Won't return on ban, exists within method + if ($this->data['user_type'] != USER_FOUNDER) + { + if (!$board_config['forwarded_for_check']) + { + $this->check_ban($this->data['user_id'], $this->ip); + } + else + { + $ips = explode(', ', $this->forwarded_for); + $ips[] = $this->ip; + $this->check_ban($this->data['user_id'], $ips); + } + } + $this->data['is_registered'] = (!$bot && $this->data['user_id'] != ANONYMOUS && ($this->data['user_type'] == USER_NORMAL || $this->data['user_type'] == USER_FOUNDER)) ? true : false; + $this->data['is_bot'] = ($bot) ? true : false; + + // If our friend is a bot, we re-assign a previously assigned session + if ($this->data['is_bot'] && $bot == $this->data['user_id'] && $this->data['session_id']) + { + // Only assign the current session if the ip, browser and forwarded_for match... + if (strpos($this->ip, ':') !== false && strpos($this->data['session_ip'], ':') !== false) + { + $s_ip = short_ipv6($this->data['session_ip'], $board_config['ip_check']); + $u_ip = short_ipv6($this->ip, $board_config['ip_check']); + } + else + { + $s_ip = implode('.', array_slice(explode('.', $this->data['session_ip']), 0, $board_config['ip_check'])); + $u_ip = implode('.', array_slice(explode('.', $this->ip), 0, $board_config['ip_check'])); + } + + $s_browser = ($board_config['browser_check']) ? strtolower(substr($this->data['session_browser'], 0, 149)) : ''; + $u_browser = ($board_config['browser_check']) ? strtolower(substr($this->browser, 0, 149)) : ''; + + $s_forwarded_for = ($board_config['forwarded_for_check']) ? substr($this->data['session_forwarded_for'], 0, 254) : ''; + $u_forwarded_for = ($board_config['forwarded_for_check']) ? substr($this->forwarded_for, 0, 254) : ''; + + if ($u_ip === $s_ip && $s_browser === $u_browser && $s_forwarded_for === $u_forwarded_for) + { + $this->session_id = $this->data['session_id']; + + // Only update session DB a minute or so after last update or if page changes + if ($this->time_now - $this->data['session_time'] > 60 || ($this->update_session_page && $this->data['session_page'] != $this->page['page'])) + { + $this->data['session_time'] = $this->data['session_last_visit'] = $this->time_now; + + $sql_ary = array('session_time' => $this->time_now, 'session_last_visit' => $this->time_now, 'session_admin' => 0); + + if ($this->update_session_page) + { + $sql_ary['session_page'] = substr($this->page['page'], 0, 199); + } + + $sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE session_id = '" . $db->sql_escape($this->session_id) . "'"; + $db->sql_query($sql); + + // Update the last visit time + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_lastvisit = ' . (int) $this->data['session_time'] . ' + WHERE user_id = ' . (int) $this->data['user_id']; + $db->sql_query($sql); + } + + $SID = '?sid='; + $_SID = ''; + return true; + } + else + { + // If the ip and browser does not match make sure we only have one bot assigned to one session + $db->sql_query('DELETE FROM ' . SESSIONS_TABLE . ' WHERE session_user_id = ' . $this->data['user_id']); + } + } + + $session_autologin = (($this->cookie_data['k'] || $persist_login) && $this->data['is_registered']) ? true : false; + $set_admin = ($set_admin && $this->data['is_registered']) ? true : false; + + // Create or update the session + $sql_ary = array( + 'session_user_id' => (int) $this->data['user_id'], + 'session_start' => (int) $this->time_now, + 'session_last_visit' => (int) $this->data['session_last_visit'], + 'session_time' => (int) $this->time_now, + 'session_browser' => (string) substr($this->browser, 0, 149), + 'session_forwarded_for' => (string) $this->forwarded_for, + 'session_ip' => (string) $this->ip, + 'session_autologin' => ($session_autologin) ? 1 : 0, + 'session_admin' => ($set_admin) ? 1 : 0, + 'session_viewonline' => ($viewonline) ? 1 : 0, + ); + + if ($this->update_session_page) + { + $sql_ary['session_page'] = (string) substr($this->page['page'], 0, 199); + } + + $db->sql_return_on_error(true); + + $sql = 'DELETE + FROM ' . SESSIONS_TABLE . ' + WHERE session_id = \'' . $db->sql_escape($this->session_id) . '\' + AND session_user_id = ' . ANONYMOUS; + + if (!defined('IN_ERROR_HANDLER') && (!$this->session_id || !$db->sql_query($sql) || !$db->sql_affectedrows())) + { + // Limit new sessions in 1 minute period (if required) + if (empty($this->data['session_time']) && $board_config['active_sessions']) + { + $sql = 'SELECT COUNT(session_id) AS sessions + FROM ' . SESSIONS_TABLE . ' + WHERE session_time >= ' . ($this->time_now - 60); + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if ((int) $row['sessions'] > (int) $board_config['active_sessions']) + { + header('HTTP/1.1 503 Service Unavailable'); + trigger_error('BOARD_UNAVAILABLE'); + } + } + } + + $this->session_id = $this->data['session_id'] = md5(phpBB3::unique_id()); + + $sql_ary['session_id'] = (string) $this->session_id; + $sql_ary['session_page'] = (string) substr($this->page['page'], 0, 199); + + $sql = 'INSERT INTO ' . SESSIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + + $db->sql_return_on_error(false); + + // Regenerate autologin/persistent login key + if ($session_autologin) + { + $this->set_login_key(); + } + + // refresh data + $SID = '?sid=' . $this->session_id; + $_SID = $this->session_id; + $this->data = array_merge($this->data, $sql_ary); + + if (!$bot) + { + $cookie_expire = $this->time_now + (($board_config['max_autologin_time']) ? 86400 * (int) $board_config['max_autologin_time'] : 31536000); + + $this->set_cookie('u', $this->cookie_data['u'], $cookie_expire); + $this->set_cookie('k', $this->cookie_data['k'], $cookie_expire); + $this->set_cookie('sid', $this->session_id, $cookie_expire); + + unset($cookie_expire); + } + else + { + $this->data['session_time'] = $this->data['session_last_visit'] = $this->time_now; + + // Update the last visit time + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_lastvisit = ' . (int) $this->data['session_time'] . ' + WHERE user_id = ' . (int) $this->data['user_id']; + $db->sql_query($sql); + + $SID = '?sid='; + $_SID = ''; + } + + return true; + } + + /** + * Kills a session + * + * This method does what it says on the tin. It will delete a pre-existing session. + * It resets cookie information (destroying any autologin key within that cookie data) + * and update the users information from the relevant session data. It will then + * grab guest user information. + */ + function session_kill($new_session = true) + { + global $SID, $_SID, $db, $board_config, $mx_root_path, $php_root_path, $phpEx; + + $sql = 'DELETE FROM ' . SESSIONS_TABLE . " + WHERE session_id = '" . $db->sql_escape($this->session_id) . "' + AND session_user_id = " . (int) $this->data['user_id']; + $db->sql_query($sql); + + // Allow connecting logout with external auth method logout + $method = basename(trim($board_config['auth_method'])); + if ((@include_once $mx_root_path . "includes/shared/phpbb3/includes/auth/auth_" . $method . ".$phpEx") === false) + { + if ((@include_once $mx_root_path . "includes/shared/phpbb3/includes/auth/auth_" . $method . ".$phpEx") === false) + { + mx_message_die(CRITICAL_ERROR, 'File(s3) ' . $mx_root_path . "includes/shared/phpbb3/includes/auth/auth_" . $method . ".$phpEx" . ' couldn\'t be opened.'); + } + } + //$provider = $phpbb_container->get('auth.provider.' . $method); + $method = 'logout_' . $method; + if (function_exists($method)) + { + $method($this->data, $new_session); + } + //$provider->logout($this->data, $new_session); + if ($this->data['user_id'] != ANONYMOUS) + { + // Delete existing session, update last visit info first! + if (!isset($this->data['session_time'])) + { + $this->data['session_time'] = time(); + } + + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_lastvisit = ' . (int) $this->data['session_time'] . ' + WHERE user_id = ' . (int) $this->data['user_id']; + $db->sql_query($sql); + + if ($this->cookie_data['k']) + { + $sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE . ' + WHERE user_id = ' . (int) $this->data['user_id'] . " + AND key_id = '" . $db->sql_escape(md5($this->cookie_data['k'])) . "'"; + $db->sql_query($sql); + } + + // Reset the data array + $this->data = array(); + + $sql = 'SELECT * + FROM ' . USERS_TABLE . ' + WHERE user_id = ' . ANONYMOUS; + $result = $db->sql_query($sql); + $this->data = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + } + + $cookie_expire = $this->time_now - 31536000; + $this->set_cookie('u', '', $cookie_expire); + $this->set_cookie('k', '', $cookie_expire); + $this->set_cookie('sid', '', $cookie_expire); + unset($cookie_expire); + + $SID = '?sid='; + $this->session_id = $_SID = ''; + + // To make sure a valid session is created we create one for the anonymous user + if ($new_session) + { + $this->session_create(ANONYMOUS); + } + + return true; + } + + /** + * Session garbage collection + * + * This looks a lot more complex than it really is. Effectively we are + * deleting any sessions older than an admin definable limit. Due to the + * way in which we maintain session data we have to ensure we update user + * data before those sessions are destroyed. In addition this method + * removes autologin key information that is older than an admin defined + * limit. + */ + function session_gc() + { + global $db, $board_config; + + if (!$this->time_now) + { + $this->time_now = time(); + } + + // Firstly, delete guest sessions + $sql = 'DELETE FROM ' . SESSIONS_TABLE . ' + WHERE session_user_id = ' . ANONYMOUS . ' + AND session_time < ' . (int) ($this->time_now - $board_config['session_length']); + $db->sql_query($sql); + + // Get expired sessions, only most recent for each user + $sql = 'SELECT session_user_id, session_page, MAX(session_time) AS recent_time + FROM ' . SESSIONS_TABLE . ' + WHERE session_time < ' . ($this->time_now - $board_config['session_length']) . ' + GROUP BY session_user_id, session_page'; + $result = $db->sql_query_limit($sql, 10); + + $del_user_id = array(); + $del_sessions = 0; + + while ($row = $db->sql_fetchrow($result)) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_lastvisit = ' . (int) $row['recent_time'] . ", user_lastpage = '" . $db->sql_escape($row['session_page']) . "' + WHERE user_id = " . (int) $row['session_user_id']; + $db->sql_query($sql); + + $del_user_id[] = (int) $row['session_user_id']; + $del_sessions++; + } + $db->sql_freeresult($result); + + if (sizeof($del_user_id)) + { + // Delete expired sessions + $sql = 'DELETE FROM ' . SESSIONS_TABLE . ' + WHERE ' . $db->sql_in_set('session_user_id', $del_user_id) . ' + AND session_time < ' . ($this->time_now - $board_config['session_length']); + $db->sql_query($sql); + } + + if ($del_sessions < 10) + { + // Less than 10 sessions, update gc timer ... else we want gc + // called again to delete other sessions + set_config('session_last_gc', $this->time_now, true); + } + + if ($board_config['max_autologin_time']) + { + $sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE . ' + WHERE last_login < ' . (time() - (86400 * (int) $board_config['max_autologin_time'])); + $db->sql_query($sql); + } + + return; + } + + /** + * Sets a cookie + * + * Sets a cookie of the given name with the specified data for the given length of time. + */ + function set_cookie($name, $cookiedata, $cookietime) + { + global $board_config; + + $name_data = rawurlencode($board_config['cookie_name'] . '_' . $name) . '=' . rawurlencode($cookiedata); + $expire = gmdate('D, d-M-Y H:i:s \\G\\M\\T', $cookietime); + $domain = (!$board_config['cookie_domain'] || $board_config['cookie_domain'] == 'localhost' || $board_config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $board_config['cookie_domain']; + + header('Set-Cookie: ' . $name_data . '; expires=' . $expire . '; path=' . $board_config['cookie_path'] . $domain . ((!$board_config['cookie_secure']) ? '' : '; secure') . '; HttpOnly', false); + } + + /** + * Check for banned user + * + * Checks whether the supplied user is banned by id, ip or email. If no parameters + * are passed to the method pre-existing session data is used. If $return is false + * this routine does not return on finding a banned user, it outputs a relevant + * message and stops execution. + * + * @param string|array $user_ips Can contain a string with one IP or an array of multiple IPs + */ + function check_ban($user_id = false, $user_ips = false, $user_email = false, $return = false) + { + global $board_config, $db; + + if (defined('IN_CHECK_BAN')) + { + return; + } + + $banned = false; + + $sql = 'SELECT ban_ip, ban_userid, ban_email, ban_exclude, ban_give_reason, ban_end + FROM ' . BANLIST_TABLE . ' + WHERE (ban_end >= ' . time() . ' OR ban_end = 0)'; + + // Determine which entries to check, only return those + if ($user_email === false) + { + $sql .= " AND ban_email = ''"; + } + + if ($user_ips === false) + { + $sql .= " AND (ban_ip = '' OR ban_exclude = 1)"; + } + + if ($user_id === false) + { + $sql .= ' AND (ban_userid = 0 OR ban_exclude = 1)'; + } + else + { + $sql .= ' AND (ban_userid = ' . $user_id; + + if ($user_email !== false) + { + $sql .= " OR ban_email <> ''"; + } + + if ($user_ips !== false) + { + $sql .= " OR ban_ip <> ''"; + } + + $sql .= ')'; + } + + $result = $db->sql_query($sql); + + $ban_triggered_by = 'user'; + while ($row = $db->sql_fetchrow($result)) + { + $ip_banned = false; + if (!empty($row['ban_ip'])) + { + if (!is_array($user_ips)) + { + $ip_banned = preg_match('#^' . str_replace('\*', '.*?', preg_quote($row['ban_ip'], '#')) . '$#i', $user_ips); + } + else + { + foreach ($user_ips as $user_ip) + { + if (preg_match('#^' . str_replace('\*', '.*?', preg_quote($row['ban_ip'], '#')) . '$#i', $user_ip)) + { + $ip_banned = true; + break; + } + } + } + } + + if ((!empty($row['ban_userid']) && intval($row['ban_userid']) == $user_id) || + $ip_banned || + (!empty($row['ban_email']) && preg_match('#^' . str_replace('\*', '.*?', preg_quote($row['ban_email'], '#')) . '$#i', $user_email))) + { + if (!empty($row['ban_exclude'])) + { + $banned = false; + break; + } + else + { + $banned = true; + $ban_row = $row; + + if (!empty($row['ban_userid']) && intval($row['ban_userid']) == $user_id) + { + $ban_triggered_by = 'user'; + } + else if (!empty($row['ban_ip']) && preg_match('#^' . str_replace('\*', '.*?', preg_quote($row['ban_ip'], '#')) . '$#i', $user_ips)) + { + $ban_triggered_by = 'ip'; + } + else + { + $ban_triggered_by = 'email'; + } + + // Don't break. Check if there is an exclude rule for this user + } + } + } + $db->sql_freeresult($result); + + if ($banned && !$return) + { + global $template; + + // If the session is empty we need to create a valid one... + if (empty($this->session_id)) + { + $this->session_create(ANONYMOUS); + } + + // Initiate environment ... since it won't be set at this stage + $this->setup(); + + // Logout the user, banned users are unable to use the normal 'logout' link + if ($this->data['user_id'] != ANONYMOUS) + { + $this->session_kill(); + } + + // We show a login box here to allow founders accessing the board if banned by IP + if (defined('IN_LOGIN') && $this->data['user_id'] == ANONYMOUS) + { + global $phpEx; + + $this->setup('ucp'); + $this->data['is_registered'] = $this->data['is_bot'] = false; + + // Set as a precaution to allow login_box() handling this case correctly as well as this function not being executed again. + define('IN_CHECK_BAN', 1); + + login_box("index.$phpEx"); + + // The false here is needed, else the user is able to circumvent the ban. + $this->session_kill(false); + } + + // Ok, we catch the case of an empty session id for the anonymous user... + // This can happen if the user is logging in, banned by username and the login_box() being called "again". + if (empty($this->session_id) && defined('IN_CHECK_BAN')) + { + $this->session_create(ANONYMOUS); + } + + + // Determine which message to output + $till_date = ($ban_row['ban_end']) ? $this->format_date($ban_row['ban_end']) : ''; + $message = ($ban_row['ban_end']) ? 'BOARD_BAN_TIME' : 'BOARD_BAN_PERM'; + + $message = sprintf($this->lang[$message], $till_date, '', ''); + $message .= ($ban_row['ban_give_reason']) ? '
' . sprintf($this->lang['BOARD_BAN_REASON'], $ban_row['ban_give_reason']) : ''; + $message .= '
' . $this->lang['BAN_TRIGGERED_BY_' . strtoupper($ban_triggered_by)] . ''; + + trigger_error($message); + } + + return ($banned) ? true : false; + } + + /** + * Check if ip is blacklisted + * This should be called only where absolutly necessary + * + * Only IPv4 (rbldns does not support AAAA records/IPv6 lookups) + * + * @author satmd (from the php manual) + * @param string $mode register/post - spamcop for example is ommitted for posting + * @return false if ip is not blacklisted, else an array([checked server], [lookup]) + */ + function check_dnsbl($mode, $ip = false) + { + if ($ip === false) + { + $ip = $this->ip; + } + + $dnsbl_check = array( + 'list.dsbl.org' => 'http://dsbl.org/listing?', + 'sbl-xbl.spamhaus.org' => 'http://www.spamhaus.org/query/bl?ip=', + ); + + if ($mode == 'register') + { + $dnsbl_check['bl.spamcop.net'] = 'http://spamcop.net/bl.shtml?'; + } + + if ($ip) + { + $quads = explode('.', $ip); + $reverse_ip = $quads[3] . '.' . $quads[2] . '.' . $quads[1] . '.' . $quads[0]; + + // Need to be listed on all servers... + $listed = true; + $info = array(); + + foreach ($dnsbl_check as $dnsbl => $lookup) + { + if (phpbb_checkdnsrr($reverse_ip . '.' . $dnsbl . '.', 'A') === true) + { + $info = array($dnsbl, $lookup . $ip); + } + else + { + $listed = false; + } + } + + if ($listed) + { + return $info; + } + } + + return false; + } + + /** + * Check if URI is blacklisted + * This should be called only where absolutly necessary, for example on the submitted website field + * This function is not in use at the moment and is only included for testing purposes, it may not work at all! + * This means it is untested at the moment and therefore commented out + * + * @param string $uri URI to check + * @return true if uri is on blacklist, else false. Only blacklist is checked (~zero FP), no grey lists + function check_uribl($uri) + { + // Normally parse_url() is not intended to parse uris + // We need to get the top-level domain name anyway... change. + $uri = parse_url($uri); + + if ($uri === false || empty($uri['host'])) + { + return false; + } + + $uri = trim($uri['host']); + + if ($uri) + { + // One problem here... the return parameter for the "windows" method is different from what + // we expect... this may render this check useless... + if (phpbb_checkdnsrr($uri . '.multi.uribl.com.', 'A') === true) + { + return true; + } + } + + return false; + } + */ + + /** + * Set/Update a persistent login key + * + * This method creates or updates a persistent session key. When a user makes + * use of persistent (formerly auto-) logins a key is generated and stored in the + * DB. When they revisit with the same key it's automatically updated in both the + * DB and cookie. Multiple keys may exist for each user representing different + * browsers or locations. As with _any_ non-secure-socket no passphrase login this + * remains vulnerable to exploit. + */ + function set_login_key($user_id = false, $key = false, $user_ip = false) + { + global $board_config, $db; + + $user_id = ($user_id === false) ? $this->data['user_id'] : $user_id; + $user_ip = ($user_ip === false) ? $this->ip : $user_ip; + $key = ($key === false) ? (($this->cookie_data['k']) ? $this->cookie_data['k'] : false) : $key; + + $key_id = phpBB3::unique_id(hexdec(substr($this->session_id, 0, 8))); + + $sql_ary = array( + 'key_id' => (string) md5($key_id), + 'last_ip' => (string) $this->ip, + 'last_login' => (int) time() + ); + + if (!$key) + { + $sql_ary += array( + 'user_id' => (int) $user_id + ); + } + + if ($key) + { + $sql = 'UPDATE ' . SESSIONS_KEYS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE user_id = ' . (int) $user_id . " + AND key_id = '" . $db->sql_escape(md5($key)) . "'"; + } + else + { + $sql = 'INSERT INTO ' . SESSIONS_KEYS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); + } + $db->sql_query($sql); + + $this->cookie_data['k'] = $key_id; + + return false; + } + + /** + * Reset all login keys for the specified user + * + * This method removes all current login keys for a specified (or the current) + * user. It will be called on password change to render old keys unusable + */ + function reset_login_keys($user_id = false) + { + global $board_config, $db; + + $user_id = ($user_id === false) ? $this->data['user_id'] : $user_id; + + $sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE . ' + WHERE user_id = ' . (int) $user_id; + $db->sql_query($sql); + + // Let's also clear any current sessions for the specified user_id + // If it's the current user then we'll leave this session intact + $sql_where = 'session_user_id = ' . (int) $user_id; + $sql_where .= ($user_id === $this->data['user_id']) ? " AND session_id <> '" . $db->sql_escape($this->session_id) . "'" : ''; + + $sql = 'DELETE FROM ' . SESSIONS_TABLE . " + WHERE $sql_where"; + $db->sql_query($sql); + + // We're changing the password of the current user and they have a key + // Lets regenerate it to be safe + if ($user_id === $this->data['user_id'] && $this->cookie_data['k']) + { + $this->set_login_key($user_id); + } + } + + /** + * Check if the request originated from the same page. + * @param bool $check_script_path If true, the path will be checked as well + */ + function validate_referer($check_script_path = false) + { + global $board_config; + + // no referer - nothing to validate, user's fault for turning it off (we only check on POST; so meta can't be the reason) + if (empty($this->referer) || empty($this->host)) + { + return true; + } + + $host = htmlspecialchars($this->host); + $ref = substr($this->referer, strpos($this->referer, '://') + 3); + + if (!(stripos($ref, $host) === 0) && (!$board_config['force_server_vars'] || !(stripos($ref, $board_config['server_name']) === 0))) + { + return false; + } + else if ($check_script_path && rtrim($this->page['root_script_path'], '/') !== '') + { + $ref = substr($ref, strlen($host)); + $server_port = (!empty($_SERVER['SERVER_PORT'])) ? (int) $_SERVER['SERVER_PORT'] : (int) getenv('SERVER_PORT'); + + if ($server_port !== 80 && $server_port !== 443 && stripos($ref, ":$server_port") === 0) + { + $ref = substr($ref, strlen(":$server_port")); + } + + if (!(stripos(rtrim($ref, '/'), rtrim($this->page['root_script_path'], '/')) === 0)) + { + return false; + } + } + + return true; + } + + function unset_admin() + { + global $db; + $sql = 'UPDATE ' . SESSIONS_TABLE . ' + SET session_admin = 0 + WHERE session_id = \'' . $db->sql_escape($this->session_id) . '\''; + $db->sql_query($sql); + } + + /** ******************************************************************************************************* + * Include the User class + ******************************************************************************************************* */ + + /** + * Setup basic user-specific items (style, language, ...) + * Note: We've split original phpbb3 setup() method into setup() and setup_style() + */ + function setup($lang_set = false, $style = false) + { + global $db, $template, $board_config, $userdata, $phpbb_auth, $phpEx, $phpbb_root_path, $mx_root_path, $mx_cache; + global $mx_request_vars, $portal_config; //added for mxp + global $lang; //added for mxp + + $session_lang = ''; + /* + * Added here for reference and future implementation of a lang block in mx_coreblocks were board_config can be taken from portal_config + * + if ($board_config['lang_select_enable'] || $board_config['lang_click_enable']) + { + $session_lang_save = phpBB3::request_var('session_lang_save', false); + if (isset($session_lang_save) && $session_lang_save && $this->data['session_lang']) + { + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_lang = '" . $this->data['session_lang'] . "' + WHERE user_id = " . $this->data['user_id']; + $db->sql_query($sql); + } + + $session_lang_reset = phpBB3::request_var('session_lang_reset', false); + if (isset($session_lang_reset) && $session_lang_reset) + { + $session_lang = ''; + } + else + { + $session_lang = phpBB3::request_var('session_lang', ''); + } + + if ((isset($session_lang) && $session_lang) || $session_lang_reset) + { + $sql = 'UPDATE ' . SESSIONS_TABLE . " + SET session_lang = '" . $session_lang . "' + WHERE session_id = '" . $this->session_id . "'"; + $db->sql_query($sql); + } + elseif (isset($this->data['session_lang']) && $this->data['session_lang']) + { + $session_lang = $this->data['session_lang']; + } + } + + if (($board_config['lang_select_enable'] || $board_config['lang_click_enable']) && isset($session_lang) && $session_lang) + { + $this->data['user_lang'] = $session_lang; + $this->lang_name = (file_exists($this->lang_path . $this->data['user_lang'] . "/common.$phpEx")) ? $this->data['user_lang'] : basename($this->encode_lang($this->lang['default_lang'])); + + if ($this->data['user_id'] != ANONYMOUS) + { + $this->date_format = $this->data['user_dateformat']; + $this->timezone = $this->data['user_timezone'] * 3600; + $this->dst = $this->data['user_dst'] * 3600; + } + else + { + $this->date_format = $board_config['default_dateformat']; + $this->timezone = $board_config['board_timezone'] * 3600; + $this->dst = $board_config['board_dst'] * 3600; + } + } + */ + $lang_set = !$lang_set ? (defined('IN_ADMIN') ? 'acp/common' : 'common') : $lang_set; + + if ($this->data['session_logged_in']) + { + $this->lang_name = (file_exists($phpbb_root_path . 'language/' . $this->encode_lang($this->data['user_lang']) . "/common.$phpEx")) ? $this->encode_lang($this->data['user_lang']) : ((file_exists($phpbb_root_path . 'language/' . $this->encode_lang($this->lang['default_lang']) . "/common.$phpEx")) ? $this->encode_lang($this->lang['default_lang']) : 'en'); + $this->lang_path = $phpbb_root_path . 'language/' . $this->lang_name . '/'; + + $this->date_format = $this->data['user_dateformat']; + $this->timezone = $this->data['user_timezone'] * 3600; + $this->dst = $this->data['user_dst'] * 3600; + } + else + { + $this->lang_name = (file_exists($phpbb_root_path . 'language/' . $this->encode_lang($this->lang['default_lang']) . "/common.$phpEx")) ? $this->encode_lang($this->lang['default_lang']) : 'en'; + $this->lang_path = $phpbb_root_path . 'language/' . $this->lang_name . '/'; + $this->date_format = $board_config['default_dateformat']; + $this->timezone = $board_config['board_timezone'] * 3600; + $this->dst = $board_config['board_dst'] * 3600; + + /** + * If a guest user is surfing, we try to guess his/her language first by obtaining the browser language + * If re-enabled we need to make sure only those languages installed are checked + * Commented out so we do not loose the code. + * language checking added 2008-08-15 by Martin Truckenbrodt + **/ + if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) + { + $lang_iso_xx_yy = array(); + $lang_iso_xx = array(); + $accept_lang_xx_yy = array(); + $accept_lang_xx = array(); + + $sql = 'SELECT lang_iso FROM ' . LANG_TABLE; + $result = $db->sql_query($sql, 3600); + + while ($row = $db->sql_fetchrow($result)) + { + if (file_exists($phpbb_root_path . 'language/' . $row['lang_iso'] . "/common.$phpEx")) + { + $lang_iso_xx_yy[] = $row['lang_iso']; + if (strlen($row['lang_iso']) > 4) + { + $lang_iso_xx[$row['lang_iso']] = substr($row['lang_iso'], 0, 2); + } + } + } + $accept_lang_ary = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); + + foreach ($accept_lang_ary as $accept_lang) + { + // Set correct format ... guess full xx_yy form + $accept_lang_xx_yy = basename(substr($accept_lang, 0, 2) . '_' . strtolower(substr($accept_lang, 3, 2))); + // Set correct format ... guess only xx form + $accept_lang_xx = basename(substr($accept_lang, 0, 2)); + + // browser xx-YY == board xx_yy and + // browser xx == board xx + if (in_array($accept_lang_xx_yy, $lang_iso_xx_yy)) + { + $this->lang_name = $board_config['default_lang'] = $accept_lang_xx_yy; + break; + } + // browser xx-YY => xx == board xx + else if (in_array($accept_lang_xx, $lang_iso_xx_yy)) + { + $this->lang_name = $board_config['default_lang'] = $accept_lang_xx; + break; + } + // browser xx == board xx_yy => xx + else if (in_array($accept_lang_xx, $lang_iso_xx) && $lang_iso_xx != '') + { + $this->lang_name = $board_config['default_lang'] = array_search($accept_lang_xx, $lang_iso_xx); + break; + } + // board default language + else + { + $this->lang_name = (file_exists($phpbb_root_path . 'language/' . $this->encode_lang($this->lang['default_lang']) . "/common.$phpEx")) ? $this->encode_lang($this->lang['default_lang']) : 'en'; + } + } + $this->data['user_lang'] = $this->lang_name; + } + /* + */ + } + + /* We include common language file here to not load it every time a custom language file is included + $lang = &$this->lang; + */ + $include_result = (defined('DEBUG_EXTRA')) ? "" : "@"; // Do not suppress error if in DEBUG_EXTRA mode + if (("$include_result".include $this->lang_path . "common.$phpEx") === false) + { + //this will fix the path for anonymouse users + if ((@include $phpbb_root_path . $this->lang_path . "common.$phpEx") === false) + { + die('Language file ' . $this->lang_path . "common.$phpEx" . ' couldn\'t be opened.'); + } + } + + // + // We include common language file here to not load it every time a custom language file is included + // + $this->add_lang($lang_set); + + unset($lang_set); + } + + /** + * Enter description here... + * Note: We've split original phpbb3 setup() method into setup() and setup_style() + */ + function setup_style() + { + global $db, $template, $board_config, $userdata, $phpbb_auth, $phpEx, $phpbb_root_path, $mx_root_path, $mx_cache; + global $mx_request_vars, $portal_config, $board_config, $mx_backend; //added for mxp + + if (!empty($_GET['style']) && $phpbb_auth->acl_get('a_styles')) + { + global $SID, $_EXTRA_URL; + $style = phpBB3::request_var('style', 0); + // BEGIN Styles_Demo MOD for phpBB Block + $style_value = ''; + $SID .= '&style=' . $style; + $_EXTRA_URL = array('style=' . $style); + } + else + { + $style = $this->style; // From main style init. Should be correct and valid. + $style_value = $this->style_name; + // BEGIN Styles_Demo MOD for phpBB Block + /* */ + if(!$board_config['override_user_style'] && ($this->data['user_id'] != ANONYMOUS)) + { + // Set up style + $user_style = $this->data['user_style'] ? $this->data['user_style'] : $this->phpbb_style['style_id']; + //If user have other style in mxp then the one from phpBB not to have forum page and modules graphics will be messaed up + //Anonymouse users should see all block graphic corect + //Query phpBB style_id corepondent to mxp themes_id + $sql = "SELECT s.style_id, s.style_name + FROM " . MX_THEMES_TABLE . " AS m, " . STYLES_TABLE . " AS s, " . STYLES_TEMPLATE_TABLE . " AS t + WHERE m.themes_id = " . (int) $user_style . " + AND t.template_path = m.template_name + AND t.template_id = s.template_id"; + if ($row = $db->sql_fetchrow($db->sql_query($sql))) + { + $style = $row['style_id']; //User style + $style_value = $row['style_name']; //User style name + } + else + { + $style = $this->data['user_style'] ? $this->data['user_style'] : $board_config['default_style']; + } + } + else + { + $default_style = $portal_config['default_style']; + //If user have other style in mxp then the one from phpBB not to have forum page and modules graphics will be messaed up + //Anonymouse users should see all block graphic corect + //Query phpBB style_id corepondent to mxp themes_id + $sql = "SELECT s.style_id, s.style_name + FROM " . MX_THEMES_TABLE . " AS m, " . STYLES_TABLE . " AS s, " . STYLES_TEMPLATE_TABLE . " AS t + WHERE m.themes_id = " . (int) $default_style . " + AND t.template_path = m.template_name + AND t.template_id = s.template_id"; + if ($row = $db->sql_fetchrow($db->sql_query($sql))) + { + $style = $row['style_id']; //User style + $style_value = $row['style_name']; //User style name + } + else + { + $style = $this->data['user_style'] ? $this->data['user_style'] : $board_config['default_style']; + } + } + /* */ + // Set up style Temp code should be removed after bugtraking + //$style = ($style) ? $style : ((!$board_config['override_user_style'] && $this->data['user_id'] != ANONYMOUS) ? $this->data['user_style'] : $this->phpbb_style['style_id']); + } + + if (isset($_GET['demostyle'])) + { + $style_value = phpBB3::request_var('demostyle', ''); + if (intval($style_value) == 0) + { + //Query phpBB style_id corepondent to mxp style_name + //Any Demo Style here should work also for portal and forums + //Any Demo Style Name should be supported using same guild lines for portal as for forums for e.g. with spaces etc. + $sql = "SELECT s.style_id, s.style_name + FROM " . MX_THEMES_TABLE . " AS m, " . STYLES_TABLE . " AS s, " . STYLES_TEMPLATE_TABLE . " AS t + WHERE s.style_active = 1 AND s.style_name = '$style_value' + AND s.style_name = m.style_name + AND t.template_id = s.template_id"; + if(!$row = @$db->sql_fetchrow(@$db->sql_query($sql))) + { + die('Could not find style name '. $style_value . '!'); + } + else + { + $style_value = $row['style_id']; + } + } + else + { + //Query phpBB style_id corepondent to mxp themes_id + //Any Demo Style here should work also for portal and forums + //Any Demo Style Name should be supported using same guild lines for portal as for forums for e.g. with spaces etc. + $sql = "SELECT s.style_id, s.style_name + FROM " . MX_THEMES_TABLE . " AS m, " . STYLES_TABLE . " AS s, " . STYLES_TEMPLATE_TABLE . " AS t + WHERE m.themes_id = " . (int) $style_value . " + AND s.style_name = m.style_name + AND t.template_id = s.template_id"; + if(!$row = $db->sql_fetchrow($db->sql_query($sql))) + { + die('style_id ' . $style_value . ' not found'); + } + } + $this->set_cookie('change_style', $style_value, time() + 31536000); + } + elseif (isset($_COOKIE[$board_config['cookie_name'] . '_change_style'])) + { + $style_value = $_COOKIE[$board_config['cookie_name'] . '_change_style']; + } + + //Change the value before query + if (!empty($style_value)) + { + $style = $style_value; + } + + //We should never get this, temp fix for GoogleBot-2.1 crawler + //Remove this Deguging Code after solved + if ((intval($style) == 0) && empty($style_value)) + { + $style_value = 'prosilver'; + } + $phpbb_style = $style; + $phpbb_style_value = $style_value; + + // END Styles_Demo MOD + if (isset($style_value)) + { + //Query phpBB style_name + $sql = "SELECT s.style_id, s.style_name, t.template_storedb, t.template_path, t.template_id, t.bbcode_bitfield, c.theme_path, c.theme_name, c.theme_storedb, c.theme_id, i.imageset_path, i.imageset_id, i.imageset_name + FROM " . STYLES_TABLE . " AS s, " . STYLES_TEMPLATE_TABLE . " AS t, " . STYLES_THEME_TABLE . " AS c, " . STYLES_IMAGESET_TABLE . " i + WHERE s.style_active = 1 AND s.style_name = '$style_value' + AND t.template_id = s.template_id + AND c.theme_id = s.theme_id + AND i.imageset_id = s.imageset_id"; + if(($result = $db->sql_query($sql)) && ($row = $db->sql_fetchrow($result))) + { + $style = $row['style_id']; + $style_value = $row['style_name']; + } + else + { + mx_message_die(CRITICAL_ERROR, "Could not query database for phpbb_styles info style_name [$style]", "", __LINE__, __FILE__, $sql); + } + } + elseif (intval($style) !== 0) + { + //Query phpBB style_id get from main style init. Should be correct and valid. + $sql = "SELECT s.style_id, s.style_name, t.template_storedb, t.template_path, t.template_id, t.bbcode_bitfield, c.theme_path, c.theme_name, c.theme_storedb, c.theme_id, i.imageset_path, i.imageset_id, i.imageset_name + FROM " . MX_THEMES_TABLE . " AS m, " . STYLES_TABLE . " AS s, " . STYLES_TEMPLATE_TABLE . " AS t, " . STYLES_THEME_TABLE . " AS c, " . STYLES_IMAGESET_TABLE . " i + WHERE s.style_id = " . (int) $style . " + AND s.style_name = m.style_name + AND t.template_id = s.template_id + AND c.theme_id = s.theme_id + AND i.imageset_id = s.imageset_id"; + if(($result = $db->sql_query($sql)) && ($row = $db->sql_fetchrow($result))) + { + $style = $row['style_id']; + $style_value = $row['style_name']; + // MXP themes_id = $row['themes_id'] + } + else + { + mx_message_die(CRITICAL_ERROR, "Could not query database for phpbb_styles info style_id [$style]", "", __LINE__, __FILE__, $sql); + } + } + + $this->theme = is_array($this->theme) ? array_merge($this->theme, $row) : $row; + $db->sql_freeresult($result); + + // User has wrong style + if (!$this->theme && $style == $this->data['user_style']) + { + $style = $this->data['user_style'] = $board_config['default_style']; + + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_style = $style + WHERE user_id = {$this->data['user_id']}"; + $db->sql_query($sql); + + $sql = 'SELECT s.style_id, s.style_name, t.template_storedb, t.template_path, t.template_id, t.bbcode_bitfield, c.theme_path, c.theme_name, c.theme_storedb, c.theme_id, i.imageset_path, i.imageset_id, i.imageset_name + FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c, ' . STYLES_IMAGESET_TABLE . " i + WHERE s.style_id = $style + AND t.template_id = s.template_id + AND c.theme_id = s.theme_id + AND i.imageset_id = s.imageset_id"; + $result = $db->sql_query($sql, 3600); + $this->theme = is_array($this->theme) ? array_merge($this->theme, $db->sql_fetchrow($result)) : $db->sql_fetchrow($result); + $db->sql_freeresult($result); + $style = $this->theme['style_id']; + $style_value = $this->theme['style_name']; + } + + if (!$this->theme) + { + trigger_error('Could not get style data', E_USER_ERROR); + } + + // Now parse the cfg file and cache it + $parsed_items = $mx_backend->obtain_cfg_items($this->theme); + + // We are only interested in the theme configuration for now + $parsed_items = $parsed_items['theme']; + + $check_for = array( + 'parse_css_file' => (int) 0, + 'pagination_sep' => (string) ', ' + ); + + foreach ($check_for as $key => $default_value) + { + $this->theme[$key] = (isset($parsed_items[$key])) ? $parsed_items[$key] : $default_value; + settype($this->theme[$key], gettype($default_value)); + + if (is_string($default_value)) + { + $this->theme[$key] = htmlspecialchars($this->theme[$key]); + } + } + + // If the style author specified the theme needs to be cached + // (because of the used paths and variables) than make sure it is the case. + // For example, if the theme uses language-specific images it needs to be stored in db. + if (!$this->theme['theme_storedb'] && $this->theme['parse_css_file']) + { + $this->theme['theme_storedb'] = 1; + + $stylesheet = file_get_contents("{$phpbb_root_path}styles/{$this->theme['theme_path']}/theme/stylesheet.css"); + // Match CSS imports + $matches = array(); + preg_match_all('/@import url\(["\'](.*)["\']\);/i', $stylesheet, $matches); + if (sizeof($matches)) + { + $content = ''; + foreach ($matches[0] as $idx => $match) + { + if ($content = @file_get_contents("{$phpbb_root_path}styles/{$this->theme['theme_path']}/theme/" . $matches[1][$idx])) + { + $content = trim($content); + } + else + { + $content = ''; + } + $stylesheet = str_replace($match, $content, $stylesheet); + } + unset($content); + } + + $stylesheet = str_replace('./', 'styles/' . $this->theme['theme_path'] . '/theme/', $stylesheet); + + $sql_ary = array( + 'theme_data' => $stylesheet, + 'theme_mtime' => time(), + 'theme_storedb' => 1 + ); + + $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE theme_id = ' . $this->theme['theme_id']; + $db->sql_query($sql); + + unset($sql_ary); + } + + $template->set_template(); + + $this->img_lang = (file_exists($phpbb_root_path . 'styles/' . $this->theme['imageset_path'] . '/imageset/' . $this->lang_name)) ? $this->lang_name : $this->encode_lang($board_config['default_lang']); + + $sql = 'SELECT image_name, image_filename, image_lang, image_height, image_width + FROM ' . STYLES_IMAGESET_DATA_TABLE . ' + WHERE imageset_id = ' . $this->theme['imageset_id'] . " + AND image_filename <> '' + AND image_lang IN ('" . $db->sql_escape($this->img_lang) . "', '')"; + $result = $db->sql_query($sql, 3600); + + $localised_images = false; + while ($row = $db->sql_fetchrow($result)) + { + if ($row['image_lang']) + { + $localised_images = true; + } + + $this->img_array[$row['image_name']] = $row; + } + $db->sql_freeresult($result); + // there were no localised images, try to refresh the localised imageset for the user's language + if (!$localised_images) + { + // Attention: this code ignores the image definition list from acp_styles and just takes everything + // that the config file contains + $sql_ary = array(); + + $db->sql_transaction('begin'); + + $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . ' + WHERE imageset_id = ' . $this->theme['imageset_id'] . ' + AND image_lang = \'' . $db->sql_escape($this->img_lang) . '\''; + $result = $db->sql_query($sql); + + if (@file_exists("{$phpbb_root_path}styles/{$this->theme['imageset_path']}/imageset/{$this->img_lang}/imageset.cfg")) + { + $cfg_data_imageset_data = phpBB3::parse_cfg_file("{$phpbb_root_path}styles/{$this->theme['imageset_path']}/imageset/{$this->img_lang}/imageset.cfg"); + foreach ($cfg_data_imageset_data as $image_name => $value) + { + if (strpos($value, '*') !== false) + { + if (substr($value, -1, 1) === '*') + { + list($image_filename, $image_height) = explode('*', $value); + $image_width = 0; + } + else + { + list($image_filename, $image_height, $image_width) = explode('*', $value); + } + } + else + { + $image_filename = $value; + $image_height = $image_width = 0; + } + + if (strpos($image_name, 'img_') === 0 && $image_filename) + { + $image_name = substr($image_name, 4); + $sql_ary[] = array( + 'image_name' => (string) $image_name, + 'image_filename' => (string) $image_filename, + 'image_height' => (int) $image_height, + 'image_width' => (int) $image_width, + 'imageset_id' => (int) $this->theme['imageset_id'], + 'image_lang' => (string) $this->img_lang, + ); + } + } + } + + if (sizeof($sql_ary)) + { + $db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary); + $db->sql_transaction('commit'); + $mx_cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE); + + mx_add_log('admin', 'LOG_IMAGESET_LANG_REFRESHED', $this->theme['imageset_name'], $this->img_lang); + } + else + { + $db->sql_transaction('commit'); + mx_add_log('admin', 'LOG_IMAGESET_LANG_MISSING', $this->theme['imageset_name'], $this->img_lang); + } + } + // If this function got called from the error handler we are finished here. + if (defined('IN_ERROR_HANDLER')) + { + return; + } + // Disable board if the install/ directory is still present + // For the brave development army we do not care about this, else we need to comment out this everytime we develop locally + if (!defined('DEBUG_EXTRA') && !defined('ADMIN_START') && !defined('IN_INSTALL') && !defined('IN_LOGIN') && file_exists($phpbb_root_path . 'install')) + { + // Adjust the message slightly according to the permissions + if ($phpbb_auth->acl_gets('a_', 'm_') || $phpbb_auth->acl_getf_global('m_')) + { + $message = 'REMOVE_INSTALL'; + } + else + { + $message = (!empty($portal_config['disabled_message'])) ? $portal_config['disabled_message'] : 'BOARD_DISABLE'; + } + trigger_error($message); + } + // Is portal disabled and user not an admin or moderator? + if (($portal_config['portal_status'] == '0') && !defined('IN_LOGIN') && !$phpbb_auth->acl_gets('a_', 'm_') && !$phpbb_auth->acl_getf_global('m_')) + { + @header('HTTP/1.1 503 Service Unavailable'); + // Is board disabled and user not an admin or moderator? + if($board_config['board_disable_mess_st']) + { + $message_st = $board_config['board_disable_message']; + } + else + { + $message_st = (!empty($lang['Board_disabled'])) ? $lang['Board_disabled'] : 'BOARD_DISABLE'; + } + $message = (!empty($portal_config['disabled_message'])) ? $portal_config['disabled_message'] : $message_st; + trigger_error($message); + } + // Is load exceeded? + if ($board_config['limit_load'] && $this->load !== false) + { + if ($this->load > floatval($board_config['limit_load']) && !defined('IN_LOGIN')) + { + // Set board disabled to true to let the admins/mods get the proper notification + $board_config['board_disable'] = '1'; + $portal_config['portal_status'] = '0'; + if (!$phpbb_auth->acl_gets('a_', 'm_') && !$phpbb_auth->acl_getf_global('m_')) + { + @header('HTTP/1.1 503 Service Unavailable'); + trigger_error('BOARD_UNAVAILABLE'); + } + } + } + if (isset($this->data['session_viewonline'])) + { + // Make sure the user is able to hide his session + if (!$this->data['session_viewonline']) + { + // Reset online status if not allowed to hide the session... + if (!$phpbb_auth->acl_get('u_hideonline')) + { + $sql = 'UPDATE ' . SESSIONS_TABLE . ' + SET session_viewonline = 1 + WHERE session_user_id = ' . $this->data['user_id']; + $db->sql_query($sql); + $this->data['session_viewonline'] = 1; + } + } + else if (!$this->data['user_allow_viewonline']) + { + // the user wants to hide and is allowed to -> cloaking device on. + if ($phpbb_auth->acl_get('u_hideonline')) + { + $sql = 'UPDATE ' . SESSIONS_TABLE . ' + SET session_viewonline = 0 + WHERE session_user_id = ' . $this->data['user_id']; + $db->sql_query($sql); + $this->data['session_viewonline'] = 0; + } + } + } + // Does the user need to change their password? If so, redirect to the + // ucp profile reg_details page ... of course do not redirect if we're already in the ucp + if (!defined('IN_ADMIN') && !defined('ADMIN_START') && $board_config['chg_passforce'] && $this->data['is_registered'] && $phpbb_auth->acl_get('u_chgpasswd') && $this->data['user_passchg'] < time() - ($board_config['chg_passforce'] * 86400)) + { + if (strpos($this->page['query_string'], 'mode=reg_details') === false && $this->page['page_name'] != "ucp.$phpEx") + { + mx_redirect(mx_append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=profile&mode=reg_details')); + } + } + return; + } + + /** + * Add Language Items - use_db and use_help are assigned where needed (only use them to force inclusion) + * + * @param mixed $lang_set specifies the language entries to include + * @param bool $use_db internal variable for recursion, do not use + * @param bool $use_help internal variable for recursion, do not use + * + * Examples: + *+ * $lang_set = array('posting', 'help' => 'faq'); + * $lang_set = array('posting', 'viewtopic', 'help' => array('bbcode', 'faq')) + * $lang_set = array(array('posting', 'viewtopic'), 'help' => array('bbcode', 'faq')) + * $lang_set = 'posting' + * $lang_set = array('help' => 'faq', 'db' => array('help:faq', 'posting')) + *
+ */ + function add_lang($lang_set, $use_db = false, $use_help = false) + { + global $phpEx; + + if (is_array($lang_set)) + { + foreach ($lang_set as $key => $lang_file) + { + // Please do not delete this line. + // We have to force the type here, else [array] language inclusion will not work + $key = (string) $key; + + if ($key == 'db') + { + $this->add_lang($lang_file, true, $use_help); + } + else if ($key == 'help') + { + $this->add_lang($lang_file, $use_db, true); + } + else if (!is_array($lang_file)) + { + $this->set_lang($this->lang, $this->help, $lang_file, $use_db, $use_help); + } + else + { + $this->add_lang($lang_file, $use_db, $use_help); + } + } + unset($lang_set); + } + elseif ($lang_set) + { + $this->set_lang($this->lang, $this->help, $lang_set, $use_db, $use_help); + } + } + + /** + * Set language entry (called by add_lang) + * @access private + */ + function set_lang(&$lang, &$help, $lang_file, $use_db = false, $use_help = false) + { + global $phpbb_root_path, $phpEx; + + // Make sure the language path is set (if the user setup did not happen it is not set) + if (!$this->lang_path) + { + global $board_config; + + $this->lang_path = $phpbb_root_path . 'language/' . basename($board_config['phpbb_lang']) . '/'; + } + + // $lang == $this->lang + // $help == $this->help + // - add appropriate variables here, name them as they are used within the language file... + if (!$use_db) + { + if ($use_help && strpos($lang_file, '/') !== false) + { + $language_filename = $this->lang_path . substr($lang_file, 0, stripos($lang_file, '/') + 1) . 'help_' . substr($lang_file, stripos($lang_file, '/') + 1) . '.' . $phpEx; + } + else + { + $language_filename = $this->lang_path . (($use_help) ? 'help_' : '') . $lang_file . '.' . $phpEx; + } + + //fix for mxp + if ((@include $language_filename) === false) + { + //this will fix the path for anonymouse users + if ((@include $phpbb_root_path . $language_filename) === false) + { + die('Language file ' . $language_filename . ' couldn\'t be opened.'); + } + } + } + else + { + // Get Database Language Strings + // Put them into $lang if nothing is prefixed, put them into $help if help: is prefixed + // For example: help:faq, posting + die("You should not use db with MX-Publisher!"); + } + + // We include common language file here to not load it every time a custom language file is included + $this->lang = &$lang; + } + + /** + * Format user date + * + * @param int $gmepoch unix timestamp + * @param string $format date format in date() notation. | used to indicate relative dates, for example |d m Y|, h:i is translated to Today, h:i. + * @param bool $forcedate force non-relative date format. + * + * @return mixed translated date + */ + function format_date($gmepoch, $format = false, $forcedate = false) + { + static $midnight; + static $date_cache; + + $format = (!$format) ? $this->date_format : $format; + $now = time(); + $delta = $now - $gmepoch; + + if (!isset($date_cache[$format])) + { + // Is the user requesting a friendly date format (i.e. 'Today 12:42')? + $date_cache[$format] = array( + 'is_short' => strpos($format, '|'), + 'format_short' => substr($format, 0, strpos($format, '|')) . '||' . substr(strrchr($format, '|'), 1), + 'format_long' => str_replace('|', '', $format), + // Filter out values that are not strings (e.g. arrays) for strtr(). + 'lang' => array_filter($this->lang['datetime'], 'is_string'), + ); + + // Short representation of month in format? Some languages use different terms for the long and short format of May + if ((strpos($format, '\M') === false && strpos($format, 'M') !== false) || (strpos($format, '\r') === false && strpos($format, 'r') !== false)) + { + $date_cache[$format]['lang']['May'] = $this->lang['datetime']['May_short']; + } + } + + // Zone offset + $zone_offset = $this->timezone + $this->dst; + + // Show date <= 1 hour ago as 'xx min ago' but not greater than 60 seconds in the future + // A small tolerence is given for times in the future but in the same minute are displayed as '< than a minute ago' + if ($delta <= 3600 && $delta > -60 && ($delta >= -5 || (($now / 60) % 60) == (($gmepoch / 60) % 60)) && $date_cache[$format]['is_short'] !== false && !$forcedate && isset($this->lang['datetime']['AGO'])) + { + return $this->lang(array('datetime', 'AGO'), max(0, (int) floor($delta / 60))); + } + + if (!$midnight) + { + list($d, $m, $y) = explode(' ', gmdate('j n Y', time() + $zone_offset)); + $midnight = gmmktime(0, 0, 0, $m, $d, $y) - $zone_offset; + } + + if ($date_cache[$format]['is_short'] !== false && !$forcedate && !($gmepoch < $midnight - 86400 || $gmepoch > $midnight + 172800)) + { + $day = false; + + if ($gmepoch > $midnight + 86400) + { + $day = 'TOMORROW'; + } + else if ($gmepoch > $midnight) + { + $day = 'TODAY'; + } + else if ($gmepoch > $midnight - 86400) + { + $day = 'YESTERDAY'; + } + + if ($day !== false) + { + return str_replace('||', $this->lang['datetime'][$day], strtr(@gmdate($date_cache[$format]['format_short'], $gmepoch + $zone_offset), $date_cache[$format]['lang'])); + } + } + + return strtr(@gmdate($date_cache[$format]['format_long'], $gmepoch + $zone_offset), $date_cache[$format]['lang']); + } + + /** + * Get language id currently used by the user + **/ + function get_iso_lang_id() + { + global $board_config, $db; + + if (!empty($this->lang_id)) + { + return $this->lang_id; + } + + if (!$this->lang_name) + { + $this->lang_name = $board_config['default_lang']; + } + + $sql = 'SELECT lang_id + FROM ' . LANG_TABLE . " + WHERE lang_iso = '" . $db->sql_escape($this->lang_name) . "'"; + $result = $db->sql_query($sql); + $this->lang_id = (int) $db->sql_fetchfield('lang_id'); + $db->sql_freeresult($result); + + return $this->lang_id; + } + + /** + * Get users profile fields + */ + function get_profile_fields($user_id) + { + global $db; + + if (isset($this->profile_fields)) + { + return; + } + + $sql = 'SELECT * + FROM ' . PROFILE_FIELDS_DATA_TABLE . " + WHERE user_id = $user_id"; + $result = $db->sql_query_limit($sql, 1); + $this->profile_fields = (!($row = $db->sql_fetchrow($result))) ? array() : $row; + $db->sql_freeresult($result); + } + + /** + * Gets the user's info + * + * Will take the users email, username or member id and return their data + * + * @param int || string $username the user's email address username or member id + * @return array $results containing the user info || bool false + * @since 0.1.2 + */ + function load_user($user, $force_str = false) + { + if (!is_numeric($user) || $force_str) + { + $user = phpBB2::phpbb_clean_username($user); + } + else + { + $user = intval($user); + } + + //$this->data = array(); + + // we'll try id || email, then username + if (is_numeric($user)) + { + // number is most likely a member id + $this->data = get_user_by_id($user); + } + else + { + // the email can't be purely numeric + $this->data = get_user_by_email($user); + } + + if (empty($this->data)) + { + $this->data = get_user_by_username($user); + } + /* + if (empty($this->data)) + { + return false; + } + else + { + return $this->data; + } + */ + } + + /** + * Load user helper + * + * @param array $user_ids + */ + function load_users(array $user_ids) + { + $user_ids[] = ANONYMOUS; + + // Make user_ids unique and convert to integer. + $user_ids = array_map('intval', array_unique($user_ids)); + + // Do not load users we already have in $this->users + $user_ids = array_diff($user_ids, array_keys($this->users)); + + if (sizeof($user_ids)) + { + $sql = 'SELECT * + FROM ' . USERS_TABLE . ' + WHERE ' . $db->sql_in_set('user_id', $user_ids); + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $this->users[$row['user_id']] = $row; + } + $db->sql_freeresult($result); + } + } + + /** + * Gets the user's info from their email address + * + * Will take the users email address and return an array containing all the + * user's information in the db. Will return false on failure + * + * @param string $email the user's email address + * @return array $results containing the user info || bool false + * @since 0.1.0 + */ + function get_user_by_email($email_address = '') + { + global $db; + if ('' == $email_address || !is_string($email_address) || 2 > count(explode('@', $email_address))) + { + return false; + } + $sql = $db->sql_build_query('SELECT', ' + SELECT * FROM ' . USERS_TABLE . ' + WHERE email_address = {string:email_address}', + array('email_address' => $email_address, )); + $result = $db->sql_query_limit($sql, 1); + $return = $db->sql_fetchrow($result); + if (!$return) + { + $db->sql_freeresult($result); + //trigger_error($mx_user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING); + } + if (empty($return)) + { + return false; + } + else + { + // return all the results. + return $return; + } + } + + /** + * Gets the user's info from their member id + * + * Will take the users member id and return an array containing all the + * user's information in the db. Will return false on failure + * + * @param int $id the user's member id + * @return array $results containing the user info || bool false + * @since 0.1.2 + */ + function get_user_by_id($user_id = '') + { + global $db; + if ('' == $user_id || !is_numeric($user_id)) + { + return false; + } + else + { + $id = intval($user_id); + if (0 == $user_id) + { + return false; + } + } + $sql = $db->sql_build_query('SELECT', ' + SELECT * FROM ' . USERS_TABLE . ' + WHERE user_id = {int:user_id}', + array('user_id' => $user_id, )); + $result = $db->sql_query_limit($sql, 1); + $return = $db->sql_fetchrow($result); + if (!$return) + { + $db->sql_freeresult($result); + //trigger_error($mx_user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING); + } + if (empty($return)) + { + return false; + } + else + { + // return all the results. + return $return; + } + } + + /** + * Gets the user's info from their member name (username) + * + * Will take the users member name and return an array containing all the + * user's information in the db. Will return false on failure + * + * @param string $username the user's member name + * @return array $results containing the user info || bool false + * @since 0.1.0 + */ + function get_user_by_name($user_name = '') + { + global $db; + if ('' == $user_name || !is_string($user_name)) + { + return false; + } + $sql = $db->sql_build_query('SELECT', ' + SELECT * FROM ' . USERS_TABLE . ' + WHERE user_name = {string:user_name}', + array('user_name' => $user_name, )); + $result = $db->sql_query_limit($sql, 1); + $return = $db->sql_fetchrow($result); + if (!$return) + { + $db->sql_freeresult($result); + //trigger_error($mx_user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING); + } + if (empty($return)) + { + return false; + } + else + { + // return all the results. + return $return; + } + } + + /** + * Specify/Get images + */ + function images($img, $alt = '', $width = false, $suffix = '', $type = 'src') + { + static $imgs; + global $phpbb_root_path, $mx_root_path; + $img_data = &$imgs[$img]; + + if (empty($img_data)) + { + if (!isset($this->img_array[$img])) + { + // Do not fill the image to let designers decide what to do if the image is empty + $img_data = ''; + return $img_data; + } + $img_data['image_lang'] = $this->img_array[$img]['image_lang']; + $img_data['src'] = (!empty($img_data['image_lang']) ? (PHPBB_URL . 'styles/' . $this->theme['imageset_path'] . '/theme/' . $img_data['image_lang'] . '/' . $this->img_array[$img]['image_filename']) : (PHPBB_URL . 'styles/' . $this->theme['imageset_path'] . '/theme/images/' . $this->img_array[$img]['image_filename'])); + $img_data['width'] = $this->img_array[$img]['image_width']; + $img_data['height'] = $this->img_array[$img]['image_height']; + } + + $alt = (!empty($this->lang[$alt])) ? $this->lang[$alt] : $alt; + + switch ($type) + { + case 'full_tag': + $use_width = ($width === false) ? $img_data['width'] : $width; + + return ''; + break; + + case 'width': + return ($width === false) ? $img_data['width'] : $width; + break; + + case 'height': + return $img_data['height']; + break; + + default: + return $img_data['src']; + break; + } + } + + /** + * Specify/Get image + */ + function img($img, $alt = '', $width = false, $suffix = '', $type = 'full_tag') + { + static $imgs; + global $phpbb_root_path, $mx_root_path; + + $img_data = &$imgs[$img]; + + if (empty($img_data)) + { + if (!isset($this->img_array[$img])) + { + // Do not fill the image to let designers decide what to do if the image is empty + $img_data = ''; + return $img_data; + } + $img_data['src'] = (!empty($this->img_array[$img]['image_lang']) ? (PHPBB_URL . 'styles/' . $this->theme['imageset_path'] . '/theme/' . $this->img_array[$img]['image_lang'] . '/' . $this->img_array[$img]['image_filename']) : (PHPBB_URL . 'styles/' . $this->theme['imageset_path'] . '/theme/images/' . $this->img_array[$img]['image_filename'])); + $img_data['width'] = $this->img_array[$img]['image_width']; + $img_data['height'] = $this->img_array[$img]['image_height']; + } + + $alt = (!empty($this->lang[$alt])) ? $this->lang[$alt] : $alt; + //die($img_data); + switch ($type) + { + case 'src': + return $img_data['src']; + break; + + case 'width': + return ($width === false) ? $img_data['width'] : $width; + break; + + case 'height': + return $img_data['height']; + break; + + default: + $use_width = ($width === false) ? $img_data['width'] : $width; + + return '
'; + break; + } + } + + /** + * Get option bit field from user options + */ + function optionget($key, $data = false) + { + if (!isset($this->keyvalues[$key])) + { + $var = ($data) ? $data : $this->data['user_options']; + $this->keyvalues[$key] = ($var & 1 << $this->keyoptions[$key]) ? true : false; + } + + return $this->keyvalues[$key]; + } + + /** + * Set option bit field for user options + */ + function optionset($key, $value, $data = false) + { + $var = ($data) ? $data : $this->data['user_options']; + + if ($value && !($var & 1 << $this->keyoptions[$key])) + { + $var += 1 << $this->keyoptions[$key]; + } + else if (!$value && ($var & 1 << $this->keyoptions[$key])) + { + $var -= 1 << $this->keyoptions[$key]; + } + else + { + return ($data) ? $var : false; + } + + if (!$data) + { + $this->data['user_options'] = $var; + return true; + } + else + { + return $var; + } + } + + /** + * encode_lang + * + * $default_lang = $mx_user->encode_lang($board_config['default_lang']); + * + * @param unknown_type $lang + * @return unknown + */ + function encode_lang($lang) + { + switch($lang) + { + case 'afar': + $lang_name = 'aa'; + break; + case 'abkhazian': + $lang_name = 'ab'; + break; + case 'avestan': + $lang_name = 'ae'; + break; + case 'afrikaans': + $lang_name = 'af'; + break; + case 'akan': + $lang_name = 'ak'; + break; + case 'amharic': + $lang_name = 'am'; + break; + case 'aragonese': + $lang_name = 'an'; + break; + case 'arabic': + $lang_name = 'ar'; + break; + case 'assamese': + $lang_name = 'as'; + break; + case 'avaric': + $lang_name = 'av'; + break; + case 'aymara': + $lang_name = 'ay'; + break; + case 'azerbaijani': + $lang_name = 'az'; + break; + case 'bashkir': + $lang_name = 'ba'; + break; + case 'belarusian': + $lang_name = 'be'; + break; + case 'bulgarian': + $lang_name = 'bg'; + break; + case 'bihari': + $lang_name = 'bh'; + break; + case 'bislama': + $lang_name = 'bi'; + break; + case 'bambara': + $lang_name = 'bm'; + break; + case 'bengali': + $lang_name = 'bn'; + break; + case 'tibetan': + $lang_name = 'bo'; + break; + case 'breton': + $lang_name = 'br'; + break; + case 'bosnian': + $lang_name = 'bs'; + break; + case 'catalan': + $lang_name = 'ca'; + break; + case 'chechen': + $lang_name = 'ce'; + break; + case 'chamorro': + $lang_name = 'ch'; + break; + case 'corsican': + $lang_name = 'co'; + break; + case 'cree': + $lang_name = 'cr'; + break; + case 'czech': + $lang_name = 'cs'; + break; + case 'slavonic': + $lang_name = 'cu'; + break; + case 'chuvash': + $lang_name = 'cv'; + break; + case 'welsh_cymraeg': + $lang_name = 'cy'; + break; + case 'danish': + $lang_name = 'da'; + break; + case 'german': + $lang_name = 'de'; + break; + case 'divehi': + $lang_name = 'dv'; + break; + case 'dzongkha': + $lang_name = 'dz'; + break; + case 'ewe': + $lang_name = 'ee'; + break; + case 'greek': + $lang_name = 'el'; + break; + case 'hebrew': + $lang_name = 'he'; + break; + case 'english': + $lang_name = 'en'; + break; + case 'english_us': + $lang_name = 'en_us'; + break; + case 'esperanto': + $lang_name = 'eo'; + break; + case 'spanish': + $lang_name = 'es'; + break; + case 'estonian': + $lang_name = 'et'; + break; + case 'basque': + $lang_name = 'eu'; + break; + case 'persian': + $lang_name = 'fa'; + break; + case 'fulah': + $lang_name = 'ff'; + break; + case 'finnish': + $lang_name = 'fi'; + break; + case 'fijian': + $lang_name = 'fj'; + break; + case 'faroese': + $lang_name = 'fo'; + break; + case 'french': + $lang_name = 'fr'; + break; + case 'frisian': + $lang_name = 'fy'; + break; + case 'irish': + $lang_name = 'ga'; + break; + case 'scottish': + $lang_name = 'gd'; + break; + case 'galician': + $lang_name = 'gl'; + break; + case 'guaraní': + $lang_name = 'gn'; + break; + case 'gujarati': + $lang_name = 'gu'; + break; + case 'manx': + $lang_name = 'gv'; + break; + case 'hausa': + $lang_name = 'ha'; + break; + case 'hebrew': + $lang_name = 'he'; + break; + case 'hindi': + $lang_name = 'hi'; + break; + case 'hiri_motu': + $lang_name = 'ho'; + break; + case 'croatian': + $lang_name = 'hr'; + break; + case 'haitian': + $lang_name = 'ht'; + break; + case 'hungarian': + $lang_name = 'hu'; + break; + case 'armenian': + $lang_name = 'hy'; + break; + case 'herero': + $lang_name = 'hz'; + break; + case 'interlingua': + $lang_name = 'ia'; + break; + case 'indonesian': + $lang_name = 'id'; + break; + case 'interlingue': + $lang_name = 'ie'; + break; + case 'igbo': + $lang_name = 'ig'; + break; + case 'sichuan_yi': + $lang_name = 'ii'; + break; + case 'inupiaq': + $lang_name = 'ik'; + break; + case 'ido': + $lang_name = 'io'; + break; + case 'icelandic': + $lang_name = 'is'; + break; + case 'italian': + $lang_name = 'it'; + break; + case 'inuktitut': + $lang_name = 'iu'; + break; + case 'japanese': + $lang_name = 'ja'; + break; + case 'javanese': + $lang_name = 'jv'; + break; + case 'georgian': + $lang_name = 'ka'; + break; + case 'kongo': + $lang_name = 'kg'; + break; + case 'kikuyu': + $lang_name = 'ki'; + break; + case 'kwanyama': + $lang_name = 'kj'; + break; + case 'kazakh': + $lang_name = 'kk'; + break; + case 'kalaallisut': + $lang_name = 'kl'; + break; + case 'khmer': + $lang_name = 'km'; + break; + case 'kannada': + $lang_name = 'kn'; + break; + case 'korean': + $lang_name = 'ko'; + break; + case 'kanuri': + $lang_name = 'kr'; + break; + case 'kashmiri': + $lang_name = 'ks'; + break; + case 'kurdish': + $lang_name = 'ku'; + break; + case 'kv': + $lang_name = 'komi'; + break; + case 'cornish_kernewek': + $lang_name = 'kw'; + break; + case 'kirghiz': + $lang_name = 'ky'; + break; + case 'latin': + $lang_name = 'la'; + break; + case 'luxembourgish': + $lang_name = 'lb'; + break; + case 'ganda': + $lang_name = 'lg'; + break; + case 'limburgish': + $lang_name = 'li'; + break; + case 'lingala': + $lang_name = 'ln'; + break; + case 'lao': + $lang_name = 'lo'; + break; + case 'lithuanian': + $lang_name = 'lt'; + break; + case 'luba-katanga': + $lang_name = 'lu'; + break; + case 'latvian': + $lang_name = 'lv'; + break; + case 'malagasy': + $lang_name = 'mg'; + break; + case 'marshallese': + $lang_name = 'mh'; + break; + case 'maori': + $lang_name = 'mi'; + break; + case 'macedonian': + $lang_name = 'mk'; + break; + case 'malayalam': + $lang_name = 'ml'; + break; + case 'mongolian': + $lang_name = 'mn'; + break; + case 'moldavian': + $lang_name = 'mo'; + break; + case 'marathi': + $lang_name = 'mr'; + break; + case 'malay': + $lang_name = 'ms'; + break; + case 'maltese': + $lang_name = 'mt'; + break; + case 'burmese': + $lang_name = 'my'; + break; + case 'nauruan': + $lang_name = 'na'; + break; + case 'norwegian': + $lang_name = 'nb'; + break; + case 'ndebele': + $lang_name = 'nd'; + break; + case 'nepali': + $lang_name = 'ne'; + break; + case 'ndonga': + $lang_name = 'ng'; + break; + case 'dutch': + $lang_name = 'nl'; + break; + case 'norwegian_nynorsk': + $lang_name = 'nn'; + break; + case 'norwegian': + $lang_name = 'no'; + break; + case 'southern_ndebele': + $lang_name = 'nr'; + break; + case 'navajo': + $lang_name = 'nv'; + break; + case 'chichewa': + $lang_name = 'ny'; + break; + case 'occitan': + $lang_name = 'oc'; + break; + case 'ojibwa': + $lang_name = 'oj'; + break; + case 'oromo': + $lang_name = 'om'; + break; + case 'oriya': + $lang_name = 'or'; + break; + case 'ossetian': + $lang_name = 'os'; + break; + case 'panjabi': + $lang_name = 'pa'; + break; + case 'pali': + $lang_name = 'pi'; + break; + case 'polish': + $lang_name = 'pl'; + break; + case 'pashto': + $lang_name = 'ps'; + break; + case 'portuguese': + $lang_name = 'pt'; + break; + case 'portuguese_brasil': + $lang_name = 'pt_br'; + break; + case 'quechua': + $lang_name = 'qu'; + break; + case 'romansh': + $lang_name = 'rm'; + break; + case 'kirundi': + $lang_name = 'rn'; + break; + case 'romanian': + $lang_name = 'ro'; + break; + case 'russian': + $lang_name = 'ru'; + break; + case 'kinyarwanda': + $lang_name = 'rw'; + break; + case 'sanskrit': + $lang_name = 'sa'; + break; + case 'sardinian': + $lang_name = 'sc'; + break; + case 'sindhi': + $lang_name = 'sd'; + break; + case 'northern_sami': + $lang_name = 'se'; + break; + case 'sango': + $lang_name = 'sg'; + break; + case 'serbo-croatian': + $lang_name = 'sh'; + break; + case 'sinhala': + $lang_name = 'si'; + break; + case 'slovak': + $lang_name = 'sk'; + break; + case 'slovenian': + $lang_name = 'sl'; + break; + case 'samoan': + $lang_name = 'sm'; + break; + case 'shona': + $lang_name = 'sn'; + break; + case 'somali': + $lang_name = 'so'; + break; + case 'albanian': + $lang_name = 'sq'; + break; + case 'serbian': + $lang_name = 'sr'; + break; + case 'swati': + $lang_name = 'ss'; + break; + case 'sotho': + $lang_name = 'st'; + break; + case 'sundanese': + $lang_name = 'su'; + break; + case 'swedish': + $lang_name = 'sv'; + break; + case 'swahili': + $lang_name = 'sw'; + break; + case 'tamil': + $lang_name = 'ta'; + break; + case 'telugu': + $lang_name = 'te'; + break; + case 'tajik': + $lang_name = 'tg'; + break; + case 'thai': + $lang_name = 'th'; + break; + case 'tigrinya': + $lang_name = 'ti'; + break; + case 'turkmen': + $lang_name = 'tk'; + break; + case 'tagalog': + $lang_name = 'tl'; + break; + case 'tswana': + $lang_name = 'tn'; + break; + case 'tonga': + $lang_name = 'to'; + break; + case 'turkish': + $lang_name = 'tr'; + break; + case 'tsonga': + $lang_name = 'ts'; + break; + case 'tatar': + $lang_name = 'tt'; + break; + case 'twi': + $lang_name = 'tw'; + break; + case 'tahitian': + $lang_name = 'ty'; + break; + case 'uighur': + $lang_name = 'ug'; + break; + case 'ukrainian': + $lang_name = 'uk'; + break; + case 'urdu': + $lang_name = 'ur'; + break; + case 'uzbek': + $lang_name = 'uz'; + break; + case 'venda': + $lang_name = 've'; + break; + case 'vietnamese': + $lang_name = 'vi'; + break; + case 'volapuk': + $lang_name = 'vo'; + break; + case 'walloon': + $lang_name = 'wa'; + break; + case 'wolof': + $lang_name = 'wo'; + break; + case 'xhosa': + $lang_name = 'xh'; + break; + case 'yiddish': + $lang_name = 'yi'; + break; + case 'yoruba': + $lang_name = 'yo'; + break; + case 'zhuang': + $lang_name = 'za'; + break; + case 'chinese': + $lang_name = 'zh'; + break; + case 'chinese_simplified': + $lang_name = 'zh_cmn_hans'; + break; + case 'chinese_traditional': + $lang_name = 'zh_cmn_hant'; + break; + case 'zulu': + $lang_name = 'zu'; + break; + default: + $lang_name = $lang; + break; + } + return $lang_name; + } + + /** + * decode_lang + * + * $default_lang = $mx_user->decode_lang($board_config['default_lang']); + * + * @param unknown_type $lang + * @return unknown + */ + function decode_lang($lang) + { + switch($lang) + { + case 'aa': + $lang_name = 'afar'; + break; + case 'ab': + $lang_name = 'abkhazian'; + break; + case 'ae': + $lang_name = 'avestan'; + break; + case 'af': + $lang_name = 'afrikaans'; + break; + case 'ak': + $lang_name = 'akan'; + break; + case 'am': + $lang_name = 'amharic'; + break; + case 'an': + $lang_name = 'aragonese'; + break; + case 'ar': + $lang_name = 'arabic'; + break; + case 'as': + $lang_name = 'assamese'; + break; + case 'av': + $lang_name = 'avaric'; + break; + case 'ay': + $lang_name = 'aymara'; + break; + case 'az': + $lang_name = 'azerbaijani'; + break; + case 'ba': + $lang_name = 'bashkir'; + break; + case 'be': + $lang_name = 'belarusian'; + break; + case 'bg': + $lang_name = 'bulgarian'; + break; + case 'bh': + $lang_name = 'bihari'; + break; + case 'bi': + $lang_name = 'bislama'; + break; + case 'bm': + $lang_name = 'bambara'; + break; + case 'bn': + $lang_name = 'bengali'; + break; + case 'bo': + $lang_name = 'tibetan'; + break; + case 'br': + $lang_name = 'breton'; + break; + case 'bs': + $lang_name = 'bosnian'; + break; + case 'ca': + $lang_name = 'catalan'; + break; + case 'ce': + $lang_name = 'chechen'; + break; + case 'ch': + $lang_name = 'chamorro'; + break; + case 'co': + $lang_name = 'corsican'; + break; + case 'cr': + $lang_name = 'cree'; + break; + case 'cs': + $lang_name = 'czech'; + break; + case 'cu': + $lang_name = 'slavonic'; + break; + case 'cv': + $lang_name = 'chuvash'; + break; + case 'cy': + $lang_name = 'welsh_cymraeg'; + break; + case 'da': + $lang_name = 'danish'; + break; + case 'de': + $lang_name = 'german'; + break; + case 'dv': + $lang_name = 'divehi'; + break; + case 'dz': + $lang_name = 'dzongkha'; + break; + case 'ee': + $lang_name = 'ewe'; + break; + case 'el': + $lang_name = 'greek'; + break; + case 'he': + $lang_name = 'hebrew'; + break; + case 'en': + $lang_name = 'english'; + break; + case 'en_us': + $lang_name = 'english'; + break; + case 'eo': + $lang_name = 'esperanto'; + break; + case 'es': + $lang_name = 'spanish'; + break; + case 'et': + $lang_name = 'estonian'; + break; + case 'eu': + $lang_name = 'basque'; + break; + case 'fa': + $lang_name = 'persian'; + break; + case 'ff': + $lang_name = 'fulah'; + break; + case 'fi': + $lang_name = 'finnish'; + break; + case 'fj': + $lang_name = 'fijian'; + break; + case 'fo': + $lang_name = 'faroese'; + break; + case 'fr': + $lang_name = 'french'; + break; + case 'fy': + $lang_name = 'frisian'; + break; + case 'ga': + $lang_name = 'irish'; + break; + case 'gd': + $lang_name = 'scottish'; + break; + case 'gl': + $lang_name = 'galician'; + break; + case 'gn': + $lang_name = 'guaraní'; + break; + case 'gu': + $lang_name = 'gujarati'; + break; + case 'gv': + $lang_name = 'manx'; + break; + case 'ha': + $lang_name = 'hausa'; + break; + case 'he': + $lang_name = 'hebrew'; + break; + case 'hi': + $lang_name = 'hindi'; + break; + case 'ho': + $lang_name = 'hiri_motu'; + break; + case 'hr': + $lang_name = 'croatian'; + break; + case 'ht': + $lang_name = 'haitian'; + break; + case 'hu': + $lang_name = 'hungarian'; + break; + case 'hy': + $lang_name = 'armenian'; + break; + case 'hz': + $lang_name = 'herero'; + break; + case 'ia': + $lang_name = 'interlingua'; + break; + case 'id': + $lang_name = 'indonesian'; + break; + case 'ie': + $lang_name = 'interlingue'; + break; + case 'ig': + $lang_name = 'igbo'; + break; + case 'ii': + $lang_name = 'sichuan_yi'; + break; + case 'ik': + $lang_name = 'inupiaq'; + break; + case 'io': + $lang_name = 'ido'; + break; + case 'is': + $lang_name = 'icelandic'; + break; + case 'it': + $lang_name = 'italian'; + break; + case 'iu': + $lang_name = 'inuktitut'; + break; + case 'ja': + $lang_name = 'japanese'; + break; + case 'jv': + $lang_name = 'javanese'; + break; + case 'ka': + $lang_name = 'georgian'; + break; + case 'kg': + $lang_name = 'kongo'; + break; + case 'ki': + $lang_name = 'kikuyu'; + break; + case 'kj': + $lang_name = 'kwanyama'; + break; + case 'kk': + $lang_name = 'kazakh'; + break; + case 'kl': + $lang_name = 'kalaallisut'; + break; + case 'km': + $lang_name = 'khmer'; + break; + case 'kn': + $lang_name = 'kannada'; + break; + case 'ko': + $lang_name = 'korean'; + break; + case 'kr': + $lang_name = 'kanuri'; + break; + case 'ks': + $lang_name = 'kashmiri'; + break; + case 'ku': + $lang_name = 'kurdish'; + break; + case 'kv': + $lang_name = 'komi'; + break; + case 'kw': + $lang_name = 'cornish_kernewek'; + break; + case 'ky': + $lang_name = 'kirghiz'; + break; + case 'la': + $lang_name = 'latin'; + break; + case 'lb': + $lang_name = 'luxembourgish'; + break; + case 'lg': + $lang_name = 'ganda'; + break; + case 'li': + $lang_name = 'limburgish'; + break; + case 'ln': + $lang_name = 'lingala'; + break; + case 'lo': + $lang_name = 'lao'; + break; + case 'lt': + $lang_name = 'lithuanian'; + break; + case 'lu': + $lang_name = 'luba-katanga'; + break; + case 'lv': + $lang_name = 'latvian'; + break; + case 'mg': + $lang_name = 'malagasy'; + break; + case 'mh': + $lang_name = 'marshallese'; + break; + case 'mi': + $lang_name = 'maori'; + break; + case 'mk': + $lang_name = 'macedonian'; + break; + case 'ml': + $lang_name = 'malayalam'; + break; + case 'mn': + $lang_name = 'mongolian'; + break; + case 'mo': + $lang_name = 'moldavian'; + break; + case 'mr': + $lang_name = 'marathi'; + break; + case 'ms': + $lang_name = 'malay'; + break; + case 'mt': + $lang_name = 'maltese'; + break; + case 'my': + $lang_name = 'burmese'; + break; + case 'na': + $lang_name = 'nauruan'; + break; + case 'nb': + $lang_name = 'norwegian'; + break; + case 'nd': + $lang_name = 'ndebele'; + break; + case 'ne': + $lang_name = 'nepali'; + break; + case 'ng': + $lang_name = 'ndonga'; + break; + case 'nl': + $lang_name = 'dutch'; + break; + case 'nn': + $lang_name = 'norwegian_nynorsk'; + break; + case 'no': + $lang_name = 'norwegian'; + break; + case 'nr': + $lang_name = 'southern_ndebele'; + break; + case 'nv': + $lang_name = 'navajo'; + break; + case 'ny': + $lang_name = 'chichewa'; + break; + case 'oc': + $lang_name = 'occitan'; + break; + case 'oj': + $lang_name = 'ojibwa'; + break; + case 'om': + $lang_name = 'oromo'; + break; + case 'or': + $lang_name = 'oriya'; + break; + case 'os': + $lang_name = 'ossetian'; + break; + case 'pa': + $lang_name = 'panjabi'; + break; + case 'pi': + $lang_name = 'pali'; + break; + case 'pl': + $lang_name = 'polish'; + break; + case 'ps': + $lang_name = 'pashto'; + break; + case 'pt': + $lang_name = 'portuguese'; + break; + case 'pt_br': + $lang_name = 'portuguese_brasil'; + break; + case 'qu': + $lang_name = 'quechua'; + break; + case 'rm': + $lang_name = 'romansh'; + break; + case 'rn': + $lang_name = 'kirundi'; + break; + case 'ro': + $lang_name = 'romanian'; + break; + case 'ru': + $lang_name = 'russian'; + break; + case 'rw': + $lang_name = 'kinyarwanda'; + break; + case 'sa': + $lang_name = 'sanskrit'; + break; + case 'sc': + $lang_name = 'sardinian'; + break; + case 'sd': + $lang_name = 'sindhi'; + break; + case 'se': + $lang_name = 'northern_sami'; + break; + case 'sg': + $lang_name = 'sango'; + break; + case 'sh': + $lang_name = 'serbo-croatian'; + break; + case 'si': + $lang_name = 'sinhala'; + break; + case 'sk': + $lang_name = 'slovak'; + break; + case 'sl': + $lang_name = 'slovenian'; + break; + case 'sm': + $lang_name = 'samoan'; + break; + case 'sn': + $lang_name = 'shona'; + break; + case 'so': + $lang_name = 'somali'; + break; + case 'sq': + $lang_name = 'albanian'; + break; + case 'sr': + $lang_name = 'serbian'; + break; + case 'ss': + $lang_name = 'swati'; + break; + case 'st': + $lang_name = 'sotho'; + break; + case 'su': + $lang_name = 'sundanese'; + break; + case 'sv': + $lang_name = 'swedish'; + break; + case 'sw': + $lang_name = 'swahili'; + break; + case 'ta': + $lang_name = 'tamil'; + break; + case 'te': + $lang_name = 'telugu'; + break; + case 'tg': + $lang_name = 'tajik'; + break; + case 'th': + $lang_name = 'thai'; + break; + case 'ti': + $lang_name = 'tigrinya'; + break; + case 'tk': + $lang_name = 'turkmen'; + break; + case 'tl': + $lang_name = 'tagalog'; + break; + case 'tn': + $lang_name = 'tswana'; + break; + case 'to': + $lang_name = 'tonga'; + break; + case 'tr': + $lang_name = 'turkish'; + break; + case 'ts': + $lang_name = 'tsonga'; + break; + case 'tt': + $lang_name = 'tatar'; + break; + case 'tw': + $lang_name = 'twi'; + break; + case 'ty': + $lang_name = 'tahitian'; + break; + case 'ug': + $lang_name = 'uighur'; + break; + case 'uk': + $lang_name = 'ukrainian'; + break; + case 'ur': + $lang_name = 'urdu'; + break; + case 'uz': + $lang_name = 'uzbek'; + break; + case 've': + $lang_name = 'venda'; + break; + case 'vi': + $lang_name = 'vietnamese'; + break; + case 'vo': + $lang_name = 'volapuk'; + break; + case 'wa': + $lang_name = 'walloon'; + break; + case 'wo': + $lang_name = 'wolof'; + break; + case 'xh': + $lang_name = 'xhosa'; + break; + case 'yi': + $lang_name = 'yiddish'; + break; + case 'yo': + $lang_name = 'yoruba'; + break; + case 'za': + $lang_name = 'zhuang'; + break; + case 'zh': + $lang_name = 'chinese'; + break; + case 'zh_cmn_hans': + $lang_name = 'chinese_simplified'; + break; + case 'zh_cmn_hant': + $lang_name = 'chinese_traditional'; + break; + case 'zu': + $lang_name = 'zulu'; + break; + default: + $lang_name = $lang; + break; + } + return $lang_name; + } +} +?> \ No newline at end of file diff --git a/includes/sessions/rhea/CVS/Entries b/includes/sessions/rhea/CVS/Entries new file mode 100644 index 00000000..17848105 --- /dev/null +++ b/includes/sessions/rhea/CVS/Entries @@ -0,0 +1 @@ +D diff --git a/includes/sessions/rhea/CVS/Entries.Extra b/includes/sessions/rhea/CVS/Entries.Extra new file mode 100644 index 00000000..e69de29b diff --git a/includes/sessions/rhea/CVS/Entries.Extra.Old b/includes/sessions/rhea/CVS/Entries.Extra.Old new file mode 100644 index 00000000..e69de29b diff --git a/includes/sessions/rhea/CVS/Entries.Old b/includes/sessions/rhea/CVS/Entries.Old new file mode 100644 index 00000000..e69de29b diff --git a/includes/sessions/rhea/CVS/Repository b/includes/sessions/rhea/CVS/Repository new file mode 100644 index 00000000..990aebee --- /dev/null +++ b/includes/sessions/rhea/CVS/Repository @@ -0,0 +1 @@ +core/includes/sessions/rhea diff --git a/includes/sessions/rhea/CVS/Root b/includes/sessions/rhea/CVS/Root new file mode 100644 index 00000000..6ab1483d --- /dev/null +++ b/includes/sessions/rhea/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@mxbb.cvs.sourceforge.net:/cvsroot/mxbb diff --git a/includes/sessions/rhea/auth.php b/includes/sessions/rhea/auth.php new file mode 100644 index 00000000..c18e3d20 --- /dev/null +++ b/includes/sessions/rhea/auth.php @@ -0,0 +1,998 @@ +acl = $this->cache = $this->acl_options = array(); + $this->acl_forum_ids = false; + + if (($this->acl_options = $mx_cache->get('_acl_options')) === false) + { + $sql = 'SELECT auth_option_id, auth_option, is_global, is_local + FROM ' . ACL_OPTIONS_TABLE . ' + ORDER BY auth_option_id'; + $result = $db->sql_query($sql); + + $global = $local = 0; + $this->acl_options = array(); + while ($row = $db->sql_fetchrow($result)) + { + if ($row['is_global']) + { + $this->acl_options['global'][$row['auth_option']] = $global++; + } + + if ($row['is_local']) + { + $this->acl_options['local'][$row['auth_option']] = $local++; + } + $this->acl_options['id'][$row['auth_option']] = (int) $row['auth_option_id']; + $this->acl_options['option'][(int) $row['auth_option_id']] = $row['auth_option']; + } + $db->sql_freeresult($result); + + $mx_cache->put('_acl_options', $this->acl_options); + $this->acl_cache($userdata); + } + else if (!trim($userdata['user_permissions'])) + { + $this->acl_cache($userdata); + } + + $user_permissions = explode("\n", $userdata['user_permissions']); + + foreach ($user_permissions as $f => $seq) + { + if ($seq) + { + $i = 0; + + if (!isset($this->acl[$f])) + { + $this->acl[$f] = ''; + } + + while ($subseq = substr($seq, $i, 6)) + { + // We put the original bitstring into the acl array + $this->acl[$f] .= str_pad(base_convert($subseq, 36, 2), 31, 0, STR_PAD_LEFT); + $i += 6; + } + } + } + + return; + } + + /** + * Look up an option + * if the option is prefixed with !, then the result becomes negated + * + * If a forum id is specified the local option will be combined with a global option if one exist. + * If a forum id is not specified, only the global option will be checked. + */ + function acl_get($opt, $f = 0) + { + $negate = false; + + if (strpos($opt, '!') === 0) + { + $negate = true; + $opt = substr($opt, 1); + } + + if (!isset($this->cache[$f][$opt])) + { + // We combine the global/local option with an OR because some options are global and local. + // If the user has the global permission the local one is true too and vice versa + $this->cache[$f][$opt] = false; + + // Is this option a global permission setting? + if (isset($this->acl_options['global'][$opt])) + { + if (isset($this->acl[0])) + { + $this->cache[$f][$opt] = $this->acl[0][$this->acl_options['global'][$opt]]; + } + } + + // Is this option a local permission setting? + // But if we check for a global option only, we won't combine the options... + if ($f != 0 && isset($this->acl_options['local'][$opt])) + { + if (isset($this->acl[$f]) && isset($this->acl[$f][$this->acl_options['local'][$opt]])) + { + $this->cache[$f][$opt] |= $this->acl[$f][$this->acl_options['local'][$opt]]; + } + } + } + + // Founder always has all global options set to true... + return ($negate) ? !$this->cache[$f][$opt] : $this->cache[$f][$opt]; + } + + /** + * Get forums with the specified permission setting + * if the option is prefixed with !, then the result becomes nagated + * + * @param bool $clean set to true if only values needs to be returned which are set/unset + */ + function acl_getf($opt, $clean = false) + { + $acl_f = array(); + $negate = false; + + if (strpos($opt, '!') === 0) + { + $negate = true; + $opt = substr($opt, 1); + } + + // If we retrieve a list of forums not having permissions in, we need to get every forum_id + if ($negate) + { + if ($this->acl_forum_ids === false) + { + global $db; + + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE; + + if (sizeof($this->acl)) + { + $sql .= ' WHERE ' . $db->sql_in_set('forum_id', array_keys($this->acl), true); + } + $result = $db->sql_query($sql); + + $this->acl_forum_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $this->acl_forum_ids[] = $row['forum_id']; + } + $db->sql_freeresult($result); + } + } + + if (isset($this->acl_options['local'][$opt])) + { + foreach ($this->acl as $f => $bitstring) + { + // Skip global settings + if (!$f) + { + continue; + } + + $allowed = (!isset($this->cache[$f][$opt])) ? $this->acl_get($opt, $f) : $this->cache[$f][$opt]; + + if (!$clean) + { + $acl_f[$f][$opt] = ($negate) ? !$allowed : $allowed; + } + else + { + if (($negate && !$allowed) || (!$negate && $allowed)) + { + $acl_f[$f][$opt] = 1; + } + } + } + } + + // If we get forum_ids not having this permission, we need to fill the remaining parts + if ($negate && sizeof($this->acl_forum_ids)) + { + foreach ($this->acl_forum_ids as $f) + { + $acl_f[$f][$opt] = 1; + } + } + + return $acl_f; + } + + /** + * Get local permission state for any forum. + * + * Returns true if user has the permission in one or more forums, false if in no forum. + * If global option is checked it returns the global state (same as acl_get($opt)) + * Local option has precedence... + */ + function acl_getf_global($opt) + { + if (is_array($opt)) + { + // evaluates to true as soon as acl_getf_global is true for one option + foreach ($opt as $check_option) + { + if ($this->acl_getf_global($check_option)) + { + return true; + } + } + + return false; + } + + if (isset($this->acl_options['local'][$opt])) + { + foreach ($this->acl as $f => $bitstring) + { + // Skip global settings + if (!$f) + { + continue; + } + + // as soon as the user has any permission we're done so return true + if ((!isset($this->cache[$f][$opt])) ? $this->acl_get($opt, $f) : $this->cache[$f][$opt]) + { + return true; + } + } + } + else if (isset($this->acl_options['global'][$opt])) + { + return $this->acl_get($opt); + } + + return false; + } + + /** + * Get permission settings (more than one) + */ + function acl_gets() + { + $args = func_get_args(); + $f = array_pop($args); + + if (!is_numeric($f)) + { + $args[] = $f; + $f = 0; + } + + // alternate syntax: acl_gets(array('m_', 'a_'), $forum_id) + if (is_array($args[0])) + { + $args = $args[0]; + } + + $acl = 0; + foreach ($args as $opt) + { + $acl |= $this->acl_get($opt, $f); + } + + return $acl; + } + + /** + * Get permission listing based on user_id/options/forum_ids + */ + function acl_get_list($user_id = false, $opts = false, $forum_id = false) + { + if ($user_id !== false && !is_array($user_id) && $opts === false && $forum_id === false) + { + $hold_ary = array($user_id => $this->acl_raw_data_single_user($user_id)); + } + else + { + $hold_ary = $this->acl_raw_data($user_id, $opts, $forum_id); + } + + $auth_ary = array(); + foreach ($hold_ary as $user_id => $forum_ary) + { + foreach ($forum_ary as $forum_id => $auth_option_ary) + { + foreach ($auth_option_ary as $auth_option => $auth_setting) + { + if ($auth_setting) + { + $auth_ary[$forum_id][$auth_option][] = $user_id; + } + } + } + } + + return $auth_ary; + } + + /** + * Cache data to user_permissions row + */ + function acl_cache(&$userdata) + { + global $db; + + // Empty user_permissions + $userdata['user_permissions'] = ''; + + $hold_ary = $this->acl_raw_data_single_user($userdata['user_id']); + + // Key 0 in $hold_ary are global options, all others are forum_ids + + // If this user is founder we're going to force fill the admin options ... + if ($userdata['user_type'] == USER_FOUNDER) + { + foreach ($this->acl_options['global'] as $opt => $id) + { + if (strpos($opt, 'a_') === 0) + { + $hold_ary[0][$this->acl_options['id'][$opt]] = ACL_YES; + } + } + } + + $hold_str = $this->build_bitstring($hold_ary); + + if ($hold_str) + { + $userdata['user_permissions'] = $hold_str; + + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_permissions = '" . $db->sql_escape($userdata['user_permissions']) . "', + user_perm_from = 0 + WHERE user_id = " . $userdata['user_id']; + $db->sql_query($sql); + } + + return; + } + + /** + * Build bitstring from permission set + */ + function build_bitstring(&$hold_ary) + { + $hold_str = ''; + + if (sizeof($hold_ary)) + { + ksort($hold_ary); + + $last_f = 0; + + foreach ($hold_ary as $f => $auth_ary) + { + $ary_key = (!$f) ? 'global' : 'local'; + + $bitstring = array(); + foreach ($this->acl_options[$ary_key] as $opt => $id) + { + if (isset($auth_ary[$this->acl_options['id'][$opt]])) + { + $bitstring[$id] = $auth_ary[$this->acl_options['id'][$opt]]; + + $option_key = substr($opt, 0, strpos($opt, '_') + 1); + + // If one option is allowed, the global permission for this option has to be allowed too + // example: if the user has the a_ permission this means he has one or more a_* permissions + if ($auth_ary[$this->acl_options['id'][$opt]] == ACL_YES && (!isset($bitstring[$this->acl_options[$ary_key][$option_key]]) || $bitstring[$this->acl_options[$ary_key][$option_key]] == ACL_NEVER)) + { + $bitstring[$this->acl_options[$ary_key][$option_key]] = ACL_YES; + } + } + else + { + $bitstring[$id] = ACL_NEVER; + } + } + + // Now this bitstring defines the permission setting for the current forum $f (or global setting) + $bitstring = implode('', $bitstring); + + // The line number indicates the id, therefore we have to add empty lines for those ids not present + $hold_str .= str_repeat("\n", $f - $last_f); + + // Convert bitstring for storage - we do not use binary/bytes because PHP's string functions are not fully binary safe + for ($i = 0, $bit_length = strlen($bitstring); $i < $bit_length; $i += 31) + { + $hold_str .= str_pad(base_convert(str_pad(substr($bitstring, $i, 31), 31, 0, STR_PAD_RIGHT), 2, 36), 6, 0, STR_PAD_LEFT); + } + + $last_f = $f; + } + unset($bitstring); + + $hold_str = rtrim($hold_str); + } + + return $hold_str; + } + + /** + * Clear one or all users cached permission settings + */ + function acl_clear_prefetch($user_id = false) + { + global $db, $mx_cache; + + // Rebuild options cache + $mx_cache->destroy('_role_cache'); + + $sql = 'SELECT * + FROM ' . ACL_ROLES_DATA_TABLE . ' + ORDER BY role_id ASC'; + $result = $db->sql_query($sql); + + $this->role_cache = array(); + while ($row = $db->sql_fetchrow($result)) + { + $this->role_cache[$row['role_id']][$row['auth_option_id']] = (int) $row['auth_setting']; + } + $db->sql_freeresult($result); + + foreach ($this->role_cache as $role_id => $role_options) + { + $this->role_cache[$role_id] = serialize($role_options); + } + + $mx_cache->put('_role_cache', $this->role_cache); + + // Now empty user permissions + + $where_sql = ''; + + if ($user_id !== false) + { + $user_id = (!is_array($user_id)) ? $user_id = array((int) $user_id) : array_map('intval', $user_id); + $where_sql = ' WHERE ' . $db->sql_in_set('user_id', $user_id); + } + + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_permissions = '', + user_perm_from = 0 + $where_sql"; + $db->sql_query($sql); + + return; + } + + /** + * Get assigned roles + */ + function acl_role_data($user_type, $role_type, $ug_id = false, $forum_id = false) + { + global $db; + + $roles = array(); + + $sql_id = ($user_type == 'user') ? 'user_id' : 'group_id'; + + $sql_ug = ($ug_id !== false) ? ((!is_array($ug_id)) ? "AND a.$sql_id = $ug_id" : 'AND ' . $db->sql_in_set("a.$sql_id", $ug_id)) : ''; + $sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? "AND a.forum_id = $forum_id" : 'AND ' . $db->sql_in_set('a.forum_id', $forum_id)) : ''; + + // Grab assigned roles... + $sql = 'SELECT a.auth_role_id, a.' . $sql_id . ', a.forum_id + FROM ' . (($user_type == 'user') ? ACL_USERS_TABLE : ACL_GROUPS_TABLE) . ' a, ' . ACL_ROLES_TABLE . " r + WHERE a.auth_role_id = r.role_id + AND r.role_type = '" . $db->sql_escape($role_type) . "' + $sql_ug + $sql_forum + ORDER BY r.role_order ASC"; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $roles[$row[$sql_id]][$row['forum_id']] = $row['auth_role_id']; + } + $db->sql_freeresult($result); + + return $roles; + } + + /** + * Get raw acl data based on user/option/forum + */ + function acl_raw_data($user_id = false, $opts = false, $forum_id = false) + { + global $db; + + $sql_user = ($user_id !== false) ? ((!is_array($user_id)) ? 'user_id = ' . (int) $user_id : $db->sql_in_set('user_id', array_map('intval', $user_id))) : ''; + $sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? 'AND a.forum_id = ' . (int) $forum_id : 'AND ' . $db->sql_in_set('a.forum_id', array_map('intval', $forum_id))) : ''; + + $sql_opts = $sql_opts_select = $sql_opts_from = ''; + $hold_ary = array(); + + if ($opts !== false) + { + $sql_opts_select = ', ao.auth_option'; + $sql_opts_from = ', ' . ACL_OPTIONS_TABLE . ' ao'; + $this->build_auth_option_statement('ao.auth_option', $opts, $sql_opts); + } + + $sql_ary = array(); + + // Grab non-role settings - user-specific + $sql_ary[] = 'SELECT a.user_id, a.forum_id, a.auth_setting, a.auth_option_id' . $sql_opts_select . ' + FROM ' . ACL_USERS_TABLE . ' a' . $sql_opts_from . ' + WHERE a.auth_role_id = 0 ' . + (($sql_opts_from) ? 'AND a.auth_option_id = ao.auth_option_id ' : '') . + (($sql_user) ? 'AND a.' . $sql_user : '') . " + $sql_forum + $sql_opts"; + + // Now the role settings - user-specific + $sql_ary[] = 'SELECT a.user_id, a.forum_id, r.auth_option_id, r.auth_setting, r.auth_option_id' . $sql_opts_select . ' + FROM ' . ACL_USERS_TABLE . ' a, ' . ACL_ROLES_DATA_TABLE . ' r' . $sql_opts_from . ' + WHERE a.auth_role_id = r.role_id ' . + (($sql_opts_from) ? 'AND r.auth_option_id = ao.auth_option_id ' : '') . + (($sql_user) ? 'AND a.' . $sql_user : '') . " + $sql_forum + $sql_opts"; + + foreach ($sql_ary as $sql) + { + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $option = ($sql_opts_select) ? $row['auth_option'] : $this->acl_options['option'][$row['auth_option_id']]; + $hold_ary[$row['user_id']][$row['forum_id']][$option] = $row['auth_setting']; + } + $db->sql_freeresult($result); + } + + $sql_ary = array(); + + // Now grab group settings - non-role specific... + $sql_ary[] = 'SELECT ug.user_id, a.forum_id, a.auth_setting, a.auth_option_id' . $sql_opts_select . ' + FROM ' . ACL_GROUPS_TABLE . ' a, ' . USER_GROUP_TABLE . ' ug' . $sql_opts_from . ' + WHERE a.auth_role_id = 0 ' . + (($sql_opts_from) ? 'AND a.auth_option_id = ao.auth_option_id ' : '') . ' + AND a.group_id = ug.group_id + AND ug.user_pending = 0 + ' . (($sql_user) ? 'AND ug.' . $sql_user : '') . " + $sql_forum + $sql_opts"; + + // Now grab group settings - role specific... + $sql_ary[] = 'SELECT ug.user_id, a.forum_id, r.auth_setting, r.auth_option_id' . $sql_opts_select . ' + FROM ' . ACL_GROUPS_TABLE . ' a, ' . USER_GROUP_TABLE . ' ug, ' . ACL_ROLES_DATA_TABLE . ' r' . $sql_opts_from . ' + WHERE a.auth_role_id = r.role_id ' . + (($sql_opts_from) ? 'AND r.auth_option_id = ao.auth_option_id ' : '') . ' + AND a.group_id = ug.group_id + AND ug.user_pending = 0 + ' . (($sql_user) ? 'AND ug.' . $sql_user : '') . " + $sql_forum + $sql_opts"; + + foreach ($sql_ary as $sql) + { + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $option = ($sql_opts_select) ? $row['auth_option'] : $this->acl_options['option'][$row['auth_option_id']]; + + if (!isset($hold_ary[$row['user_id']][$row['forum_id']][$option]) || (isset($hold_ary[$row['user_id']][$row['forum_id']][$option]) && $hold_ary[$row['user_id']][$row['forum_id']][$option] != ACL_NEVER)) + { + $hold_ary[$row['user_id']][$row['forum_id']][$option] = $row['auth_setting']; + + // If we detect ACL_NEVER, we will unset the flag option (within building the bitstring it is correctly set again) + if ($row['auth_setting'] == ACL_NEVER) + { + $flag = substr($option, 0, strpos($option, '_') + 1); + + if (isset($hold_ary[$row['user_id']][$row['forum_id']][$flag]) && $hold_ary[$row['user_id']][$row['forum_id']][$flag] == ACL_YES) + { + unset($hold_ary[$row['user_id']][$row['forum_id']][$flag]); + +/* if (in_array(ACL_YES, $hold_ary[$row['user_id']][$row['forum_id']])) + { + $hold_ary[$row['user_id']][$row['forum_id']][$flag] = ACL_YES; + } +*/ + } + } + } + } + $db->sql_freeresult($result); + } + + return $hold_ary; + } + + /** + * Get raw user based permission settings + */ + function acl_user_raw_data($user_id = false, $opts = false, $forum_id = false) + { + global $db; + + $sql_user = ($user_id !== false) ? ((!is_array($user_id)) ? 'user_id = ' . (int) $user_id : $db->sql_in_set('user_id', array_map('intval', $user_id))) : ''; + $sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? 'AND a.forum_id = ' . (int) $forum_id : 'AND ' . $db->sql_in_set('a.forum_id', array_map('intval', $forum_id))) : ''; + + $sql_opts = ''; + $hold_ary = $sql_ary = array(); + + if ($opts !== false) + { + $this->build_auth_option_statement('ao.auth_option', $opts, $sql_opts); + } + + // Grab user settings - non-role specific... + $sql_ary[] = 'SELECT a.user_id, a.forum_id, a.auth_setting, a.auth_option_id, ao.auth_option + FROM ' . ACL_USERS_TABLE . ' a, ' . ACL_OPTIONS_TABLE . ' ao + WHERE a.auth_role_id = 0 + AND a.auth_option_id = ao.auth_option_id ' . + (($sql_user) ? 'AND a.' . $sql_user : '') . " + $sql_forum + $sql_opts + ORDER BY a.forum_id, ao.auth_option"; + + // Now the role settings - user-specific + $sql_ary[] = 'SELECT a.user_id, a.forum_id, r.auth_option_id, r.auth_setting, r.auth_option_id, ao.auth_option + FROM ' . ACL_USERS_TABLE . ' a, ' . ACL_ROLES_DATA_TABLE . ' r, ' . ACL_OPTIONS_TABLE . ' ao + WHERE a.auth_role_id = r.role_id + AND r.auth_option_id = ao.auth_option_id ' . + (($sql_user) ? 'AND a.' . $sql_user : '') . " + $sql_forum + $sql_opts + ORDER BY a.forum_id, ao.auth_option"; + + foreach ($sql_ary as $sql) + { + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $hold_ary[$row['user_id']][$row['forum_id']][$row['auth_option']] = $row['auth_setting']; + } + $db->sql_freeresult($result); + } + return $hold_ary; + } + + /** + * Get raw group based permission settings + */ + function acl_group_raw_data($group_id = false, $opts = false, $forum_id = false) + { + global $db; + + $sql_group = ($group_id !== false) ? ((!is_array($group_id)) ? 'group_id = ' . (int) $group_id : $db->sql_in_set('group_id', array_map('intval', $group_id))) : ''; + $sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? 'AND a.forum_id = ' . (int) $forum_id : 'AND ' . $db->sql_in_set('a.forum_id', array_map('intval', $forum_id))) : ''; + + $sql_opts = ''; + $hold_ary = $sql_ary = array(); + + if ($opts !== false) + { + $this->build_auth_option_statement('ao.auth_option', $opts, $sql_opts); + } + + // Grab group settings - non-role specific... + $sql_ary[] = 'SELECT a.group_id, a.forum_id, a.auth_setting, a.auth_option_id, ao.auth_option + FROM ' . ACL_GROUPS_TABLE . ' a, ' . ACL_OPTIONS_TABLE . ' ao + WHERE a.auth_role_id = 0 + AND a.auth_option_id = ao.auth_option_id ' . + (($sql_group) ? 'AND a.' . $sql_group : '') . " + $sql_forum + $sql_opts + ORDER BY a.forum_id, ao.auth_option"; + + // Now grab group settings - role specific... + $sql_ary[] = 'SELECT a.group_id, a.forum_id, r.auth_setting, r.auth_option_id, ao.auth_option + FROM ' . ACL_GROUPS_TABLE . ' a, ' . ACL_ROLES_DATA_TABLE . ' r, ' . ACL_OPTIONS_TABLE . ' ao + WHERE a.auth_role_id = r.role_id + AND r.auth_option_id = ao.auth_option_id ' . + (($sql_group) ? 'AND a.' . $sql_group : '') . " + $sql_forum + $sql_opts + ORDER BY a.forum_id, ao.auth_option"; + + foreach ($sql_ary as $sql) + { + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $hold_ary[$row['group_id']][$row['forum_id']][$row['auth_option']] = $row['auth_setting']; + } + $db->sql_freeresult($result); + } + + return $hold_ary; + } + + /** + * Get raw acl data based on user for caching user_permissions + * This function returns the same data as acl_raw_data(), but without the user id as the first key within the array. + */ + function acl_raw_data_single_user($user_id) + { + global $db, $mx_cache; + + // Check if the role-cache is there + if (($this->role_cache = $mx_cache->get('_role_cache')) === false) + { + $this->role_cache = array(); + + // We pre-fetch roles + $sql = 'SELECT * + FROM ' . ACL_ROLES_DATA_TABLE . ' + ORDER BY role_id ASC'; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $this->role_cache[$row['role_id']][$row['auth_option_id']] = (int) $row['auth_setting']; + } + $db->sql_freeresult($result); + + foreach ($this->role_cache as $role_id => $role_options) + { + $this->role_cache[$role_id] = serialize($role_options); + } + + $mx_cache->put('_role_cache', $this->role_cache); + } + + $hold_ary = array(); + + // Grab user-specific permission settings + $sql = 'SELECT forum_id, auth_option_id, auth_role_id, auth_setting + FROM ' . ACL_USERS_TABLE . ' + WHERE user_id = ' . $user_id; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + // If a role is assigned, assign all options included within this role. Else, only set this one option. + if ($row['auth_role_id']) + { + $hold_ary[$row['forum_id']] = (empty($hold_ary[$row['forum_id']])) ? unserialize($this->role_cache[$row['auth_role_id']]) : $hold_ary[$row['forum_id']] + unserialize($this->role_cache[$row['auth_role_id']]); + } + else + { + $hold_ary[$row['forum_id']][$row['auth_option_id']] = $row['auth_setting']; + } + } + $db->sql_freeresult($result); + + // Now grab group-specific permission settings + $sql = 'SELECT a.forum_id, a.auth_option_id, a.auth_role_id, a.auth_setting + FROM ' . ACL_GROUPS_TABLE . ' a, ' . USER_GROUP_TABLE . ' ug + WHERE a.group_id = ug.group_id + AND ug.user_pending = 0 + AND ug.user_id = ' . $user_id; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + if (!$row['auth_role_id']) + { + $this->_set_group_hold_ary($hold_ary[$row['forum_id']], $row['auth_option_id'], $row['auth_setting']); + } + else + { + foreach (unserialize($this->role_cache[$row['auth_role_id']]) as $option_id => $setting) + { + $this->_set_group_hold_ary($hold_ary[$row['forum_id']], $option_id, $setting); + } + } + } + $db->sql_freeresult($result); + + return $hold_ary; + } + + /** + * Private function snippet for setting a specific piece of the hold_ary + */ + function _set_group_hold_ary(&$hold_ary, $option_id, $setting) + { + if (!isset($hold_ary[$option_id]) || (isset($hold_ary[$option_id]) && $hold_ary[$option_id] != ACL_NEVER)) + { + $hold_ary[$option_id] = $setting; + + // If we detect ACL_NEVER, we will unset the flag option (within building the bitstring it is correctly set again) + if ($setting == ACL_NEVER) + { + $flag = substr($this->acl_options['option'][$option_id], 0, strpos($this->acl_options['option'][$option_id], '_') + 1); + $flag = (int) $this->acl_options['id'][$flag]; + + if (isset($hold_ary[$flag]) && $hold_ary[$flag] == ACL_YES) + { + unset($hold_ary[$flag]); + +/* This is uncommented, because i suspect this being slightly wrong due to mixed permission classes being possible + if (in_array(ACL_YES, $hold_ary)) + { + $hold_ary[$flag] = ACL_YES; + }*/ + } + } + } + } + + /** + * Authentication plug-ins is largely down to Sergey Kanareykin, our thanks to him. + */ + function login($username, $password, $autologin = false, $viewonline = 1, $admin = 0) + { + global $board_config, $db, $mx_user, $phpbb_root_path, $phpEx; + + $method = trim(basename($board_config['auth_method'])); + include_once($mx_root_path . 'includes/auth/auth_' . $method . '.' . $phpEx); + //$provider = $phpbb_container->get('auth.provider.' . $method); + $method = 'login_' . $method; + if (function_exists($method)) + { + $login = $method($username, $password); + + // If the auth module wants us to create an empty profile do so and then treat the status as LOGIN_SUCCESS + if ($login['status'] == LOGIN_SUCCESS_CREATE_PROFILE) + { + // we are going to use the user_add function so include functions_user.php if it wasn't defined yet + if (!function_exists('user_add')) + { + include($phpbb_root_path . 'includes/functions_user.' . $phpEx); + } + + user_add($login['user_row'], (isset($login['cp_data'])) ? $login['cp_data'] : false); + + $sql = 'SELECT user_id, username, user_password, user_passchg, user_email, user_type + FROM ' . USERS_TABLE . " + WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'"; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if (!$row) + { + return array( + 'status' => LOGIN_ERROR_EXTERNAL_AUTH, + 'error_msg' => 'AUTH_NO_PROFILE_CREATED', + 'user_row' => array('user_id' => ANONYMOUS), + ); + } + + $login = array( + 'status' => LOGIN_SUCCESS, + 'error_msg' => false, + 'user_row' => $row, + ); + } + + // If login succeeded, we will log the user in... else we pass the login array through... + if ($login['status'] == LOGIN_SUCCESS) + { + $old_session_id = $mx_user->session_id; + + if ($admin) + { + global $SID, $_SID; + + $cookie_expire = time() - 31536000; + $mx_user->set_cookie('u', '', $cookie_expire); + $mx_user->set_cookie('sid', '', $cookie_expire); + unset($cookie_expire); + + $SID = '?sid='; + $mx_user->session_id = $_SID = ''; + } + + $result = $mx_user->session_create($login['user_row']['user_id'], $admin, $autologin, $viewonline); + + // Successful session creation + if ($result === true) + { + // If admin re-authentication we remove the old session entry because a new one has been created... + if ($admin) + { + // the login array is used because the user ids do not differ for re-authentication + $sql = 'DELETE FROM ' . SESSIONS_TABLE . " + WHERE session_id = '" . $db->sql_escape($old_session_id) . "' + AND session_user_id = {$login['user_row']['user_id']}"; + $db->sql_query($sql); + } + + return array( + 'status' => LOGIN_SUCCESS, + 'error_msg' => false, + 'user_row' => $login['user_row'], + ); + } + + return array( + 'status' => LOGIN_BREAK, + 'error_msg' => $result, + 'user_row' => $login['user_row'], + ); + } + + return $login; + } + + trigger_error('Authentication method not found', E_USER_ERROR); + } + + /** + * Fill auth_option statement for later querying based on the supplied options + */ + function build_auth_option_statement($key, $auth_options, &$sql_opts) + { + global $db; + + if (!is_array($auth_options)) + { + if (strpos($auth_options, '%') !== false) + { + $sql_opts = "AND $key " . $db->sql_like_expression(str_replace('%', $db->any_char, $auth_options)); + } + else + { + $sql_opts = "AND $key = '" . $db->sql_escape($auth_options) . "'"; + } + } + else + { + $is_like_expression = false; + + foreach ($auth_options as $option) + { + if (strpos($option, '%') !== false) + { + $is_like_expression = true; + } + } + + if (!$is_like_expression) + { + $sql_opts = 'AND ' . $db->sql_in_set($key, $auth_options); + } + else + { + $sql = array(); + + foreach ($auth_options as $option) + { + if (strpos($option, '%') !== false) + { + $sql[] = $key . ' ' . $db->sql_like_expression(str_replace('%', $db->any_char, $option)); + } + else + { + $sql[] = $key . " = '" . $db->sql_escape($option) . "'"; + } + } + + $sql_opts = 'AND (' . implode(' OR ', $sql) . ')'; + } + } + } +} +?> \ No newline at end of file diff --git a/includes/sessions/rhea/bbcode.php b/includes/sessions/rhea/bbcode.php new file mode 100644 index 00000000..b3a777da --- /dev/null +++ b/includes/sessions/rhea/bbcode.php @@ -0,0 +1,2079 @@ +bbcode_bitfield = $bitfield; + $this->bbcode_cache_init(); + } + + $this->smiley_path_url = PHPBB_URL; //change this to PORTAL_URL when shared folder will be removed + $this->smiley_root_path = $phpbb_root_path; //same here + $board_config['smilies_path'] = str_replace("smiles", "smilies", $board_config['smilies_path']); + $this->smilies_path = str_replace("//", "/", $board_config['smilies_path']); + } + + /** + * Second pass bbcodes + */ + function bbcode_second_pass(&$message, $bbcode_uid = '', $bbcode_bitfield = false) + { + if ($bbcode_uid) + { + $this->bbcode_uid = $bbcode_uid; + } + + if ($bbcode_bitfield !== false) + { + //$this->bbcode_bitfield = $bbcode_bitfield; + + // Init those added with a new bbcode_bitfield (already stored codes will not get parsed again) + $this->bbcode_cache_init(); + } + + //We are called from a Core block or non phpBB3, this should never be riched only when function is called direct + if (!$this->bbcode_bitfield) + { + // Remove the uid from tags that have not been transformed into HTML + /* + if ($this->bbcode_uid) + { + $message = str_replace(':' . $this->bbcode_uid, '', $message); + } + */ + return; + } + + $str = array('search' => array(), 'replace' => array()); + $preg = array('search' => array(), 'replace' => array()); + + $bitfield = new bitfield($this->bbcode_bitfield); + $bbcodes_set = $bitfield->get_all_set(); + + $undid_bbcode_specialchars = false; + foreach ($bbcodes_set as $bbcode_id) + { + if (!empty($this->bbcode_cache[$bbcode_id])) + { + foreach ($this->bbcode_cache[$bbcode_id] as $type => $array) + { + foreach ($array as $search => $replace) + { + ${$type}['search'][] = str_replace('$uid', $this->bbcode_uid, $search); + ${$type}['replace'][] = $replace; + } + + if (sizeof($str['search'])) + { + $message = str_replace($str['search'], $str['replace'], $message); + $str = array('search' => array(), 'replace' => array()); + } + + if (sizeof($preg['search'])) + { + // we need to turn the entities back into their original form to allow the + // search patterns to work properly + if (!$undid_bbcode_specialchars) + { + $message = str_replace(array(':', '.'), array(':', '.'), $message); + $undid_bbcode_specialchars = true; + } + + $message = preg_replace($preg['search'], $preg['replace'], $message); + $preg = array('search' => array(), 'replace' => array()); + } + } + } + } + + // Remove the uid from tags that have not been transformed into HTML + $message = str_replace(':' . $this->bbcode_uid, '', $message); + } + + /** + * Init bbcode cache + * + * requires: $this->bbcode_bitfield + * sets: $this->bbcode_cache with bbcode templates needed for bbcode_bitfield + */ + function bbcode_cache_init() + { + global $mx_user, $phpbb_root_path; + + if (empty($this->template_filename)) + { + $this->template_bitfield = new bitfield($mx_user->theme['bbcode_bitfield']); + $this->template_filename = $phpbb_root_path . 'styles/' . $mx_user->theme['template_path'] . '/template/bbcode.html'; + + if (!@file_exists($this->template_filename)) + { + trigger_error('The file ' . $this->template_filename . ' is missing.', E_USER_ERROR); + } + } + + $bbcode_ids = $rowset = $sql = array(); + + $bitfield = new bitfield($this->bbcode_bitfield); + $bbcodes_set = $bitfield->get_all_set(); + + foreach ($bbcodes_set as $bbcode_id) + { + if (isset($this->bbcode_cache[$bbcode_id])) + { + // do not try to re-cache it if it's already in + continue; + } + $bbcode_ids[] = $bbcode_id; + + if ($bbcode_id > NUM_CORE_BBCODES) + { + $sql[] = $bbcode_id; + } + } + + if (sizeof($sql)) + { + global $db; + + $sql = 'SELECT * + FROM ' . BBCODES_TABLE . ' + WHERE ' . $db->sql_in_set('bbcode_id', $sql); + $result = $db->sql_query($sql, 3600); + + while ($row = $db->sql_fetchrow($result)) + { + // To circumvent replacing newlines with
for the generated html, + // we use carriage returns here. They are later changed back to newlines + $row['bbcode_tpl'] = str_replace("\n", "\r", $row['bbcode_tpl']); + $row['second_pass_replace'] = str_replace("\n", "\r", $row['second_pass_replace']); + + $rowset[$row['bbcode_id']] = $row; + } + $db->sql_freeresult($result); + } + + foreach ($bbcode_ids as $bbcode_id) + { + switch ($bbcode_id) + { + case 0: + $this->bbcode_cache[$bbcode_id] = array( + 'str' => array( + '[/quote:$uid]' => $this->bbcode_tpl('quote_close', $bbcode_id) + ), + 'preg' => array( + '#\[quote(?:="(.*?)")?:$uid\]((?!\[quote(?:=".*?")?:$uid\]).)?#ise' => "\$this->bbcode_second_pass_quote('\$1', '\$2')" + ) + ); + break; + + case 1: + $this->bbcode_cache[$bbcode_id] = array( + 'str' => array( + '[b:$uid]' => $this->bbcode_tpl('b_open', $bbcode_id), + '[/b:$uid]' => $this->bbcode_tpl('b_close', $bbcode_id), + ) + ); + break; + + case 2: + $this->bbcode_cache[$bbcode_id] = array( + 'str' => array( + '[i:$uid]' => $this->bbcode_tpl('i_open', $bbcode_id), + '[/i:$uid]' => $this->bbcode_tpl('i_close', $bbcode_id), + ) + ); + break; + + case 3: + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[url:$uid\]((.*?))\[/url:$uid\]#s' => $this->bbcode_tpl('url', $bbcode_id), + '#\[url=([^\[]+?):$uid\](.*?)\[/url:$uid\]#s' => $this->bbcode_tpl('url', $bbcode_id), + ) + ); + break; + + case 4: + if ($mx_user->optionget('viewimg')) + { + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[img:$uid\](.*?)\[/img:$uid\]#s' => $this->bbcode_tpl('img', $bbcode_id), + ) + ); + } + else + { + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[img:$uid\](.*?)\[/img:$uid\]#s' => str_replace('$2', '[ img ]', $this->bbcode_tpl('url', $bbcode_id, true)), + ) + ); + } + break; + + case 5: + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[size=([\-\+]?\d+):$uid\](.*?)\[/size:$uid\]#s' => $this->bbcode_tpl('size', $bbcode_id), + ) + ); + break; + + case 6: + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '!\[color=(#[0-9a-f]{6}|[a-z\-]+):$uid\](.*?)\[/color:$uid\]!is' => $this->bbcode_tpl('color', $bbcode_id), + ) + ); + break; + + case 7: + $this->bbcode_cache[$bbcode_id] = array( + 'str' => array( + '[u:$uid]' => $this->bbcode_tpl('u_open', $bbcode_id), + '[/u:$uid]' => $this->bbcode_tpl('u_close', $bbcode_id), + ) + ); + break; + + case 8: + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[code(?:=([a-z]+))?:$uid\](.*?)\[/code:$uid\]#ise' => "\$this->bbcode_second_pass_code('\$1', '\$2')", + ) + ); + break; + + case 9: + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#(\[\/?(list|\*):[mou]?:?$uid\])[\n]{1}#' => "\$1", + '#(\[list=([^\[]+):$uid\])[\n]{1}#' => "\$1", + '#\[list=([^\[]+):$uid\]#e' => "\$this->bbcode_list('\$1')", + ), + 'str' => array( + '[list:$uid]' => $this->bbcode_tpl('ulist_open_default', $bbcode_id), + '[/list:u:$uid]' => $this->bbcode_tpl('ulist_close', $bbcode_id), + '[/list:o:$uid]' => $this->bbcode_tpl('olist_close', $bbcode_id), + '[*:$uid]' => $this->bbcode_tpl('listitem', $bbcode_id), + '[/*:$uid]' => $this->bbcode_tpl('listitem_close', $bbcode_id), + '[/*:m:$uid]' => $this->bbcode_tpl('listitem_close', $bbcode_id) + ), + ); + break; + + case 10: + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[email:$uid\]((.*?))\[/email:$uid\]#is' => $this->bbcode_tpl('email', $bbcode_id), + '#\[email=([^\[]+):$uid\](.*?)\[/email:$uid\]#is' => $this->bbcode_tpl('email', $bbcode_id) + ) + ); + break; + + case 11: + if ($mx_user->optionget('viewflash')) + { + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#' => $this->bbcode_tpl('flash', $bbcode_id), + ) + ); + } + else + { + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array( + '#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#' => str_replace('$1', '$3', str_replace('$2', '[ flash ]', $this->bbcode_tpl('url', $bbcode_id, true))) + ) + ); + } + break; + + case 12: + $this->bbcode_cache[$bbcode_id] = array( + 'str' => array( + '[/attachment:$uid]' => $this->bbcode_tpl('inline_attachment_close', $bbcode_id) + ), + 'preg' => array( + '#\[attachment=([0-9]+):$uid\]#' => $this->bbcode_tpl('inline_attachment_open', $bbcode_id) + ) + ); + break; + + + default: + if (isset($rowset[$bbcode_id])) + { + if ($this->template_bitfield->get($bbcode_id)) + { + // The bbcode requires a custom template to be loaded + if (!$bbcode_tpl = $this->bbcode_tpl($rowset[$bbcode_id]['bbcode_tag'], $bbcode_id)) + { + // For some reason, the required template seems not to be available, use the default template + $bbcode_tpl = (!empty($rowset[$bbcode_id]['second_pass_replace'])) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl']; + } + else + { + // In order to use templates with custom bbcodes we need + // to replace all {VARS} to corresponding backreferences + // Note that backreferences are numbered from bbcode_match + if (preg_match_all('/\{(URL|LOCAL_URL|WEB|IPAPERLINK|EMAIL|TEXT|SIMPLETEXT|IDENTIFIER|COLOR|NUMBER)[0-9]*\}/', $rowset[$bbcode_id]['bbcode_match'], $m)) + { + foreach ($m[0] as $i => $tok) + { + $bbcode_tpl = str_replace($tok, '$' . ($i + 1), $bbcode_tpl); + } + } + } + } + else + { + // Default template + $bbcode_tpl = ($rowset[$bbcode_id]['second_pass_replace']) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl']; + } + + // Replace {L_*} lang strings + $bbcode_tpl = preg_replace('/{L_([A-Z_]+)}/e', "(!empty(\$mx_user->lang['\$1'])) ? \$mx_user->lang['\$1'] : ucwords(strtolower(str_replace('_', ' ', '\$1')))", $bbcode_tpl); + + if (!empty($rowset[$bbcode_id]['second_pass_replace'])) + { + // The custom BBCode requires second-pass pattern replacements + $this->bbcode_cache[$bbcode_id] = array( + 'preg' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl) + ); + } + else + { + $this->bbcode_cache[$bbcode_id] = array( + 'str' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl) + ); + } + } + else + { + $this->bbcode_cache[$bbcode_id] = false; + } + break; + } + } + } + + /** + * Return bbcode template + */ + function bbcode_tpl($tpl_name, $bbcode_id = -1, $skip_bitfield_check = false) + { + static $bbcode_hardtpl = array(); + if (empty($bbcode_hardtpl)) + { + global $mx_user; + + $bbcode_hardtpl = array( + 'b_open' => '', + 'b_close' => '', + 'i_open' => '', + 'i_close' => '', + 'ipaper_open' => '', + 'ipaper_close' => '', + 'u_open' => '', + 'u_close' => '', + 'img' => '', + 'size' => '$2', + 'color' => '$2', + 'email' => '$2' + ); + } + + if ($bbcode_id != -1 && !$skip_bitfield_check && !$this->template_bitfield->get($bbcode_id)) + { + return (isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false; + } + + if (empty($this->bbcode_template)) + { + if (($tpl = file_get_contents($this->template_filename)) === false) + { + trigger_error('Could not load bbcode template', E_USER_ERROR); + } + + // replace \ with \\ and then ' with \'. + $tpl = str_replace('\\', '\\\\', $tpl); + $tpl = str_replace("'", "\'", $tpl); + + // strip newlines and indent + $tpl = preg_replace("/\n[\n\r\s\t]*/", '', $tpl); + + // Turn template blocks into PHP assignment statements for the values of $bbcode_tpl.. + $this->bbcode_template = array(); + + $matches = preg_match_all('#(.*?)#', $tpl, $match); + + for ($i = 0; $i < $matches; $i++) + { + if (empty($match[1][$i])) + { + continue; + } + + $this->bbcode_template[$match[1][$i]] = $this->bbcode_tpl_replace($match[1][$i], $match[2][$i]); + } + } + + + return (isset($this->bbcode_template[$tpl_name])) ? $this->bbcode_template[$tpl_name] : ((isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false); + } + + /** + * Return bbcode template replacement + */ + function bbcode_tpl_replace($tpl_name, $tpl) + { + global $mx_user; + + static $replacements = array( + 'quote_username_open' => array('{USERNAME}' => '$1'), + 'color' => array('{COLOR}' => '$1', '{TEXT}' => '$2'), + 'size' => array('{SIZE}' => '$1', '{TEXT}' => '$2'), + 'img' => array('{URL}' => '$1'), + 'flash' => array('{WIDTH}' => '$1', '{HEIGHT}' => '$2', '{URL}' => '$3'), + 'scribd' => array('{WIDTH}' => '$1', '{HEIGHT}' => '$2', '{SCRIBDURL}' => '$3'), + 'youtube' => array('{YOUTUBEID}' => '$1', '{YOUTUBELINK}' => '$2', '{WIDTH}' => '$3', '{HEIGHT}' => '$4'), + 'ipaper' => array('{IPAPERID}' => '$1', '{IPAPERKEY}' => '$2', '{WIDTH}' => '$3', '{HEIGHT}' => '$4', '{IPAPERLINK}' => '$5'), + 'ipaper_open' => array('{IPAPERCODE}' => '$1'), + 'url' => array('{URL}' => '$1', '{DESCRIPTION}' => '$2'), + 'web' => array('{URL}' => '$1', '{DESCRIPTION}' => '$2'), + 'size' => array('{ID}' => '$1', '{TEXT}' => '$2'), + 'email' => array('{EMAIL}' => '$1', '{DESCRIPTION}' => '$2') + ); + + $tpl = preg_replace('/{L_([A-Z_]+)}/e', "(!empty(\$mx_user->lang['\$1'])) ? \$mx_user->lang['\$1'] : ucwords(strtolower(str_replace('_', ' ', '\$1')))", $tpl); + + if (!empty($replacements[$tpl_name])) + { + $tpl = strtr($tpl, $replacements[$tpl_name]); + } + + return trim($tpl); + } + + /** + * Second parse list bbcode + */ + function bbcode_list($type) + { + if ($type == '') + { + $tpl = 'ulist_open_default'; + $type = 'default'; + } + else if ($type == 'i') + { + $tpl = 'olist_open'; + $type = 'lower-roman'; + } + else if ($type == 'I') + { + $tpl = 'olist_open'; + $type = 'upper-roman'; + } + else if (preg_match('#^(disc|circle|square)$#i', $type)) + { + $tpl = 'ulist_open'; + $type = strtolower($type); + } + else if (preg_match('#^[a-z]$#', $type)) + { + $tpl = 'olist_open'; + $type = 'lower-alpha'; + } + else if (preg_match('#[A-Z]#', $type)) + { + $tpl = 'olist_open'; + $type = 'upper-alpha'; + } + else if (is_numeric($type)) + { + $tpl = 'olist_open'; + $type = 'arabic-numbers'; + } + else + { + $tpl = 'olist_open'; + $type = 'arabic-numbers'; + } + + return str_replace('{LIST_TYPE}', $type, $this->bbcode_tpl($tpl)); + } + + /** + * Second parse quote tag + */ + function bbcode_second_pass_quote($mx_username, $quote) + { + // when using the /e modifier, preg_replace slashes double-quotes but does not + // seem to slash anything else + $quote = str_replace('\"', '"', $quote); + $mx_username = str_replace('\"', '"', $mx_username); + + // remove newline at the beginning + if ($quote == "\n") + { + $quote = ''; + } + + $quote = (($mx_username) ? str_replace('$1', $mx_username, $this->bbcode_tpl('quote_username_open')) : $this->bbcode_tpl('quote_open')) . $quote; + + return $quote; + } + + /** + * Second parse code tag + */ + function bbcode_second_pass_code($type, $code) + { + // when using the /e modifier, preg_replace slashes double-quotes but does not + // seem to slash anything else + $code = str_replace('\"', '"', $code); + + switch ($type) + { + case 'php': + // Not the english way, but valid because of hardcoded syntax highlighting + if (strpos($code, '
') === 0) + { + $code = substr($code, 41); + } + + // no break; + + default: + $code = str_replace("\t", ' ', $code); + $code = str_replace(' ', ' ', $code); + $code = str_replace(' ', ' ', $code); + + // remove newline at the beginning + if (!empty($code) && $code[0] == "\n") + { + $code = substr($code, 1); + } + break; + } + + $code = $this->bbcode_tpl('code_open') . $code . $this->bbcode_tpl('code_close'); + + return $code; + } + + + /** + * Loads bbcode templates from the bbcode.tpl file of the current template set. + * Creates an array, keys are bbcode names like "b_open" or "url", values + * are the associated template. + * Probably pukes all over the place if there's something really screwed + * with the bbcode.tpl file. + * + * Nathan Codding, Sept 26 2001. + * This a temporary function + */ + function load_bbcode_template() + { + global $template; + $tpl_filename = $template->make_filename('bbcode.tpl'); + $tpl = fread(fopen($tpl_filename, 'r'), filesize($tpl_filename)); + + // replace \ with \\ and then ' with \'. + $tpl = str_replace('\\', '\\\\', $tpl); + $tpl = str_replace('\'', '\\\'', $tpl); + + // strip newlines. + $tpl = str_replace("\n", '', $tpl); + + // Turn template blocks into PHP assignment statements for the values of $bbcode_tpls.. + $tpl = preg_replace('#(.*?)#', "\n" . '$bbcode_tpls[\'\\1\'] = \'\\2\';', $tpl); + + $bbcode_tpls = array(); + + eval($tpl); + + return $bbcode_tpls; + } + + /** + * Prepares the loaded bbcode templates for insertion into preg_replace() + * or str_replace() calls in the bbencode_second_pass functions. This + * means replacing template placeholders with the appropriate preg backrefs + * or with language vars. NOTE: If you change how the regexps work in + * bbencode_second_pass(), you MUST change this function. + * + * Nathan Codding, Sept 26 2001 + * + * This a temporary function + */ + function prepare_bbcode_template($bbcode_tpl) + { + global $document_id, $access_key, $height, $width; + global $lang; + + $bbcode_tpl['olist_open'] = str_replace('{LIST_TYPE}', '\\1', $bbcode_tpl['olist_open']); + + $bbcode_tpl['color_open'] = str_replace('{COLOR}', '\\1', $bbcode_tpl['color_open']); + + $bbcode_tpl['size_open'] = str_replace('{SIZE}', '\\1', $bbcode_tpl['size_open']); + + $bbcode_tpl['quote_open'] = str_replace('{L_QUOTE}', $lang['Quote'], $bbcode_tpl['quote_open']); + + $bbcode_tpl['quote_username_open'] = str_replace('{L_QUOTE}', $lang['Quote'], $bbcode_tpl['quote_username_open']); + $bbcode_tpl['quote_username_open'] = str_replace('{L_WROTE}', $lang['wrote'], $bbcode_tpl['quote_username_open']); + $bbcode_tpl['quote_username_open'] = str_replace('{USERNAME}', '\\1', $bbcode_tpl['quote_username_open']); + + $bbcode_tpl['code_open'] = str_replace('{L_CODE}', $lang['Code'], $bbcode_tpl['code_open']); + + $bbcode_tpl['img'] = str_replace('{URL}', '\\1', $bbcode_tpl['img']); + + // We do URLs in several different ways.. + $bbcode_tpl['url1'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']); + $bbcode_tpl['url1'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url1']); + + $bbcode_tpl['url2'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']); + $bbcode_tpl['url2'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url2']); + + $bbcode_tpl['url3'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']); + $bbcode_tpl['url3'] = str_replace('{DESCRIPTION}', '\\2', $bbcode_tpl['url3']); + + $bbcode_tpl['url4'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']); + $bbcode_tpl['url4'] = str_replace('{DESCRIPTION}', '\\3', $bbcode_tpl['url4']); + + $bbcode_tpl['email'] = str_replace('{EMAIL}', '\\1', $bbcode_tpl['email']); + + // bbcode_box Mod + $bbcode_tpl['align_open'] = str_replace('{ALIGN}', '\\1', $bbcode_tpl['align_open']); + // $bbcode_tpl['stream'] = str_replace('{URL}', '\\1', $bbcode_tpl['stream']); + $bbcode_tpl['ram'] = str_replace('{URL}', '\\1', $bbcode_tpl['ram']); + $bbcode_tpl['marq_open'] = str_replace('{MARQ}', '\\1', $bbcode_tpl['marq_open']); + $bbcode_tpl['table_open'] = str_replace('{TABLE}', '\\1', $bbcode_tpl['table_open']); + $bbcode_tpl['cell_open'] = str_replace('{CELL}', '\\1', $bbcode_tpl['cell_open']); + $bbcode_tpl['web'] = str_replace('{URL}', '\\1', $bbcode_tpl['web']); + //$bbcode_tpl['center_open'] = str_replace('{CENTER}', '\\1', $bbcode_tpl['center_open']); + //$bbcode_tpl['flash'] = str_replace('{WIDTH}', '\\1', $bbcode_tpl['flash']); + //$bbcode_tpl['flash'] = str_replace('{HEIGHT}', '\\2', $bbcode_tpl['flash']); + //$bbcode_tpl['flash'] = str_replace('{URL}', '\\3', $bbcode_tpl['flash']); + //$bbcode_tpl['video'] = str_replace('{URL}', '\\3', $bbcode_tpl['video']); + //$bbcode_tpl['video'] = str_replace('{WIDTH}', '\\1', $bbcode_tpl['video']); + //$bbcode_tpl['video'] = str_replace('{HEIGHT}', '\\2', $bbcode_tpl['video']); + $bbcode_tpl['font_open'] = str_replace('{FONT}', '\\1', $bbcode_tpl['font_open']); + $bbcode_tpl['poet_open'] = str_replace('{POET}', '\\1', $bbcode_tpl['poet_open']); + // bbcode_box Mod + + //Start more bbcode + $bbcode_tpl['stream'] = str_replace('{URL}', '\\1', $bbcode_tpl['stream']); + $bbcode_tpl['flash'] = str_replace('{WIDTH}', '\\1', $bbcode_tpl['flash']); + $bbcode_tpl['flash'] = str_replace('{HEIGHT}', '\\2', $bbcode_tpl['flash']); + $bbcode_tpl['flash'] = str_replace('{URL}', '\\3', $bbcode_tpl['flash']); + $bbcode_tpl['video'] = str_replace('{URL}', '\\3', $bbcode_tpl['video']); + $bbcode_tpl['video'] = str_replace('{WIDTH}', '\\1', $bbcode_tpl['video']); + $bbcode_tpl['video'] = str_replace('{HEIGHT}', '\\2', $bbcode_tpl['video']); + $bbcode_tpl['GVideo'] = str_replace('{GVIDEOID}', '\\1', $bbcode_tpl['GVideo']); + $bbcode_tpl['GVideo'] = str_replace('{GVIDEOLINK}', $lang['Link'], $bbcode_tpl['GVideo']); + $bbcode_tpl['youtube'] = str_replace('{YOUTUBEID}', '\\1', $bbcode_tpl['youtube']); + $bbcode_tpl['youtube'] = str_replace('{YOUTUBELINK}', $lang['Link'], $bbcode_tpl['youtube']); + $bbcode_tpl['youtube'] = str_replace('{WIDTH}', '\\3', $bbcode_tpl['youtube']); + $bbcode_tpl['youtube'] = str_replace('{HEIGHT}', '\\4', $bbcode_tpl['youtube']); + $bbcode_tpl['ipaper'] = str_replace('{IPAPERID}', '\\1', $bbcode_tpl['ipaper']); + $bbcode_tpl['ipaper'] = str_replace('{IPAPERKEY}', '\\2', $bbcode_tpl['ipaper']); + $bbcode_tpl['ipaper'] = str_replace('{WIDTH}', '\\3', $bbcode_tpl['ipaper']); + $bbcode_tpl['ipaper'] = str_replace('{HEIGHT}', '\\4', $bbcode_tpl['ipaper']); + $bbcode_tpl['ipaper'] = str_replace('{IPAPERLINK}', '\\5', $bbcode_tpl['ipaper']); + //$bbcode_tpl['scribd'] = str_replace('{WIDTH}', '\\1', $bbcode_tpl['scribd']); + //$bbcode_tpl['scribd'] = str_replace('{HEIGHT}', '\\2', $bbcode_tpl['scribd']); + $bbcode_tpl['scribd'] = str_replace('{SCRIBDID}', '\\1', $bbcode_tpl['scribd']); + $bbcode_tpl['scribd'] = str_replace('{SCRIBDURL}', $lang['Link'], $bbcode_tpl['scribd']); + //Stop more bbcode + + define("BBCODE_TPL_READY", true); + + return $bbcode_tpl; + } + + /** + * custom version of nl2br which takes custom BBCodes into account + */ + function bbcode_nl2br($text) + { + // custom BBCodes might contain carriage returns so they + // are not converted into
so now revert that + $text = str_replace(array("\n", "\r"), array('
', "\n"), $text); + return $text; + } + + /** + * Does second-pass bbencoding. This should be used before displaying the message in + * a thread. Assumes the message is already first-pass encoded, and we are given the + * correct UID as used in first-pass encoding. + * This a temporary function + */ + function bbencode_second_pass($text, $uid = '', $bitfield = false) + { + global $lang, $bbcode_tpl; + + if ($uid) + { + $this->bbcode_uid = $uid; + } + + if ($bitfield !== false) + { + $this->bbcode_bitfield = $bitfield; + + // Init those added with a new bbcode_bitfield (already stored codes will not get parsed again) + $this->bbcode_cache_init(); + } + + //Check if it's a phpBB3 block + if ($bitfield) + { + $this->bbcode_second_pass($text, $uid, $bitfield); + } + + //$text = str_replace(array("\n", "\r"), array('
', "\n"), $text); + $text = str_replace(array("\n", "\r"), array('
', ""), $text); + $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text); + + // pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0). + // This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it. + $text = " " . $text; + + // First: If there isn't a "[" and a "]" in the message, don't bother. + if (! (strpos($text, "[") && strpos($text, "]")) ) + { + // Remove padding, return. + $text = substr($text, 1); + return $text; + } + + // Only load the templates ONCE.. + if (!defined("BBCODE_TPL_READY")) + { + // load templates from file into array. + $bbcode_tpl = $this->load_bbcode_template(); + + // prepare array for use in regexps. + $bbcode_tpl = $this->prepare_bbcode_template($bbcode_tpl); + } + + // [CODE] and [/CODE] for posting code (HTML, PHP, C etc etc) in your posts. + $text = $this->bbencode_second_pass_code($text, $uid, $bbcode_tpl); + + // [IPAPER] and [/IPAPER] for posting iPaper in your posts. + $text = $this->bbencode_ipaper_pass_render($text, $uid, $bbcode_tpl); + + // [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff. + $text = str_replace("[quote:$uid]", $bbcode_tpl['quote_open'], $text); + $text = str_replace("[/quote:$uid]", $bbcode_tpl['quote_close'], $text); + + // New one liner to deal with opening quotes with usernames... + // replaces the two line version that I had here before.. + $text = preg_replace("/\[quote:$uid=\"(.*?)\"\]/si", $bbcode_tpl['quote_username_open'], $text); + + // [list] and [list=x] for (un)ordered lists. + // unordered lists + $text = str_replace("[list:$uid]", $bbcode_tpl['ulist_open'], $text); + // li tags + $text = str_replace("[*:$uid]", $bbcode_tpl['listitem'], $text); + // ending tags + $text = str_replace("[/list:u:$uid]", $bbcode_tpl['ulist_close'], $text); + $text = str_replace("[/list:o:$uid]", $bbcode_tpl['olist_close'], $text); + // Ordered lists + $text = preg_replace("/\[list=([a1]):$uid\]/si", $bbcode_tpl['olist_open'], $text); + + // colours + $text = preg_replace("/\[color=(\#[0-9A-F]{6}|[a-z]+):$uid\]/si", $bbcode_tpl['color_open'], $text); + $text = str_replace("[/color:$uid]", $bbcode_tpl['color_close'], $text); + + // size + $text = preg_replace("/\[size=([1-2]?[0-9]):$uid\]/si", $bbcode_tpl['size_open'], $text); + $text = str_replace("[/size:$uid]", $bbcode_tpl['size_close'], $text); + + // [b] and [/b] for bolding text. + $text = str_replace("[b:$uid]", $bbcode_tpl['b_open'], $text); + $text = str_replace("[/b:$uid]", $bbcode_tpl['b_close'], $text); + + // [u] and [/u] for underlining text. + $text = str_replace("[u:$uid]", $bbcode_tpl['u_open'], $text); + $text = str_replace("[/u:$uid]", $bbcode_tpl['u_close'], $text); + + // [i] and [/i] for italicizing text. + $text = str_replace("[i:$uid]", $bbcode_tpl['i_open'], $text); + $text = str_replace("[/i:$uid]", $bbcode_tpl['i_close'], $text); + + //$text = str_replace('url:' . $uid, 'url', $text); + + // Patterns and replacements for URL and email tags.. + $patterns = array(); + $replacements = array(); + + // [img]image_url_here[/img] code.. + // This one gets first-passed.. + $patterns[] = "#\[img:$uid\]([^?](?:[^\[]+|\[(?!url))*?)\[/img:$uid\]#i"; + $replacements[] = $bbcode_tpl['img']; + + // matches a [url]xxxx://www.phpbb.com[/url] code.. + $patterns[] = "#\[url\]([\w]+?://([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is"; + $replacements[] = $bbcode_tpl['url1']; + + // [url]www.phpbb.com[/url] code.. (no xxxx:// prefix). + $patterns[] = "#\[url\]((www|ftp)\.([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is"; + $replacements[] = $bbcode_tpl['url2']; + + // [url=xxxx://www.phpbb.com]phpBB[/url] code.. + $patterns[] = "#\[url=([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is"; + $replacements[] = $bbcode_tpl['url3']; + + // [url=www.phpbb.com]phpBB[/url] code.. (no xxxx:// prefix). + $patterns[] = "#\[url=((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is"; + $replacements[] = $bbcode_tpl['url4']; + + // [email]user@domain.tld[/email] code.. + $patterns[] = "#\[email\]([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si"; + $replacements[] = $bbcode_tpl['email']; + + //Strat more bbcode + $text = preg_replace($patterns, $replacements, $text); + // align + $text = preg_replace("/\[align=(left|right|center|justify):$uid\]/si", $bbcode_tpl['align_open'], $text); + $text = str_replace("[/align:$uid]", $bbcode_tpl['align_close'], $text); + // marquee + $text = preg_replace("/\[marq=(left|right|up|down):$uid\]/si", $bbcode_tpl['marq_open'], $text); + $text = str_replace("[/marq:$uid]", $bbcode_tpl['marq_close'], $text); + // table + $text = preg_replace("/\[table=(.*?):$uid\]/si", $bbcode_tpl['table_open'], $text); + $text = str_replace("[/table:$uid]", $bbcode_tpl['table_close'], $text); + // cell + $text = preg_replace("/\[cell=(.*?):$uid\]/si", $bbcode_tpl['cell_open'], $text); + $text = str_replace("[/cell:$uid]", $bbcode_tpl['cell_close'], $text); + // center + $text = preg_replace("/\[center:$uid\]/si", $bbcode_tpl['center_open'], $text); + $text = str_replace("[/center:$uid]", $bbcode_tpl['center_close'], $text); + // font + $text = preg_replace("/\[font=(.*?):$uid\]/si", $bbcode_tpl['font_open'], $text); + $text = str_replace("[/font:$uid]", $bbcode_tpl['font_close'], $text); + // poet + $text = preg_replace("/\[poet(.*?):$uid\]/si", $bbcode_tpl['poet_open'], $text); + $text = str_replace("[/poet:$uid]", $bbcode_tpl['poet_close'], $text); + //[hr] + $text = str_replace("[hr:$uid]", $bbcode_tpl['hr'], $text); + // bbcode_box Mod + // [fade] and [/fade] for faded text. + $text = str_replace("[fade:$uid]", $bbcode_tpl['fade_open'], $text); + $text = str_replace("[/fade:$uid]", $bbcode_tpl['fade_close'], $text); + // real + $patterns[] = "#\[ram:$uid\](.*?)\[/ram:$uid\]#si"; + $replacements[] = $bbcode_tpl['ram']; + // [stream]Sound URL[/stream] code.. + $patterns[] = "#\[stream:$uid\](.*?)\[/stream:$uid\]#si"; + $replacements[] = $bbcode_tpl['stream']; + //web + $patterns[] = "#\[web:$uid\](.*?)\[/web:$uid\]#si"; + $replacements[] = $bbcode_tpl['web']; + // [flash width= height= loop= ] and [/flash] code.. + $patterns[] = "#\[flash width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-9]?[0-9]):$uid\](.*?)\[/flash:$uid\]#si"; + $replacements[] = $bbcode_tpl['flash']; + // [flash width= height= loop= ] and [/flash] code.. + $patterns[10] = "#\[video width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-9]?[0-9]):$uid\](.*?)\[/video:$uid\]#si"; + $replacements[10] = $bbcode_tpl['video']; + + // [flash width=X height=X]Flash URL[/flash] code.. + $patterns[] = "#\[flash width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-9]?[0-9]):$uid\](.*?)\[/flash:$uid\]#si"; + $replacements[] = $bbcode_tpl['flash']; + + // [video width=X height=X]Video URL[/video] code.. + $patterns[] = "#\[video width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-9]?[0-9]):$uid\](.*?)\[/video:$uid\]#si"; + $replacements[] = $bbcode_tpl['video']; + + // [GVideo]GVideo URL[/GVideo] code.. + $patterns[] = "#\[GVideo\]http://video.google.[A-Za-z0-9.]{2,5}/videoplay\?docid=([0-9A-Za-z-_]*)[^[]*\[/GVideo\]#is"; + $replacements[] = $bbcode_tpl['GVideo']; + + // [youtube]www.youtube.com[/youtube] + $patterns[] = "#\[youtube\]http://(?:www\.)?youtube.com/watch\?v=([0-9A-Za-z-_]{11})[^[]*\[/youtube\]#is"; + $replacements[] = $bbcode_tpl['youtube']; + + // [youtube=xxxx://www.youtube.com]Youtube[/youtube] code.. + //$patterns[] = "#\[youtube=http://(?:www\.)?youtube.com/watch\?v=([0-9A-Za-z-_]{11})]([^?\n\r\t].*?)\[/youtube\]#is"; + //$replacements[] = $bbcode_tpl['youtube']; + + // [scribd]Scribd URL[/scribd] code.. + $patterns[] = "#\[scribd\]http://(?:d\.)?scribd.com/ScribdViewer.swf\?document_id=([0-9A-Za-z-_]*)[^[]*\[/scribd\]#is"; + $replacements[] = $bbcode_tpl['scribd']; + + // [scribd]Scribd URL[/scribd] code.. + $patterns[] = "#\[scribd id=([0-9A-Za-z-_]{8}) key=([0-9A-Za-z-_]{24})\](.*?)\[/scribd\]#is"; + $replacements[] = $bbcode_tpl['scribd']; + + // [ipaper]Scribd URL[/ipaper] code.. + $patterns[] = "#\[ipaper\]http://(?:d\.)?scribd.com/ScribdViewer.swf\?document_id=([0-9A-Za-z-_]*)\&access_key=([0-9A-Za-z-_]*)[^[]*\[/ipaper\]#is"; + $replacements[] = $bbcode_tpl['ipaper']; + + //Stop more bbcode + $text = preg_replace($patterns, $replacements, $text); + + // Remove the uid from tags that have not been transformed into HTML + $text = str_replace(':' . $uid, '', $text); + + // Remove our padding from the string.. + $text = substr($text, 1); + + return $text; + + } // bbencode_second_pass() + + /** + * This is used to change a [*] tag into a [*:$uid] tag as part + * of the first-pass bbencoding of [list] tags. It fits the + * standard required in order to be passed as a variable + * function into bbencode_first_pass_pda(). + */ + function replace_listitems($text, $uid) + { + $text = str_replace("[*]", "[*:$uid]", $text); + + return $text; + } + + function make_bbcode_uid() + { + global $mx_backend; + // Unique ID for this message.. + + $uid = $mx_backend->dss_rand(); + + // BBCode UID length fix + @define('BBCODE_UID_LEN', (PORTAL_BACKEND == 'phpbb3') ? 8 : 10); + + $uid = substr($uid, 0, BBCODE_UID_LEN); + + return $uid; + } + + function bbencode_first_pass($text, $uid) + { + // pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0). + // This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it. + $text = " " . $text; + + // [CODE] and [/CODE] for posting code (HTML, PHP, C etc etc) in your posts. + $text = $this->bbencode_first_pass_pda($text, $uid, '[code]', '[/code]', '', true, ''); + + // [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff. + $text = $this->bbencode_first_pass_pda($text, $uid, '[quote]', '[/quote]', '', false, ''); + $text = $this->bbencode_first_pass_pda($text, $uid, '/\[quote=\\\\"(.*?)\\\\"\]/is', '[/quote]', '', false, '', "[quote:$uid=\\\"\\1\\\"]"); + + // [ipaper] and [/ipaper] for posting scribd embed bbcode in your posts. + $text = $this->bbencode_first_pass_pda($text, $uid, '[ipaper]', '[/ipaper]', '', true, ''); + + // [youtube] and [/youtube] for posting scribd embed bbcode in your posts. + $text = $this->bbencode_first_pass_pda($text, $uid, '[youtube]', '[/youtube]', '', true, ''); + + // [scribd] and [/scribd] for posting scribd embed bbcode in your posts. + $text = $this->bbencode_first_pass_pda($text, $uid, '[scribd]', '[/scribd]', '', false, ''); + $text = $this->bbencode_first_pass_pda($text, $uid, '/\[scribd\\\\id=([0-9A-Za-z-_]{8})\\\\key=([0-9A-Za-z-_]{24})\](.*?)\]/is', '[/scribd]', '', false, '', "[scribd:$uid=\\\id=\\1\\\key=\\2\\\]"); + + // [list] and [list=x] for (un)ordered lists. + $open_tag = array(); + $open_tag[0] = "[list]"; + + // unordered.. + $text = $this->bbencode_first_pass_pda($text, $uid, $open_tag, "[/list]", "[/list:u]", false, 'replace_listitems'); + + $open_tag[0] = "[list=1]"; + $open_tag[1] = "[list=a]"; + + // ordered. + $text = $this->bbencode_first_pass_pda($text, $uid, $open_tag, "[/list]", "[/list:o]", false, 'replace_listitems'); + + // [color] and [/color] for setting text color + $text = preg_replace("#\[color=(\#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/color\]#si", "[color=\\1:$uid]\\2[/color:$uid]", $text); + + // [size] and [/size] for setting text size + $text = preg_replace("#\[size=([1-2]?[0-9])\](.*?)\[/size\]#si", "[size=\\1:$uid]\\2[/size:$uid]", $text); + + // [b] and [/b] for bolding text. + $text = preg_replace("#\[b\](.*?)\[/b\]#si", "[b:$uid]\\1[/b:$uid]", $text); + + // [u] and [/u] for underlining text. + $text = preg_replace("#\[u\](.*?)\[/u\]#si", "[u:$uid]\\1[/u:$uid]", $text); + + // [i] and [/i] for italicizing text. + $text = preg_replace("#\[i\](.*?)\[/i\]#si", "[i:$uid]\\1[/i:$uid]", $text); + + // [img]image_url_here[/img] code.. + $text = preg_replace("#\[img\]((http|ftp|https|ftps)://)([^ \?&=\#\"\n\r\t<]*?(\.(jpg|jpeg|gif|png)))\[/img\]#sie", "'[img:$uid]\\1' . str_replace(' ', '%20', '\\3') . '[/img:$uid]'", $text); + + // bbcode_box Mod + // [fade] and [/fade] for faded text. + $text = preg_replace("#\[fade\](.*?)\[/fade\]#si", "[fade:$uid]\\1[/fade:$uid]", $text); + // [align] and [/align] + $text = preg_replace("#\[align=(left|right|center|justify)\](.*?)\[/align\]#si", "[align=\\1:$uid]\\2[/align:$uid]", $text); + // [marq] and [/marq] + $text = preg_replace("#\[marq=(left|right|up|down)\](.*?)\[/marq\]#si", "[marq=\\1:$uid]\\2[/marq:$uid]", $text); + // [table] and [/table] + $text = preg_replace("#\[table=(.*?)\](.*?)\[/table\]#si", "[table=\\1:$uid]\\2[/table:$uid]", $text); + // [cell] and [/cell] + $text = preg_replace("#\[cell=(.*?)\](.*?)\[/cell\]#si", "[cell=\\1:$uid]\\2[/cell:$uid]", $text); + // [font] and [/font] + $text = preg_replace("#\[font=(.*?)\](.*?)\[/font\]#si", "[font=\\1:$uid]\\2[/font:$uid]", $text); + // [poet] and [/poet] + $text = preg_replace("#\[poet(.*?)\](.*?)\[/poet\]#si", "[poet\\1:$uid]\\2[/poet:$uid]", $text); + // [center] and [/center] + $text = preg_replace("#\[center\](.*?)\[/center\]#si", "[center:$uid]\\1[/center:$uid]", $text); + // [real]and[/real] + $text = preg_replace("#\[ram\](.*?)\[/ram\]#si", "[ram:$uid]\\1[/ram:$uid]", $text); + // [stream]and[/stream] + //$text = preg_replace("#\[stream\](.*?)\[/stream\]#si", "[stream:$uid]\\1[/stream:$uid]", $text); + // [web]and[/web] + $text = preg_replace("#\[web\](http(s)?://)([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)\[/web\]#si", "[web:$uid]\\1\\3[/web:$uid]", $text); + //[flash width= heigth= loop=] and [/flash] + //$text = preg_replace("#\[flash width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-9]?[0-9])\](([a-z]+?)://([^, \n\r]+))\[\/flash\]#si","[flash width=\\1 height=\\2:$uid\]\\3[/flash:$uid]", $text); + //[video width= heigth=] and [/video] + //$text = preg_replace("#\[video width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-9]?[0-9])\](([a-z]+?)://([^, \n\r]+))\[\/video\]#si","[video width=\\1 height=\\2:$uid\]\\3[/video:$uid]", $text); + // [hr] + $text = preg_replace("#\[hr\]#si", "[hr:$uid]", $text); + // bbcode_box Mod + + //Start more bbcode + $text = str_replace('url:' . $uid, 'url', $text); + + // [stream]Sound URL[/stream] code.. + $text = preg_replace("#\[stream\](.*?)\[/stream\]#si", "[stream:$uid]\\1[/stream:$uid]", $text); + + // [scribd width=X height=X]Scribd URL[/scribd] code.. + $text = preg_replace("#\[scribd width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-9]?[0-9])\](([a-z]+?)://([^, \n\r]+))\[\/scribd\]#si","[scribd width=\\1 height=\\2:$uid\]\\3[/scribd:$uid]", $text); + + // [flash width=X height=X]Flash URL[/flash] code.. + $text = preg_replace("#\[flash width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-9]?[0-9])\](([a-z]+?)://([^, \n\r]+))\[\/flash\]#si","[flash width=\\1 height=\\2:$uid\]\\3[/flash:$uid]", $text); + + // [video width=X height=X]Video URL[/video] code.. + $text = preg_replace("#\[video width=([0-6]?[0-9]?[0-9]) height=([0-4]?[0-9]?[0-9])\](([a-z]+?)://([^, \n\r]+))\[\/video\]#si","[video width=\\1 height=\\2:$uid\]\\3[/video:$uid]", $text); + + //Stop more bbcode + + // Remove our padding from the string.. + return substr($text, 1);; + + } // bbencode_first_pass() + + + /** + * $text - The text to operate on. + * $uid - The UID to add to matching tags. + * $open_tag - The opening tag to match. Can be an array of opening tags. + * $close_tag - The closing tag to match. + * $close_tag_new - The closing tag to replace with. + * $mark_lowest_level - boolean - should we specially mark the tags that occur + * at the lowest level of nesting? (useful for [code], because + * we need to match these tags first and transform HTML tags + * in their contents.. + * $func - This variable should contain a string that is the name of a function. + * That function will be called when a match is found, and passed 2 + * parameters: ($text, $uid). The function should return a string. + * This is used when some transformation needs to be applied to the + * text INSIDE a pair of matching tags. If this variable is FALSE or the + * empty string, it will not be executed. + * If open_tag is an array, then the pda will try to match pairs consisting of + * any element of open_tag followed by close_tag. This allows us to match things + * like [list=A]...[/list] and [list=1]...[/list] in one pass of the PDA. + * + * NOTES: - this function assumes the first character of $text is a space. + * - every opening tag and closing tag must be of the [...] format. + */ + function bbencode_first_pass_pda($text, $uid, $open_tag, $close_tag, $close_tag_new, $mark_lowest_level, $func, $open_regexp_replace = false) + { + $open_tag_count = 0; + + if (!$close_tag_new || ($close_tag_new == '')) + { + $close_tag_new = $close_tag; + } + + $close_tag_length = strlen($close_tag); + $close_tag_new_length = strlen($close_tag_new); + $uid_length = strlen($uid); + + $use_function_pointer = ($func && ($func != '')); + + $stack = array(); + + if (is_array($open_tag)) + { + if (0 == count($open_tag)) + { + // No opening tags to match, so return. + return $text; + } + $open_tag_count = count($open_tag); + } + else + { + // only one opening tag. make it into a 1-element array. + $open_tag_temp = $open_tag; + $open_tag = array(); + $open_tag[0] = $open_tag_temp; + $open_tag_count = 1; + } + + $open_is_regexp = false; + + if ($open_regexp_replace) + { + $open_is_regexp = true; + if (!is_array($open_regexp_replace)) + { + $open_regexp_temp = $open_regexp_replace; + $open_regexp_replace = array(); + $open_regexp_replace[0] = $open_regexp_temp; + } + } + + if ($mark_lowest_level && $open_is_regexp) + { + mx_message_die(GENERAL_ERROR, "Unsupported operation for bbcode_first_pass_pda()."); + } + + // Start at the 2nd char of the string, looking for opening tags. + $curr_pos = 1; + while ($curr_pos && ($curr_pos < strlen($text))) + { + $curr_pos = strpos($text, "[", $curr_pos); + + // If not found, $curr_pos will be 0, and the loop will end. + if ($curr_pos) + { + // We found a [. It starts at $curr_pos. + // check if it's a starting or ending tag. + $found_start = false; + $which_start_tag = ""; + $start_tag_index = -1; + + for ($i = 0; $i < $open_tag_count; $i++) + { + // Grab everything until the first "]"... + $possible_start = substr($text, $curr_pos, strpos($text, ']', $curr_pos + 1) - $curr_pos + 1); + + // + // We're going to try and catch usernames with "[' characters. + // + if( preg_match('#\[quote=\\\"#si', $possible_start, $match) && !preg_match('#\[quote=\\\"(.*?)\\\"\]#si', $possible_start) ) + { + // OK we are in a quote tag that probably contains a ] bracket. + // Grab a bit more of the string to hopefully get all of it.. + if ($close_pos = strpos($text, '"]', $curr_pos + 14)) + { + if (strpos(substr($text, $curr_pos + 14, $close_pos - ($curr_pos + 14)), '[quote') === false) + { + $possible_start = substr($text, $curr_pos, $close_pos - $curr_pos + 7); + } + } + } + + // Now compare, either using regexp or not. + if ($open_is_regexp) + { + $match_result = array(); + if (preg_match($open_tag[$i], $possible_start, $match_result)) + { + $found_start = true; + $which_start_tag = $match_result[0]; + $start_tag_index = $i; + break; + } + } + else + { + // straightforward string comparison. + if (0 == strcasecmp($open_tag[$i], $possible_start)) + { + $found_start = true; + $which_start_tag = $open_tag[$i]; + $start_tag_index = $i; + break; + } + } + } + + if ($found_start) + { + // We have an opening tag. + // Push its position, the text we matched, and its index in the open_tag array on to the stack, and then keep going to the right. + $match = array("pos" => $curr_pos, "tag" => $which_start_tag, "index" => $start_tag_index); + array_push($stack, $match); + // + // Rather than just increment $curr_pos + // Set it to the ending of the tag we just found + // Keeps error in nested tag from breaking out + // of table structure.. + // + $curr_pos += strlen($possible_start); + } + else + { + // check for a closing tag.. + $possible_end = substr($text, $curr_pos, $close_tag_length); + if (0 == strcasecmp($close_tag, $possible_end)) + { + // We have an ending tag. + // Check if we've already found a matching starting tag. + if (sizeof($stack) > 0) + { + // There exists a starting tag. + $curr_nesting_depth = sizeof($stack); + // We need to do 2 replacements now. + $match = array_pop($stack); + $start_index = $match['pos']; + $start_tag = $match['tag']; + $start_length = strlen($start_tag); + $start_tag_index = $match['index']; + + if ($open_is_regexp) + { + $start_tag = preg_replace($open_tag[$start_tag_index], $open_regexp_replace[$start_tag_index], $start_tag); + } + + // everything before the opening tag. + $before_start_tag = substr($text, 0, $start_index); + + // everything after the opening tag, but before the closing tag. + $between_tags = substr($text, $start_index + $start_length, $curr_pos - $start_index - $start_length); + + // Run the given function on the text between the tags.. + if ($use_function_pointer) + { + $between_tags = $this->$func($between_tags, $uid); + } + + // everything after the closing tag. + $after_end_tag = substr($text, $curr_pos + $close_tag_length); + + // Mark the lowest nesting level if needed. + if ($mark_lowest_level && ($curr_nesting_depth == 1)) + { + if ($open_tag[0] == '[code]') + { + $code_entities_match = array('#<#', '#>#', '#"#', '#:#', '#\[#', '#\]#', '#\(#', '#\)#', '#\{#', '#\}#'); + $code_entities_replace = array('<', '>', '"', ':', '[', ']', '(', ')', '{', '}'); + $between_tags = preg_replace($code_entities_match, $code_entities_replace, $between_tags); + } + $text = $before_start_tag . substr($start_tag, 0, $start_length - 1) . ":$curr_nesting_depth:$uid]"; + $text .= $between_tags . substr($close_tag_new, 0, $close_tag_new_length - 1) . ":$curr_nesting_depth:$uid]"; + } + else + { + if ($open_tag[0] == '[code]') + { + $text = $before_start_tag . '[code]'; + $text .= $between_tags . '[/code]'; + } + else + { + if ($open_is_regexp) + { + $text = $before_start_tag . $start_tag; + } + else + { + $text = $before_start_tag . substr($start_tag, 0, $start_length - 1) . ":$uid]"; + } + $text .= $between_tags . substr($close_tag_new, 0, $close_tag_new_length - 1) . ":$uid]"; + } + } + + $text .= $after_end_tag; + + // Now.. we've screwed up the indices by changing the length of the string. + // So, if there's anything in the stack, we want to resume searching just after it. + // otherwise, we go back to the start. + if (sizeof($stack) > 0) + { + $match = array_pop($stack); + $curr_pos = $match['pos']; + // bbcode_array_push($stack, $match); + // ++$curr_pos; + } + else + { + $curr_pos = 1; + } + } + else + { + // No matching start tag found. Increment pos, keep going. + ++$curr_pos; + } + } + else + { + // No starting tag or ending tag.. Increment pos, keep looping., + ++$curr_pos; + } + } + } + } // while + + return $text; + + } // bbencode_first_pass_pda() + + /** + * Does second-pass bbencoding of the [code] tags. This includes + * running htmlspecialchars() over the text contained between + * any pair of [code] tags that are at the first level of + * nesting. Tags at the first level of nesting are indicated + * by this format: [code:1:$uid] ... [/code:1:$uid] + * Other tags are in this format: [code:$uid] ... [/code:$uid] + * This a temporary function + */ + function bbencode_second_pass_code($text, $uid, $bbcode_tpl) + { + global $lang; + + $code_start_html = $bbcode_tpl['code_open']; + $code_end_html = $bbcode_tpl['code_close']; + + // First, do all the 1st-level matches. These need an htmlspecialchars() run, + // so they have to be handled differently. + $match_count = preg_match_all("#\[code:1:$uid\](.*?)\[/code:1:$uid\]#si", $text, $matches); + + for ($i = 0; $i < $match_count; $i++) + { + $before_replace = $matches[1][$i]; + $after_replace = $matches[1][$i]; + + // Replace 2 spaces with " " so non-tabbed code indents without making huge long lines. + $after_replace = str_replace(" ", " ", $after_replace); + // now Replace 2 spaces with " " to catch odd #s of spaces. + $after_replace = str_replace(" ", " ", $after_replace); + + // Replace tabs with " " so tabbed code indents sorta right without making huge long lines. + $after_replace = str_replace("\t", " ", $after_replace); + + // now Replace space occurring at the beginning of a line + $after_replace = preg_replace("/^ {1}/m", ' ', $after_replace); + + $str_to_match = "[code:1:$uid]" . $before_replace . "[/code:1:$uid]"; + + $replacement = $code_start_html; + $replacement .= $after_replace; + $replacement .= $code_end_html; + + $text = str_replace($str_to_match, $replacement, $text); + } + + // Now, do all the non-first-level matches. These are simple. + $text = str_replace("[code:$uid]", $code_start_html, $text); + $text = str_replace("[/code:$uid]", $code_end_html, $text); + + return $text; + + } // bbencode_second_pass_code() + + /** + * Rewritten by Florin C Bodin - July 10, 2009. + * Description: Pass Embed Scibd iPaper in a post Pass + * Version: 0.2 + * Original Author: Stuart Marsh + * Author URI: http://www.beardygeek.com + * This should be used before displaying the message. + */ + function bbencode_ipaper_pass_render($text, $uid, $bbcode_tpl) + { + global $document_id, $access_key, $height, $width; + global $lang; + + $params = array('document_id','access_key','height','width'); + + $ipaper_start_html = $bbcode_tpl['ipaper_open']; + $ipaper_end_html = $bbcode_tpl['ipaper_close']; + + // First, do all the 1st-level matches. + $match_count = preg_match_all("#\[ipaper:1:$uid\](.*?)\[/ipaper:1:$uid\]#si", $text, $matches); + + for ($i = 0; $i < $match_count; $i++) + { + + $before_replace = $matches[1][$i]; + $after_replace = $matches[1][$i]; + + //Remove ipaper open and close bbcode tags. + $before_replace = str_replace(array($ipaper_start_html, $ipaper_end_html), "", $before_replace); + $after_replace = str_replace(array($ipaper_start_html, $ipaper_end_html), "", $after_replace); + $after_replace = str_replace(array('”','″'), '', $after_replace); + + // Then, do the 2nd-level matches. + $total = preg_match_all("|([^?=]+)=([^?=]+)(#{0,}[^?=]*)|", $after_replace, $attributes, PREG_SET_ORDER); + + if ($total) + { + $this->ipaper_head(); + } + + $arguments[] = array(); + + foreach ((array) $attributes as $elem) + { + if(!in_array($elem[$i], $params)) + { + $arguments[$elem[1]] = $elem[2]; + } + } + + if ((!array_key_exists('document_id', $arguments)) && (!array_key_exists('access_key', $arguments))) + { + return 'Error: Required parameter "docId" or "access_key" is missing!'; + } + + // First, do all the 1st-level matches. + if (array_key_exists('document_id', $arguments)) + { + $document_id = $arguments['document_id']; + } + else + { + $document_id = ''; + } + + if (array_key_exists('access_key', $arguments)) + { + $access_key = $arguments['access_key']; + } + else + { + $access_key = 'key-'; + } + + if (array_key_exists('height', $arguments)) + { + $height = $arguments['height']; + } + else + { + $height = 600; + } + + if (array_key_exists('width', $arguments)) + { + $width = $arguments['width']; + } + else + { + $width = 400; + } + + $after_replace = ''; + $after_replace .= "\n".''."\n"; + $after_replace .= ''."\n"; + + $str_to_match = "[ipaper:1:$uid]" . $before_replace . "[/ipaper:1:$uid]"; + + $replacement = $ipaper_start_html . $after_replace . $ipaper_end_html; + + $text = str_replace($str_to_match, $replacement, $text); + + } + + // Now, do all the non-first-level matches. These are simple. + $text = str_replace("[ipaper:$uid]", $ipaper_start_html, $text); + $text = str_replace("[/ipaper:$uid]", $ipaper_end_html, $text); + + return $text; + + } //bbencode_ipaper_pass_render() + + + function ipaper_head() + { + // ------------------------------------------------------------------------- + // Extend page with additional header or footer data + // Examples: + // $mx_page->add_css_file(); // Include style dependent *.css file, eg module_path/template_path/template/theme.css + // $mx_page->add_js_file( 'includes/js.js' ); // Relative to module_root + // $mx_page->add_header_text( 'header text' ); + // $mx_page->add_footer_text( 'includes/test.txt', true ); // Relative to module_root + // Note: Included text from file (last example), will evaluate $theme and $mx_block->info variables. + // ------------------------------------------------------------------------- + + global $document_id, $access_key, $height, $width; + global $mx_page; + + $addional_header_text = $header_text = ""; + + $header_text .= ''."\n"; + $header_text .= ''; + + $addional_header_text .= "\n"."\n".$header_text; + + + if (is_object($mx_page)) + { + $mx_page->add_header_text($addional_header_text); + } + } + + + /** + * Rewritten by Nathan Codding - Feb 6, 2001. + * - Goes through the given string, and replaces xxxx://yyyy with an HTML tag linking + * to that URL + * - Goes through the given string, and replaces www.xxxx.yyyy[zzzz] with an HTML tag linking + * to http://www.xxxx.yyyy[/zzzz] + * - Goes through the given string, and replaces xxxx@yyyy with an HTML mailto: tag linking + * to that email address + * - Only matches these 2 patterns either after a space, or at the beginning of a line + * + * Notes: the email one might get annoying - it's easy to make it more restrictive, though.. maybe + * have it require something like xxxx@yyyy.zzzz or such. We'll see. + * We can add here more phpBB3 stuff in time - Ory + */ + function make_clickable($text) + { + $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text); + + // pad it with a space so we can match things at the start of the 1st line. + $ret = ' ' . $text; + + // matches an "xxxx://yyyy" URL at the start of a line, or after a space. + // xxxx can only be alpha characters. + // yyyy is anything up to the first space, newline, comma, double quote or < + $ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1\\2", $ret); + + // matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing + // Must contain at least 2 dots. xxxx contains either alphanum, or "-" + // zzzz is optional.. will contain everything up to the first space, newline, + // comma, double quote or <. + $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1\\2", $ret); + + // matches an email@domain type address at the start of a line, or after a space. + // Note: Only the followed chars are valid; alphanums, "-", "_" and or ".". + $ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1\\2@\\3", $ret); + + // Remove our padding.. + $ret = substr($ret, 1); + + return($ret); + } + + /** + * Nathan Codding - Feb 6, 2001 + * Reverses the effects of make_clickable(), for use in editpost. + * - Does not distinguish between "www.xxxx.yyyy" and "http://aaaa.bbbb" type URLs. + * + */ + function undo_make_clickable($text) + { + $text = preg_replace("#.*?#i", "\\1", $text); + $text = preg_replace("#.*?#i", "\\1", $text); + + return $text; + + } + + // + // MXP Wrapper + // + + /** + * bbcode to html. + * + * Convert the bbcode to html + * + * @param string $bbtext + * @param string $bbcode_uid + * @param boolean $smilies_on + * @return string + */ + function decode($mytext, $bbcode_uid, $smilies_on = true, $bbcode_bitfield = false) + { + global $mx_root_path, $phpbb_root_path, $phpEx, $mx_page; + + if (!$mytext) + { + return ''; + } + + $mytext = mx_censor_text($mytext); + + //Do some checks + $phpbb3_text = $bbcode_bitfield ? true : false; + $bbcode_bitfield = ($bbcode_bitfield && (strlen($bbcode_bitfield) < 2)) ? false : $bbcode_bitfield; + + if (!empty($bbcode_uid)) + { + $mytext = $this->bbencode_second_pass($mytext, $bbcode_uid, $bbcode_bitfield); + } + + $mytext = str_replace(array("\n", "\r"), array('
', "\n"), $mytext); + $mytext = $this->bbcode_nl2br($mytext); + + //$mytext = smiley_text($mytext, !($flags & OPTION_FLAG_SMILIES)); + if ($smilies_on && $phpbb3_text) + { + $mytext = $this->smilies3_pass($mytext); + } + else if ($smilies_on) + { + $mytext = $this->smilies_pass($mytext); + } + + //$mytext = str_replace("\n", "\n
\n", $mytext); + + if ($mytext != '') + { + $mytext = $this->make_clickable($mytext); + } + + return $mytext; + } + + /** + * Smilies pass. + * + * compatible with phpBB3 blocks + * + * @param string $message + * @return string + * + */ + function smilies3_pass($message) + { + static $orig, $repl; + global $board_config, $mx_root_path, $phpbb_root_path, $phpEx; + + if (!isset($orig)) + { + global $db; + $orig = $repl = array(); + + $sql = 'SELECT * FROM ' . SMILIES_TABLE; + if( !$result = $db->sql_query($sql) ) + { + mx_message_die(GENERAL_ERROR, "Couldn't obtain smilies data", "", __LINE__, __FILE__, $sql); + } + + while ($row = $db->sql_fetchrow($result)) + { + if (empty($row['code'])) + { + continue; + } + + // (assertion) + $match[] = '(?<=^|[\n .])' . preg_quote($row['code'], '#') . '(?![^<>]*>)'; + $replace[] = ''; + } + + $db->sql_freeresult($result); + + if (sizeof($match)) + { + if ($max_smilies) + { + $num_matches = preg_match_all('#' . implode('|', $match) . '#', $message, $matches); + unset($matches); + + if ($num_matches !== false && $num_matches > $max_smilies) + { + $this->warn_msg[] = sprintf($mx_user->lang['TOO_MANY_SMILIES'], $max_smilies); + return; + } + } + + // Make sure the delimiter # is added in front and at the end of every element within $match + $message = trim(preg_replace(explode(chr(0), '#' . implode('#' . chr(0) . '#', $match) . '#'), $replace, $message)); + } + } + + $message = str_replace("{SMILIES_PATH}", $this->smiley_path_url . $this->smilies_path . $smilies[$i][$this->smiley_url], ' ' . $message . ' '); + + return $message; + } + + /** + * Smilies pass. + * + * compatible with phpBB2 blocks + * + * @param string $message + * @return string + * + */ + function smilies_pass($message) + { + static $orig, $repl; + global $board_config, $mx_root_path, $phpbb_root_path, $phpEx; + + if (!isset($orig)) + { + global $db; + $orig = $repl = array(); + + $sql = 'SELECT * FROM ' . SMILIES_TABLE; + if( !$result = $db->sql_query($sql) ) + { + mx_message_die(GENERAL_ERROR, "Couldn't obtain smilies data", "", __LINE__, __FILE__, $sql); + } + + $smilies = $db->sql_fetchrowset($result); + + if (count($smilies)) + { + @usort($smilies, 'smiley_sort'); + } + + for ($i = 0; $i < count($smilies); $i++) + { + $orig[] = "/(?<=.\W|\W.|^\W)" . preg_quote($smilies[$i]['code'], "/") . "(?=.\W|\W.|\W$)/"; + $repl[] = '
'; + } + } + + if (count($orig)) + { + $message = preg_replace($orig, $repl, ' ' . $message . ' '); + $message = substr($message, 1, -1); + } + + return $message; + } + + /** + * phpBB Smilies pass. + * + * Hacking smilies_pass from phpbb/includes/bbcode.php + * + * NOTE: This is only kept for reference - not used. + * + * @param string $message + * @return string + */ + function mx_smilies_pass_old($message) + { + global $mx_page, $board_config, $phpbb_root_path, $phpEx; + + $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; + } + + // + // This function will prepare a posted message for + // entry into the database. + // + function prepare_message($message, $html_on, $bbcode_on, $smile_on, $bbcode_uid = 0) + { + global $board_config, $html_entities_match, $html_entities_replace; + + // + // Clean up the message + // + $message = trim($message); + + if ($html_on) + { + // If HTML is on, we try to make it safe + // This approach is quite agressive and anything that does not look like a valid tag + // is going to get converted to HTML entities + $message = stripslashes($message); + $html_match = '#<[^\w<]*(\w+)((?:"[^"]*"|\'[^\']*\'|[^<>\'"])+)?>#'; + $matches = array(); + + $message_split = preg_split($html_match, $message); + preg_match_all($html_match, $message, $matches); + + $message = ''; + + foreach ($message_split as $part) + { + $tag = array(array_shift($matches[0]), array_shift($matches[1]), array_shift($matches[2])); + $message .= preg_replace($html_entities_match, $html_entities_replace, $part) . clean_html($tag); + } + + $message = addslashes($message); + $message = str_replace('"', '\"', $message); + } + else + { + $message = preg_replace($html_entities_match, $html_entities_replace, $message); + } + + if($bbcode_on && $bbcode_uid != '') + { + $message = $this->bbencode_first_pass($message, $bbcode_uid); + } + + return $message; + } + + //Core BBCode Starts + + /** + * Generate smilies. + * + * Hacking generate_smilies from phpbb/includes/functions_post(ing).php + * + * @param string $mode + * @param integer $page_id + * + * Fill smiley templates (or just the variables) with smilies, either in a window or inline + */ + function generate_smilies($mode, $forum_id) + { + global $mx_page, $board_config, $template, $mx_root_path, $phpbb_root_path, $phpEx; + global $db, $lang, $images, $theme; + global $user_ip, $session_length, $starttime; + global $userdata, $phpbb_auth, $mx_user; + + $inline_columns = 4; + $inline_rows = 5; + $window_columns = 8; + + $start = phpBB3::request_var('start', 0); + + if ($mode == 'window') + { + if ($forum_id) + { + $sql = 'SELECT forum_style + FROM ' . FORUMS_TABLE . " + WHERE forum_id = $forum_id"; + $result = $db->sql_query_limit($sql, 1); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + $mx_user->setup('posting', (int) $row['forum_style']); + } + else + { + $mx_user->setup('posting'); + } + + //page_header($mx_user->lang['SMILIES']); + + $sql = 'SELECT COUNT(smiley_id) AS item_count + FROM ' . SMILIES_TABLE . ' + GROUP BY smiley_url'; + $result = $db->sql_query($sql, 3600); + + $smiley_count = 0; + while ($row = $db->sql_fetchrow($result)) + { + ++$smiley_count; + } + $db->sql_freeresult($result); + /* + $template->set_filenames(array( + 'body' => 'posting_smilies.html') + ); + generate_pagination(mx3_append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=smilies&f=' . $forum_id), $smiley_count, $config['smilies_per_page'], $start); + */ + } + + $display_link = false; + if ($mode == 'inline') + { + $sql = 'SELECT smiley_id + FROM ' . SMILIES_TABLE . ' + WHERE display_on_posting = 0'; + $result = $db->sql_query_limit($sql, 1, 0, 3600); + + if ($row = $db->sql_fetchrow($result)) + { + $display_link = true; + } + $db->sql_freeresult($result); + } + + if ($mode == 'window') + { + $sql = 'SELECT smiley_url, MIN(emotion) as emotion, MIN(code) AS code, smiley_width, smiley_height, MIN(smiley_order) AS min_smiley_order + FROM ' . SMILIES_TABLE . ' + GROUP BY smiley_url, smiley_width, smiley_height + ORDER BY min_smiley_order'; + $result = $db->sql_query_limit($sql, $config['smilies_per_page'], $start, 3600); + } + else + { + $sql = 'SELECT * + FROM ' . SMILIES_TABLE . ' + WHERE display_on_posting = 1 + ORDER BY smiley_order'; + $result = $db->sql_query($sql, 3600); + } + + $smilies = array(); + + //phpBB2 code start + if ($result) + { + $num_smilies = 0; + $rowset = array(); + while ($row = $db->sql_fetchrow($result)) + { + if (empty($smilies[$row['smiley_url']])) + { + $smilies[$row['smiley_url']] = $row; + $rowset[$row['smiley_url']]['code'] = str_replace("'", "\\'", str_replace('\\', '\\\\', $row['code'])); + $rowset[$row['smiley_url']]['emotion'] = $row['emotion']; + $num_smilies++; + } + } + $db->sql_freeresult($result); + + if ($num_smilies) + { + $smilies_count = ($mode == 'inline') ? min(19, $num_smilies) : $num_smilies; + $smilies_split_row = ($mode == 'inline') ? $inline_columns - 1 : $window_columns - 1; + + $s_colspan = 0; + $row = 0; + $col = 0; + + while (list($smile_url, $data) = @each($rowset)) + { + if (!$col) + { + $template->assign_block_vars('smilies_row', array()); + } + + $template->assign_block_vars('smilies_row.smilies_col', array( + 'SMILEY_CODE' => $data['code'], + 'SMILEY_IMG' => $this->smiley_path_url . $board_config['smilies_path'] . '/' . $smile_url, + 'SMILEY_DESC' => isset($data['emotion']) ? $data['emotion'] : $row['emotion']) + ); + + $s_colspan = max($s_colspan, $col + 1); + + if ($col == $smilies_split_row) + { + if ($mode == 'inline' && $row == $inline_rows - 1) + { + break; + } + $col = 0; + $row++; + } + else + { + $col++; + } + } + + if ($mode == 'inline' && $num_smilies > $inline_rows * $inline_columns) + { + $template->assign_block_vars('switch_smilies_extra', array()); + + $template->assign_vars(array( + 'L_MORE_SMILIES' => $lang['More_emoticons'], + 'U_MORE_SMILIES' => mx3_append_sid(PHPBB_URL . "posting.$phpEx", "mode=smilies")) + ); + } + + $template->assign_vars(array( + 'L_EMOTICONS' => $lang['Emoticons'], + 'L_CLOSE_WINDOW' => $lang['Close_window'], + 'S_SMILIES_COLSPAN' => $s_colspan) + ); + } + } + + if ($mode == 'window') + { + $template->pparse('smiliesbody'); + include($mx_root_path . 'includes/page_tail.'.$phpEx); + } + } +} +?> \ No newline at end of file diff --git a/includes/sessions/rhea/constants.php b/includes/sessions/rhea/constants.php new file mode 100644 index 00000000..66c971a2 --- /dev/null +++ b/includes/sessions/rhea/constants.php @@ -0,0 +1,263 @@ + @define +* to supress any notices since in mx_constants.php some are allready @@defined +*/ + +// User related +@define('ANONYMOUS', 1); + +@define('USER_ACTIVATION_NONE', 0); +@define('USER_ACTIVATION_SELF', 1); +@define('USER_ACTIVATION_ADMIN', 2); +@define('USER_ACTIVATION_DISABLE', 3); + +@define('AVATAR_UPLOAD', 1); +@define('AVATAR_REMOTE', 2); +@define('AVATAR_GALLERY', 3); + +@define('USER_NORMAL', 0); +@define('USER_INACTIVE', 1); +@define('USER_IGNORE', 2); +@define('USER_FOUNDER', 3); + +@define('INACTIVE_REGISTER', 1); +@define('INACTIVE_PROFILE', 2); +@define('INACTIVE_MANUAL', 3); +@define('INACTIVE_REMIND', 4); + +// ACL +@define('ACL_NEVER', 0); +@define('ACL_YES', 1); +@define('ACL_NO', -1); + +// Login error codes +@define('LOGIN_CONTINUE', 1); +@define('LOGIN_BREAK', 2); +@define('LOGIN_SUCCESS', 3); +@define('LOGIN_SUCCESS_CREATE_PROFILE', 20); +@define('LOGIN_ERROR_USERNAME', 10); +@define('LOGIN_ERROR_PASSWORD', 11); +@define('LOGIN_ERROR_ACTIVE', 12); +@define('LOGIN_ERROR_ATTEMPTS', 13); +@define('LOGIN_ERROR_EXTERNAL_AUTH', 14); +@define('LOGIN_ERROR_PASSWORD_CONVERT', 15); + +// SQL codes phpBB2 +@define('BEGIN_TRANSACTION', 1); +@define('END_TRANSACTION', 2); + +// Error codes (from phpbb2) +@define('GENERAL_MESSAGE', 200); +@define('GENERAL_ERROR', 202); +@define('CRITICAL_MESSAGE', 203); +@define('CRITICAL_ERROR', 204); + +// Group settings +@define('GROUP_OPEN', 0); +@define('GROUP_CLOSED', 1); +@define('GROUP_HIDDEN', 2); +@define('GROUP_SPECIAL', 3); +@define('GROUP_FREE', 4); + +// Forum/Topic states +@define('FORUM_CAT', 0); +@define('FORUM_POST', 1); +@define('FORUM_LINK', 2); +@define('ITEM_UNLOCKED', 0); +@define('ITEM_LOCKED', 1); +@define('ITEM_MOVED', 2); + +// Forum Flags +@define('FORUM_FLAG_LINK_TRACK', 1); +@define('FORUM_FLAG_PRUNE_POLL', 2); +@define('FORUM_FLAG_PRUNE_ANNOUNCE', 4); +@define('FORUM_FLAG_PRUNE_STICKY', 8); +@define('FORUM_FLAG_ACTIVE_TOPICS', 16); +@define('FORUM_FLAG_POST_REVIEW', 32); + +// Optional text flags +@define('OPTION_FLAG_BBCODE', 1); +@define('OPTION_FLAG_SMILIES', 2); +@define('OPTION_FLAG_LINKS', 4); + +// Topic types +@define('POST_NORMAL', 0); +@define('POST_STICKY', 1); +@define('POST_ANNOUNCE', 2); +@define('POST_GLOBAL', 3); + +// Lastread types +@define('TRACK_NORMAL', 0); +@define('TRACK_POSTED', 1); + +// Notify methods +@define('NOTIFY_EMAIL', 0); +@define('NOTIFY_IM', 1); +@define('NOTIFY_BOTH', 2); + +// Email Priority Settings +@define('MAIL_LOW_PRIORITY', 4); +@define('MAIL_NORMAL_PRIORITY', 3); +@define('MAIL_HIGH_PRIORITY', 2); + +// Log types +@define('LOG_ADMIN', 0); +@define('LOG_MOD', 1); +@define('LOG_CRITICAL', 2); +@define('LOG_USERS', 3); + +// Private messaging - Do NOT change these values +@define('PRIVMSGS_HOLD_BOX', -4); +@define('PRIVMSGS_NO_BOX', -3); +@define('PRIVMSGS_OUTBOX', -2); +@define('PRIVMSGS_SENTBOX', -1); +@define('PRIVMSGS_INBOX', 0); + +// Full Folder Actions +@define('FULL_FOLDER_NONE', -3); +@define('FULL_FOLDER_DELETE', -2); +@define('FULL_FOLDER_HOLD', -1); + +// Download Modes - Attachments +@define('INLINE_LINK', 1); +// This mode is only used internally to allow modders extending the attachment functionality +@define('PHYSICAL_LINK', 2); + +// Confirm types +@define('CONFIRM_REG', 1); +@define('CONFIRM_LOGIN', 2); +@define('CONFIRM_POST', 3); + +// Categories - Attachments +@define('ATTACHMENT_CATEGORY_NONE', 0); +@define('ATTACHMENT_CATEGORY_IMAGE', 1); // Inline Images +@define('ATTACHMENT_CATEGORY_WM', 2); // Windows Media Files - Streaming +@define('ATTACHMENT_CATEGORY_RM', 3); // Real Media Files - Streaming +@define('ATTACHMENT_CATEGORY_THUMB', 4); // Not used within the database, only while displaying posts +@define('ATTACHMENT_CATEGORY_FLASH', 5); // Flash/SWF files +@define('ATTACHMENT_CATEGORY_QUICKTIME', 6); // Quicktime/Mov files + +// BBCode UID length +@define('BBCODE_UID_LEN', 5); + +// Number of core BBCodes +@define('NUM_CORE_BBCODES', 12); + +// Magic url types +@define('MAGIC_URL_EMAIL', 1); +@define('MAGIC_URL_FULL', 2); +@define('MAGIC_URL_LOCAL', 3); +@define('MAGIC_URL_WWW', 4); + +// Profile Field Types +@define('FIELD_INT', 1); +@define('FIELD_STRING', 2); +@define('FIELD_TEXT', 3); +@define('FIELD_BOOL', 4); +@define('FIELD_DROPDOWN', 5); +@define('FIELD_DATE', 6); + +// referer validation +define('REFERER_VALIDATE_NONE', 0); +define('REFERER_VALIDATE_HOST', 1); +define('REFERER_VALIDATE_PATH', 2); + +// phpbb_chmod() permissions +@define('CHMOD_ALL', 7); +@define('CHMOD_READ', 4); +@define('CHMOD_WRITE', 2); +@define('CHMOD_EXECUTE', 1); + +// Captcha code length +define('CAPTCHA_MIN_CHARS', 4); +define('CAPTCHA_MAX_CHARS', 7); + +// Additional constants +define('VOTE_CONVERTED', 127); + +// Additional constants +@define('RANKS_PATH', 'images/ranks/'); + +// Table names +@define('ACL_GROUPS_TABLE', $table_prefix . 'acl_groups'); +@define('ACL_OPTIONS_TABLE', $table_prefix . 'acl_options'); +@define('ACL_ROLES_DATA_TABLE', $table_prefix . 'acl_roles_data'); +@define('ACL_ROLES_TABLE', $table_prefix . 'acl_roles'); +@define('ACL_USERS_TABLE', $table_prefix . 'acl_users'); +@define('ATTACHMENTS_TABLE', $table_prefix . 'attachments'); +@define('BANLIST_TABLE', $table_prefix . 'banlist'); +@define('BBCODES_TABLE', $table_prefix . 'bbcodes'); +@define('BOOKMARKS_TABLE', $table_prefix . 'bookmarks'); +@define('BOTS_TABLE', $table_prefix . 'bots'); +@define('CONFIG_TABLE', $table_prefix . 'config'); +@define('CONFIRM_TABLE', $table_prefix . 'confirm'); +@define('DISALLOW_TABLE', $table_prefix . 'disallow'); +@define('DRAFTS_TABLE', $table_prefix . 'drafts'); +@define('EXTENSIONS_TABLE', $table_prefix . 'extensions'); +@define('EXTENSION_GROUPS_TABLE', $table_prefix . 'extension_groups'); +@define('FORUMS_TABLE', $table_prefix . 'forums'); +@define('FORUMS_ACCESS_TABLE', $table_prefix . 'forums_access'); +@define('FORUMS_TRACK_TABLE', $table_prefix . 'forums_track'); +@define('FORUMS_WATCH_TABLE', $table_prefix . 'forums_watch'); +@define('GROUPS_TABLE', $table_prefix . 'groups'); +@define('ICONS_TABLE', $table_prefix . 'icons'); +@define('LANG_TABLE', $table_prefix . 'lang'); +@define('LOG_TABLE', $table_prefix . 'log'); +@define('MODERATOR_CACHE_TABLE', $table_prefix . 'moderator_cache'); +@define('MODULES_TABLE', $table_prefix . 'modules'); +@define('POLL_OPTIONS_TABLE', $table_prefix . 'poll_options'); +@define('POLL_VOTES_TABLE', $table_prefix . 'poll_votes'); +@define('POSTS_TABLE', $table_prefix . 'posts'); +@define('PRIVMSGS_TABLE', $table_prefix . 'privmsgs'); +@define('PRIVMSGS_FOLDER_TABLE', $table_prefix . 'privmsgs_folder'); +@define('PRIVMSGS_RULES_TABLE', $table_prefix . 'privmsgs_rules'); +@define('PRIVMSGS_TO_TABLE', $table_prefix . 'privmsgs_to'); +@define('PROFILE_FIELDS_TABLE', $table_prefix . 'profile_fields'); +@define('PROFILE_FIELDS_DATA_TABLE', $table_prefix . 'profile_fields_data'); +@define('PROFILE_FIELDS_LANG_TABLE', $table_prefix . 'profile_fields_lang'); +@define('PROFILE_LANG_TABLE', $table_prefix . 'profile_lang'); +@define('RANKS_TABLE', $table_prefix . 'ranks'); +@define('REPORTS_TABLE', $table_prefix . 'reports'); +@define('REPORTS_REASONS_TABLE', $table_prefix . 'reports_reasons'); +@define('SEARCH_RESULTS_TABLE', $table_prefix . 'search_results'); +@define('SEARCH_WORDLIST_TABLE', $table_prefix . 'search_wordlist'); +@define('SEARCH_WORDMATCH_TABLE', $table_prefix . 'search_wordmatch'); +@define('SESSIONS_TABLE', $table_prefix . 'sessions'); +@define('SESSIONS_KEYS_TABLE', $table_prefix . 'sessions_keys'); +@define('SITELIST_TABLE', $table_prefix . 'sitelist'); +@define('SMILIES_TABLE', $table_prefix . 'smilies'); +@define('STYLES_TABLE', $table_prefix . 'styles'); +@define('STYLES_TEMPLATE_TABLE', $table_prefix . 'styles_template'); +@define('STYLES_TEMPLATE_DATA_TABLE',$table_prefix . 'styles_template_data'); +@define('STYLES_THEME_TABLE', $table_prefix . 'styles_theme'); +@define('STYLES_IMAGESET_TABLE', $table_prefix . 'styles_imageset'); +@define('STYLES_IMAGESET_DATA_TABLE',$table_prefix . 'styles_imageset_data'); +@define('TOPICS_TABLE', $table_prefix . 'topics'); +@define('TOPICS_POSTED_TABLE', $table_prefix . 'topics_posted'); +@define('TOPICS_TRACK_TABLE', $table_prefix . 'topics_track'); +@define('TOPICS_WATCH_TABLE', $table_prefix . 'topics_watch'); +@define('USER_GROUP_TABLE', $table_prefix . 'user_group'); +@define('USERS_TABLE', $table_prefix . 'users'); +@define('WARNINGS_TABLE', $table_prefix . 'warnings'); +@define('WORDS_TABLE', $table_prefix . 'words'); +@define('ZEBRA_TABLE', $table_prefix . 'zebra'); + +// Additional tables + +// Additional constants +@define('INHERIT_LANG_NONE', 0); +@define('INHERIT_LANG_EN', 1); +@define('INHERIT_LANG_DEFAULT', 2); +?> \ No newline at end of file diff --git a/includes/sessions/rhea/core.php b/includes/sessions/rhea/core.php new file mode 100644 index 00000000..a4053c00 --- /dev/null +++ b/includes/sessions/rhea/core.php @@ -0,0 +1,1780 @@ +acl_getf('f_read', false)) + { + if ($user->data['user_id'] != ANONYMOUS) + { + //trigger_error('SORRY_AUTH_READ'); + $auth_data_sql = false; + } + //login_box('', $user->lang['LOGIN_VIEWFORUM']); + $auth_data_sql = $this->acl_getf_global('m_'); + } + // + // Loop through the list of forums to retrieve the ids for + // those with AUTH_VIEW allowed. + // + foreach( $is_auth_ary as $fid => $is_auth_row ) + { + if( ($is_auth_row['f_read']) ) + { + $auth_data_sql .= ( $auth_data_sql != '' ) ? ', ' . $fid : $fid; + } + } + if( empty($auth_data_sql) ) + { + $auth_data_sql = 0; + } + $userdata[$userdata_key] = $auth_data_sql; + return $auth_data_sql; + } + + /** + * function acl_getfignore() + * $auth_level_read can be a value or array; + * $ignore_forum_ids can have this sintax: forum_id(1), forum_id(2), ..., forum_is(n); + * 1st test 25.06.2008 by FlorinCB + */ + function acl_getfignore($auth_level_read, $ignore_forum_ids) + { + global $phpbb_root_path, $mx_user; + + $ignore_forum_ids = ($ignore_forum_ids) ? $ignore_forum_ids : ''; + + $auth_user = array(); + + if (is_array($auth_level_read)) + { + foreach ($auth_level_read as $auth_level) + { + $auth_user = $this->acl_getf('!' . $auth_level, true); + + if ($num_forums = count($auth_user)) + { + while ( list($forum_id, $auth_mod) = each($auth_user) ) + { + $unauthed = false; + + if (!$auth_mod[$auth_level] && ( strstr($ignore_forum_ids,$auth_mod['forum_id']) === FALSE)) + { + $unauthed = true; + } + + if ($unauthed) + { + $ignore_forum_ids .= ($ignore_forum_ids) ? ',' . $forum_id : $forum_id; + } + } + } + unset($auth_level_read); + } + } + elseif ($auth_level_read) + { + $auth_user = $this->acl_getf('!' . $auth_level_read, true); + + if ($num_forums = count($auth_user)) + { + while ( list($forum_id, $auth_mod) = each($auth_user) ) + { + $unauthed = false; + + if (!$auth_mod[$auth_level] && ( strstr($ignore_forum_ids,$auth_mod['forum_id']) === FALSE)) + { + $unauthed = true; + } + + if ($unauthed) + { + $ignore_forum_ids .= ($ignore_forum_ids) ? ',' . $forum_id : $forum_id; + } + } + } + + } + $ignore_forum_ids = ($ignore_forum_ids) ? $ignore_forum_ids : 0; + return $ignore_forum_ids; + } +} + +// +// Init the phpbb_auth class +// +$phpbb_auth = new phpbb_auth(); + +/** +* Backend specific tasks +* @package MX-Publisher +*/ +class mx_backend +{ + // + // XS Template - use backend db settings + // + var $edit_db = true; + + /** + * Validate backend + * + * Define Users/Group/Sessions backend, and validate + * Set $phpbb_root_path, $tplEx, $table_prefix + * + */ + function validate_backend() + { + global $db, $portal_config, $phpbb_root_path, $mx_root_path; + global $table_prefix, $phpEx, $tplEx; + + $table_prefix = false; + $tplEx = 'html'; + // Define relative path to phpBB, and validate + $phpbb_root_path = $mx_root_path . $portal_config['portal_backend_path']; + str_replace("//", "/", $phpbb_root_path); + $portal_backend_valid_file = @file_exists($phpbb_root_path . "mcp.$phpEx"); + + // Load phpbb config.php (to get table prefix) + if ((include $phpbb_root_path . "config.$phpEx") === false) + { + die('Configuration file (config) ' . $phpbb_root_path . "config.$phpEx" . ' couldn\'t be opened.'); + } + + // Validate db connection for backend + $_result = $db->sql_query("SELECT config_value from " . $table_prefix . "config WHERE config_name = 'cookie_domain'"); + $portal_backend_valid_db = $db->sql_numrows($_result) != 0; + + return $portal_backend_valid_file && !empty($table_prefix) && $portal_backend_valid_db; + } + + /** + * setup_backend + * + * Define some general backend definitions + * PORTAL_URL, PHPBB_URL, PORTAL_VERSION & $board_config + * + */ + function setup_backend() + { + global $portal_config, $board_config, $phpbb_root_path, $phpEx; + + $script_name = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($portal_config['script_path'])); + $server_name = trim($portal_config['server_name']); + $server_protocol = ( $portal_config['cookie_secure'] ) ? 'https://' : 'http://'; + $server_port = (($portal_config['server_port']) && ($portal_config['server_port'] <> 80)) ? ':' . trim($portal_config['server_port']) . '/' : '/'; + + $server_url = $server_protocol . str_replace("//", "/", $server_name . $server_port . $script_name . '/'); //On some server the slash is not added and this trick will fix it + + define('PORTAL_URL', $server_url); + define('PORTAL_VERSION', $portal_config['portal_version']); + + // + // Grab phpBB global variables, re-cache if necessary + // - optional parameter to enable/disable cache for config data. If enabled, remember to refresh the MX-Publisher cache whenever updating phpBB config settings + // - true: enable cache, false: disable cache + $board_config = $this->obtain_phpbb_config(false); + $script_name_phpbb = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($board_config['script_path'])) . '/'; + + $server_url_phpbb = $server_protocol . $server_name . $server_port . $script_name_phpbb; + define('PHPBB_URL', $server_url_phpbb); + + // Define backend template extension + $tplEx = 'html'; + if (!defined('TPL_EXT')) define('TPL_EXT', $tplEx); + // + // Now sync Configs + // In phpBB mode, we rely on native phpBB configs, thus we need to sync mxp and phpbb settings + // + $this->sync_configs(); + } + + /** + * Sync Configs + * @access private + */ + function sync_configs() + { + global $portal_config, $board_config; + + foreach ($portal_config as $key => $value) + { + $do = true; + switch ($key) + { + // + // Keep phpBB cookies/sessions + // + case 'cookie_domain': + case 'cookie_name': + case 'cookie_path': + case 'cookie_secure': + case 'session_length': + case 'allow_autologin': + case 'max_autologin_time': + case 'max_login_attempts': + case 'login_reset_time': + + $do = false; + break; + + // + // Keep phpBB stats + // + case 'record_online_users': + case 'record_online_date': + + $do = false; + break; + + // + // Keep portal settings + // + case 'default_style': + case 'override_user_style': + case 'default_lang': + + // + // Keep portal settings + // + case 'allow_html': + case 'allow_html_tags': + case 'allow_bbcode': + case 'allow_smilies': + case 'smilies_path': + + // + // Keep portal settings + // + case 'board_email': + case 'board_email_sig': + case 'smtp_delivery': + case 'smtp_host': + case 'smtp_username': + case 'smtp_password': + case 'smtp_auth_method': + + // + // Keep portal settings + // + case 'default_dateformat': + case 'board_timezone': + case 'gzip_compress': + + // + // Keep portal settings + // + case 'portal_id': + case 'portal_status': + case 'disabled_message': + case 'script_path': + case 'mx_use_cache': + case 'mod_rewrite': + case 'default_admin_style': + case 'overall_header': + case 'overall_footer': + case 'main_layout': + case 'navigation_block': + case 'top_phpbb_links': + case 'portal_version': + case 'portal_recached': + case 'portal_backend': + case 'portal_startdate': + case 'rand_seed': + + break; + + // Rename config keys and get internal sitename/sitedesc + case 'portal_name': + + $key = 'sitename'; + break; + + case 'portal_desc': + + $key = 'site_desc'; + break; + } + + if ($do) + { + $board_config[$key] = $value; + } + } + } + + /** + * load_file + * + * @param unknown_type $force_shared + * @access private + */ + function load_file($force_shared) + { + global $mx_root_path, $phpbb_root_path, $phpEx; + + if ($force_shared) + { + $backend = in_array($force_shared, array('internal', 'phpbb2', 'phpbb3')) ? $force_shared : PORTAL_BACKEND; + switch ($backend) + { + case 'internal': + case 'phpbb2': + case 'smf2': + case 'mybb': + $path = $mx_root_path . 'includes/shared/phpbb2/includes/'; + break; + + case 'phpbb3': + case 'olympus': + case 'ascraeus': + case 'rhea': + $path = $mx_root_path . 'includes/shared/phpbb3/includes/'; + break; + } + } + else + { + $path = $phpbb_root_path . 'includes/'; + } + return $path; + } + + /** + * dss_rand + * + * @param unknown_type $force_shared + * @access private + */ + function dss_rand() + { + global $db, $portal_config, $board_config, $dss_seeded; + + $val = $board_config['rand_seed'] . microtime(); + $val = md5($val); + $board_config['rand_seed'] = md5($board_config['rand_seed'] . $val . 'a'); + + if($dss_seeded !== true) + { + $sql = "UPDATE " . CONFIG_TABLE . " SET + config_value = '" . $board_config['rand_seed'] . "' + WHERE config_name = 'rand_seed'"; + //display an error debuging message only if the portal is installed/upgraded + if(!@$db->sql_query($sql) && @!file_exists('install')) + { + mx_message_die(GENERAL_ERROR, "Unable to reseed PRNG", "", __LINE__, __FILE__, $sql); + } + elseif(!@$db->sql_query($sql) && @file_exists('install')) + { + mx_message_die(GENERAL_ERROR, "Unable to reseed PRNG"."
Please finish upgrading and
". t(isset($lang['Please_remove_install_contrib'])), "", __LINE__, __FILE__, $sql); + } + $dss_seeded = true; + } + return substr($val, 4, 16); + } + + function make_jumpbox($action, $match_forum_id = 0) + { + global $template, $userdata, $lang, $db, $nav_links, $phpEx, $SID; + + $sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id + FROM ' . FORUMS_TABLE . ' + ORDER BY left_id ASC'; + $result = $db->sql_query($sql, 600); + + $right = $padding = 0; + $padding_store = array('0' => 0); + $display_jumpbox = false; + $iteration = 0; + + // Sometimes it could happen that forums will be displayed here not be displayed within the index page + // This is the result of forums not displayed at index, having list permissions and a parent of a forum with no permissions. + // If this happens, the padding could be "broken" + + $forum_rows = array(); + while ($row = $db->sql_fetchrow($result)) + { + $forum_rows[] = $row; + + if ($forum_rows['left_id'] < $right) + { + $padding++; + $padding_store[$row['parent_id']] = $padding; + } + else if ($row['left_id'] > $right + 1) + { + // Ok, if the $padding_store for this parent is empty there is something wrong. For now we will skip over it. + // @todo digging deep to find out "how" this can happen. + $padding = (isset($padding_store[$row['parent_id']])) ? $padding_store[$row['parent_id']] : $padding; + } + + $right = $forum_rows['right_id']; + + if ($forum_rows['forum_type'] == FORUM_CAT && ($forum_rows['left_id'] + 1 == $forum_rows['right_id'])) + { + // Non-postable forum with no subforums, don't display + continue; + } + + if ( $total_forums = count($forum_rows) ) + { + for($i = 0; $i < $total_categories; $i++) + { + $boxstring_forums = ''; + for($j = 0; $j < $total_forums; $j++) + { + $selected = ( $forum_rows[$j]['forum_id'] == $match_forum_id ) ? 'selected="selected"' : ''; + $boxstring_forums .= ''; + + // + // Add an array to $nav_links for the Mozilla navigation bar. + // 'chapter' and 'forum' can create multiple items, therefore we are using a nested array. + // + $nav_links['chapter forum'][$forum_rows[$j]['forum_id']] = array ( + 'url' => mx_append_sid(PHPBB_URL . "viewforum.$phpEx?" . POST_FORUM_URL . "=" . $forum_rows[$j]['forum_id']), + 'title' => $forum_rows[$j]['forum_name'] + ); + + } + + if ( $boxstring_forums != '' ) + { + $boxstring .= ''; + $boxstring .= ''; + $boxstring .= ''; + $boxstring .= $boxstring_forums; + } + } + } + + $boxstring .= ''; + } + + // Let the jumpbox work again in sites having additional session id checks. + // if ( !empty($SID) ) + // { + $boxstring .= ''; + // } + + $template->set_filenames(array( + 'jumpbox' => 'jumpbox.tpl') + ); + + $template->assign_vars(array( + 'L_GO' => $lang['Go'], + 'L_JUMP_TO' => $lang['Jump_to'], + 'L_SELECT_FORUM' => $lang['Select_forum'], + + 'S_JUMPBOX_SELECT' => $boxstring, + 'S_JUMPBOX_ACTION' => mx_append_sid($action), + 'S_FORUM_COUNT' => $j) + ); + + $template->assign_var_from_handle('JUMPBOX', 'jumpbox'); + + return; + } + + /** + * Backend specific Page Header data + * + * @param unknown_type $mode + */ + function page_header($mode = false) + { + global $db, $mx_root_path, $phpbb_root_path, $userdata, $mx_user, $lang, $images, $phpEx, $board_config, $gen_simple_header, $layouttemplate, $mx_page; + + switch ($mode) + { + case 'generate_login_logout_stats': + + if ( $mx_user->data['user_id'] != 1 ) + { + $is_logged = true; + $u_login_logout = 'login.'.$phpEx.'?logout=true&sid=' . $mx_user->data['session_id']; + $l_login_logout = $lang['Logout'] . ' [ ' . $mx_user->data['username'] . ' ]'; + } + else + { + $is_logged = false; + $u_login_logout = 'login.'.$phpEx; + $l_login_logout = $lang['Login']; + } + $s_last_visit = ( $mx_user->data['session_logged_in'] ) ? phpBB2::create_date($board_config['default_dateformat'], $mx_user->data['user_lastvisit'], $board_config['board_timezone']) : ''; + + // + // Obtain number of new private messages + // if user is logged in + // + if ( ($mx_user->data['session_logged_in']) && (empty($gen_simple_header)) ) + { + if ( $mx_user->data['user_new_privmsg'] ) + { + $l_message_new = ( $mx_user->data['user_new_privmsg'] == 1 ) ? $lang['New_pm'] : $lang['New_pms']; + $l_privmsgs_text = sprintf($l_message_new, $mx_user->data['user_new_privmsg']); + + if ( $mx_user->data['user_last_privmsg'] > $mx_user->data['user_lastvisit'] ) + { + $sql = "UPDATE " . USERS_TABLE . " + SET user_last_privmsg = " . $mx_user->data['user_lastvisit'] . " + WHERE user_id = " . $mx_user->data['user_id']; + if ( !$db->sql_query($sql) ) + { + mx_message_die(GENERAL_ERROR, 'Could not update private message new/read time for user', '', __LINE__, __FILE__, $sql); + } + + $s_privmsg_new = 1; + $icon_pm = $images['pm_new_msg']; + } + else + { + $s_privmsg_new = 0; + $icon_pm = $images['pm_no_new_msg']; + } + $mx_priv_msg = $lang['Private_Messages'] . ' (' . $mx_user->data['user_new_privmsg'] . ')'; + } + else + { + $l_privmsgs_text = $lang['No_new_pm']; + + $s_privmsg_new = 0; + $icon_pm = $images['pm_no_new_msg']; + $mx_priv_msg = $lang['Private_Messages']; + } + + if ( $mx_user->data['user_unread_privmsg'] ) + { + $l_message_unread = ( $mx_user->data['user_unread_privmsg'] == 1 ) ? $lang['Unread_pm'] : $lang['Unread_pms']; + $l_privmsgs_text_unread = sprintf($l_message_unread, $mx_user->data['user_unread_privmsg']); + } + else + { + $l_privmsgs_text_unread = $lang['No_unread_pm']; + } + } + else + { + $icon_pm = $images['pm_no_new_msg']; + $l_privmsgs_text = $lang['Login_check_pm']; + $l_privmsgs_text_unread = ''; + $s_privmsg_new = 0; + $mx_priv_msg = $lang['Private_Messages']; + } + + $layouttemplate->assign_vars(array( + 'U_LOGIN_LOGOUT' => mx_append_sid(PORTAL_URL . $u_login_logout), + 'L_LOGIN_LOGOUT' => $l_login_logout, + 'LAST_VISIT_DATE' => sprintf($lang['You_last_visit'], $s_last_visit), + 'PRIVATE_MESSAGE_INFO' => $l_privmsgs_text, + 'PRIVATE_MESSAGE_INFO_UNREAD' => $l_privmsgs_text_unread, + 'PRIVATE_MESSAGE_NEW_FLAG' => $s_privmsg_new, + 'PRIVMSG_IMG' => $icon_pm, + 'L_PRIVATEMSGS' => $mx_priv_msg, + + // Backend + 'PHPBB' => true, + + // Show phpbb stats? + 'PHPBB_STATS' => $mx_page->phpbb_stats, + + // Allow autologin? + 'ALLOW_AUTOLOGIN' => !$userdata['session_logged_in'] && (!isset($board_config['allow_autologin']) || $board_config['allow_autologin']), + + // phpBB PM + 'ENABLE_PM_POPUP' => $userdata['session_logged_in'] && !empty($userdata['user_popup_pm']), + )); + + break; + + case 'generate_nav_links': + + $u_register = 'ucp.'.$phpEx.'?mode=register'; + $u_profile = 'ucp.'.$phpEx; + $u_privatemsgs = 'ucp.'.$phpEx.'?i=pm&folder=inbox'; + $u_privatemsgs_popup ='ucp.'.$phpEx.'?i=pm&mode=popup'; + $u_search = 'search.'.$phpEx; + $u_memberlist = 'memberlist.'.$phpEx; + $u_modcp = 'mcp.'.$phpEx; + $u_faq = 'faq.'.$phpEx; + $u_viewonline = 'viewonline.'.$phpEx; + $u_group_cp = 'ucp.'.$phpEx.'?i=167'; + $u_sendpassword = ($board_config['email_enable']) ? mx3_append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=sendpassword') : ''; + + $layouttemplate->assign_vars(array( + 'U_REGISTER' => mx_append_sid(PHPBB_URL . $u_register), + 'U_PROFILE' => mx_append_sid(PHPBB_URL . $u_profile), + 'U_PRIVATEMSGS' => mx_append_sid(PHPBB_URL . $u_privatemsgs), + 'U_PRIVATEMSGS_POPUP' => mx_append_sid(PHPBB_URL . $u_privatemsgs_popup), + 'U_SEARCH' => mx_append_sid(PHPBB_URL . $u_search), + 'U_MEMBERLIST' =>mx_append_sid(PHPBB_URL . $u_memberlist), + 'U_MODCP' => mx_append_sid(PHPBB_URL . $u_modcp), + 'U_FAQ' => mx_append_sid(PHPBB_URL . $u_faq), + 'U_VIEWONLINE' => mx_append_sid(PHPBB_URL . $u_viewonline), + 'U_GROUP_CP' => mx_append_sid(PHPBB_URL . $u_group_cp), + 'U_SEND_PASSWORD' => $u_sendpassword, + )); + + break; + } + } + + /** + * Backend specific Page Tail data + * + * @param unknown_type $mode + */ + function page_tail($mode = false) + { + global $board_config, $userdata, $template; + + switch ($mode) + { + case 'generate_backend_version': + $current_phpbb_version = $board_config['version']; + + $template->assign_vars(array( + 'PHPBB_BACKEND' => true, + 'PHPBB_VERSION' => ($userdata['user_level'] == ADMIN && $userdata['user_id'] != ANONYMOUS) ? $current_phpbb_version : '', + 'U_PHPBB_ROOT_PATH' => PHPBB_URL, + )); + + break; + } + } + + + /** + * obtain_phpbb_config + * + * @access public + * @param boolean $use_cache + * @return unknown + */ + public function obtain_forum_config() + { + global $db, $mx_cache, $phpEx; + + if (!defined('CONFIG_TABLE')) + { + global $table_prefix, $mx_root_path; + + require $mx_root_path. "includes/sessions/phpbb2/constants.$phpEx"; + } + + if (($mx_cache->get('phpbb_config')) === false) + { + $config = $cached_config = array(); + + $sql = 'SELECT config_name, config_value, is_dynamic + FROM ' . CONFIG_TABLE; + if (!($result = $db->sql_query($sql))) + { + if (!function_exists('mx_message_die')) + { + die("Couldnt query config information, Allso this hosting or server is using a cache optimizer not compatible with MX-Publisher or just lost connection to database wile query."); + } + else + { + mx_message_die( GENERAL_ERROR, 'Couldnt query config information', '', __LINE__, __FILE__, $sql ); + } + } + + while ($row = $db->sql_fetchrow($result)) + { + if (!$row['is_dynamic']) + { + $cached_config[$row['config_name']] = $row['config_value']; + } + + $config[$row['config_name']] = $row['config_value']; + } + $db->sql_freeresult($result); + + $mx_cache->put('phpbb_config', $cached_config); + } + else + { + $sql = 'SELECT config_name, config_value + FROM ' . CONFIG_TABLE . ' + WHERE is_dynamic = 1'; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $config[$row['config_name']] = $row['config_value']; + } + $db->sql_freeresult($result); + } + + return $config; + } + + /** + * Set phpbb config values + * + * @param unknown_type $config_name + * @param unknown_type $config_value + */ + public function set_forum_config($key, $new_value, $use_cache = false) + { + global $db, $mx_cache, $phpEx; + + if (!defined('CONFIG_TABLE')) + { + global $table_prefix, $mx_root_path; + + require $mx_root_path. "includes/sessions/phpbb2/constants.$phpEx"; + } + + // Read out config values + $config = $this->obtain_phpbb_config(); + $old_value = !isset($config[$key]) ? $config[$key] : false; + $use_cache = (($key == 'comments_pagination') || ($key == 'pagination')) ? true : false; + + $sql = 'UPDATE ' . CONFIG_TABLE . " + SET config_value = '" . $db->sql_escape($new_value) . "' + WHERE config_name = '" . $db->sql_escape($key) . "'"; + + if ($old_value !== false) + { + $sql .= " AND config_value = '" . $db->sql_escape($old_value) . "'"; + } + + $db->sql_query($sql); + + if (!$db->sql_affectedrows() && isset($config[$key])) + { + return false; + } + + if (!isset($config[$key])) + { + $sql = 'INSERT INTO ' . CONFIG_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'config_name' => $key, + 'config_value' => $new_value)), + 'is_dynamic' => ($use_cache) ? 0 : 1)); + $db->sql_query($sql); + } + + $config[$key] = $new_value; + + + if ($use_cache) + { + $mx_cache->destroy('config'); + $mx_cache->put('config', $config); + } + + return true; + } + + /** + * Get MX-Publisher config data + * + * @access public + * @return unknown + */ + public function obtain_portal_config($use_cache = true) + { + global $db, $mx_cache; + + if ( ($portal_config = $mx_cache->get('mx_config')) && ($use_cache) ) + { + return $portal_config; + } + else + { + $sql = "SELECT * + FROM " . PORTAL_TABLE . " + WHERE portal_id = '1'"; + + if ( !($result = $db->sql_query($sql)) ) + { + if (!function_exists('mx_message_die')) + { + die("Couldnt query portal configuration, Allso this hosting or server is using a cache optimizer not compatible with MX-Publisher or just lost connection to database wile query."); + } + else + { + mx_message_die( GENERAL_ERROR, 'Couldnt query portal configuration', '', __LINE__, __FILE__, $sql ); + } + } + $row = $db->sql_fetchrow($result); + foreach ($row as $config_name => $config_value) + { + $portal_config[$config_name] = trim($config_value); + } + $db->sql_freeresult($result); + $mx_cache->put('mx_config', $portal_config); + + return ($portal_config); + } + } + + /** + * Set config value. Creates missing config entry. + * + */ + function set_portal_config($key, $new_value) + { + global $db, $mx_cache, $portal_config; + + // Read out config values + $portal_config = $this->obtain_portal_config(); + + $new[$key] = $new_value; + + $sql = "UPDATE " . PORTAL_TABLE . " SET " . $db->sql_build_array('UPDATE', utf8_normalize_nfc($new)); + + if( !($db->sql_query($sql)) ) + { + mx_message_die(GENERAL_ERROR, "Failed to update portal configuration ", "", __LINE__, __FILE__, $sql); + } + + if (!$db->sql_affectedrows() && !isset($portal_config[$key])) + { + $sql = 'INSERT INTO ' . PORTAL_TABLE . ' ' . $db->sql_build_array('INSERT', array( + $db->sql_escape($key) => $db->sql_escape($new_value))); + $db->sql_query($sql); + } + + $portal_config[$key] = $new_value; + + $mx_cache->destroy('mx_config'); + } + + /** + * Get userdata + * + * Get Userdata, $mx_user can be username or user_id. If force_str is true, the username will be forced. + * Cached sql, since this function is used for every block. + * + * @param unknown_type $mx_user id or name + * @param boolean $force_str force clean_username + * @return array + */ + function get_userdata($mxuser, $force_str = false) + { + global $db, $phpBB2; + + if (!is_numeric($mxuser) || $force_str) + { + $mx_user = $phpBB2->phpbb_clean_username($mxuser); + } + else + { + $mx_user = intval($mxuser); + } + + $sql = "SELECT * + FROM " . USERS_TABLE . " + WHERE "; + $sql .= ((is_integer($mxuser)) ? "user_id = $mxuser" : "username = '" . str_replace("\'", "''", $mxuser) . "'" ) . " AND user_id <> " . ANONYMOUS; + if (!($result = $db->sql_query($sql, 120))) + { + if (!function_exists('mx_message_die')) + { + die("Tried obtaining data for a non-existent user. Function mx_backend->get_userdata()"); + } + else + { + mx_message_die(GENERAL_ERROR, 'Tried obtaining data for a non-existent user', '', __LINE__, __FILE__, $sql); + } + } + $return = ($row = $db->sql_fetchrow($result)) ? $row : false; + /* + foreach ($row as $user_key => $user_value) + { + $userdata[$user_key] = trim($user_value); + } + */ + $db->sql_freeresult($result); + //return ($userdata); + return $return; + } + + /** + * Set user data value. + * + */ + function set_userdata($key, $new_value) + { + global $db, $mx_user; + + $new[$key] = $new_value; + + $sql = "UPDATE " . USERS_TABLE . " + SET " . $db->sql_build_array('UPDATE', utf8_normalize_nfc($new)) . " + WHERE user_id = '" . $mx_user->data['user_id'] . "'"; + if (!($db->sql_query($sql))) + { + mx_message_die(GENERAL_ERROR, "Failed to update portal configuration ", "", __LINE__, __FILE__, $sql); + } + + if (!$db->sql_affectedrows() && !isset($mx_user->data[$key])) + { + mx_message_die(GENERAL_ERROR, "Wrong Backend? Adding missing entry key to update MXP configuration is not supported ATM.", "", __LINE__, __FILE__, $sql); + } + $mx_user->data[$key] = $new_value; + } + + /** + * Obtain ranks + */ + function obtain_ranks() + { + global $mx_cache; + + if (($ranks = $mx_cache->get('_ranks')) === false) + { + global $db; + + $sql = 'SELECT * + FROM ' . RANKS_TABLE . ' + ORDER BY rank_min DESC'; + $result = $db->sql_query($sql); + + $ranks = array(); + while ($row = $db->sql_fetchrow($result)) + { + if ($row['rank_special']) + { + $ranks['special'][$row['rank_id']] = array( + 'rank_title' => $row['rank_title'], + 'rank_image' => $row['rank_image'] + ); + } + else + { + $ranks['normal'][] = array( + 'rank_title' => $row['rank_title'], + 'rank_min' => $row['rank_min'], + 'rank_image' => $row['rank_image'] + ); + } + } + $db->sql_freeresult($result); + + $mx_cache->put('_ranks', $ranks); + } + + return $ranks; + } + + /** + * Obtain allowed extensions + * + * @param mixed $forum_id If false then check for private messaging, if int then check for forum id. If true, then only return extension informations. + * + * @return array allowed extensions array. + */ + function obtain_attach_extensions($forum_id) + { + global $mx_cache; + + if (($extensions = $mx_cache->get('_extensions')) === false) + { + global $db; + + $extensions = array( + '_allowed_post' => array(), + '_allowed_pm' => array(), + ); + + // The rule is to only allow those extensions defined. ;) + $sql = 'SELECT e.extension, g.* + FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g + WHERE e.group_id = g.group_id + AND (g.allow_group = 1 OR g.allow_in_pm = 1)'; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $extension = strtolower(trim($row['extension'])); + + $extensions[$extension] = array( + 'display_cat' => (int) $row['cat_id'], + 'download_mode' => (int) $row['download_mode'], + 'upload_icon' => trim($row['upload_icon']), + 'max_filesize' => (int) $row['max_filesize'], + 'allow_group' => $row['allow_group'], + 'allow_in_pm' => $row['allow_in_pm'], + ); + + $allowed_forums = ($row['allowed_forums']) ? unserialize(trim($row['allowed_forums'])) : array(); + + // Store allowed extensions forum wise + if ($row['allow_group']) + { + $extensions['_allowed_post'][$extension] = (!sizeof($allowed_forums)) ? 0 : $allowed_forums; + } + + if ($row['allow_in_pm']) + { + $extensions['_allowed_pm'][$extension] = 0; + } + } + $db->sql_freeresult($result); + + $mx_cache->put('_extensions', $extensions); + } + + // Forum post + if ($forum_id === false) + { + // We are checking for private messages, therefore we only need to get the pm extensions... + $return = array('_allowed_' => array()); + + foreach ($extensions['_allowed_pm'] as $extension => $check) + { + $return['_allowed_'][$extension] = 0; + $return[$extension] = $extensions[$extension]; + } + + $extensions = $return; + } + else if ($forum_id === true) + { + return $extensions; + } + else + { + $forum_id = (int) $forum_id; + $return = array('_allowed_' => array()); + + foreach ($extensions['_allowed_post'] as $extension => $check) + { + // Check for allowed forums + if (is_array($check)) + { + $allowed = (!in_array($forum_id, $check)) ? false : true; + } + else + { + $allowed = true; + } + + if ($allowed) + { + $return['_allowed_'][$extension] = 0; + $return[$extension] = $extensions[$extension]; + } + } + + $extensions = $return; + } + + if (!isset($extensions['_allowed_'])) + { + $extensions['_allowed_'] = array(); + } + + return $extensions; + } + + /** + * Obtain active bots + */ + function obtain_bots() + { + global $mx_cache; + + if (($bots = $mx_cache->get('_bots')) === false) + { + global $db; + + switch ($db->sql_layer) + { + case 'mssql': + case 'mssql_odbc': + $sql = 'SELECT user_id, bot_agent, bot_ip + FROM ' . BOTS_TABLE . ' + WHERE bot_active = 1 + ORDER BY LEN(bot_agent) DESC'; + break; + + case 'firebird': + $sql = 'SELECT user_id, bot_agent, bot_ip + FROM ' . BOTS_TABLE . ' + WHERE bot_active = 1 + ORDER BY CHAR_LENGTH(bot_agent) DESC'; + break; + + // LENGTH supported by MySQL, IBM DB2 and Oracle for sure... + default: + $sql = 'SELECT user_id, bot_agent, bot_ip + FROM ' . BOTS_TABLE . ' + WHERE bot_active = 1 + ORDER BY LENGTH(bot_agent) DESC'; + break; + } + $result = $db->sql_query($sql); + + $bots = array(); + while ($row = $db->sql_fetchrow($result)) + { + $bots[] = $row; + } + $db->sql_freeresult($result); + + $mx_cache->put('_bots', $bots); + } + + return $bots; + } + + /** + * Obtain cfg file data + * + * @param unknown_type $theme + * @return unknown + */ + function obtain_cfg_items($theme) + { + global $board_config, $phpbb_root_path, $mx_cache; + + $parsed_items = array( + 'theme' => array(), + 'template' => array(), + 'imageset' => array() + ); + + foreach ($parsed_items as $key => $parsed_array) + { + $parsed_array = $mx_cache->get('_cfg_' . $key . '_' . $theme[$key . '_path']); + + if ($parsed_array === false) + { + $parsed_array = array(); + } + + $reparse = false; + $filename = $phpbb_root_path . 'styles/' . $theme[$key . '_path'] . '/' . $key . '/' . $key . '.cfg'; + + if (!file_exists($filename)) + { + continue; + } + + if (!isset($parsed_array['filetime']) || (($board_config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime']))) + { + $reparse = true; + } + + // Re-parse cfg file + if ($reparse) + { + $parsed_array = mx_parse_cfg_file($filename); + $parsed_array['filetime'] = @filemtime($filename); + + $mx_cache->put('_cfg_' . $key . '_' . $theme[$key . '_path'], $parsed_array); + } + $parsed_items[$key] = $parsed_array; + } + + return $parsed_items; + } + + /** + * Obtain disallowed usernames + */ + function obtain_disallowed_usernames() + { + global $mx_cache; + + if (($usernames = $mx_cache->get('_disallowed_usernames')) === false) + { + global $db; + + $sql = 'SELECT disallow_username + FROM ' . DISALLOW_TABLE; + $result = $db->sql_query($sql); + + $usernames = array(); + while ($row = $db->sql_fetchrow($result)) + { + $usernames[] = str_replace('%', '.*?', preg_quote(utf8_clean_string($row['disallow_username']), '#')); + } + $db->sql_freeresult($result); + + $mx_cache->put('_disallowed_usernames', $usernames); + } + + return $usernames; + } + + /** + * Obtain hooks... + */ + function obtain_hooks() + { + global $phpbb_root_path, $phpEx, $mx_cache; + + if (($hook_files = $mx_cache->get('_hooks')) === false) + { + $hook_files = array(); + + // Now search for hooks... + $dh = @opendir($phpbb_root_path . 'includes/hooks/'); + + if ($dh) + { + while (($file = readdir($dh)) !== false) + { + if (strpos($file, 'hook_') === 0 && substr($file, -(strlen($phpEx) + 1)) === '.' . $phpEx) + { + $hook_files[] = substr($file, 0, -(strlen($phpEx) + 1)); + } + } + closedir($dh); + } + + $mx_cache->put('_hooks', $hook_files); + } + + return $hook_files; + } + + /** + * Enter description here... + * + * @return unknown + */ + function generate_group_select_sql() + { + // Get us all the groups exept bots and guests + $sql = "SELECT g.group_id, g.group_name, g.group_type + FROM " . GROUPS_TABLE . " g + WHERE g.group_name NOT IN ('BOTS', 'GUESTS') + ORDER BY g.group_type ASC, g.group_name"; + return $sql; + } + + /** + * Enter description here... + * + * @return unknown + */ + function generate_session_online_sql($guest = false) + { + if ($guest) + { + $sql = "SELECT u.*, s.*, s.session_page AS user_session_page + FROM " . USERS_TABLE . " u, " . SESSIONS_TABLE . " s + WHERE u.user_id = " . ANONYMOUS . " + AND u.user_id = s.session_user_id + AND s.session_time >= " . ( time() - 300 ) . " + ORDER BY s.session_time DESC"; + } + else + { + $sql = "SELECT u.*, s.*, s.session_time AS user_session_time, s.session_page AS user_session_page + FROM " . USERS_TABLE . " u, " . SESSIONS_TABLE . " s + WHERE u.user_id <> " . ANONYMOUS . " + AND u.user_id = s.session_user_id + AND s.session_time >= " . ( time() - 300 ) . " + ORDER BY s.session_time DESC"; + } + return $sql; + } + + /** + * Enter description here... + * + * @param unknown_type $str_ip + * @return unknown + */ + function decode_ip($str_ip) + { + return $str_ip; + } + + /** + * Enter description here... + * + * @return unknown + */ + function get_phpbb_version() + { + global $board_config; + + return $board_config['version']; + } + + /** + * Enter description here... + * + * @return unknown + */ + function confirm_backend() + { + global $portal_config; + + return PORTAL_BACKEND == $portal_config['portal_backend']; + } + + /** + * Get username details for placing into templates. + * + * @param string $mode Can be profile (for getting an url to the profile), username (for obtaining the username), colour (for obtaining the user colour) or full (for obtaining a html string representing a coloured link to the users profile). + * @param int $user_id The users id + * @param string $username The users name + * @param string $username_colour The users colour + * @param string $guest_username optional parameter to specify the guest username. It will be used in favor of the GUEST language variable then. + * @param string $custom_profile_url optional parameter to specify a profile url. The user id get appended to this url as &u={user_id} + * + * @return string A string consisting of what is wanted based on $mode. + */ + function get_username_string($mode, $user_id, $username = false, $username_colour = '', $guest_username = false, $custom_profile_url = false) + { + global $phpbb_root_path, $mx_root_path, $phpEx, $mx_user, $phpbb_auth; + + $profile_url = ''; + + //Added by OryNider + if (($username == false) || ($username_colour == false)) + { + $this_userdata = mx_get_userdata($user_id, false); + $user_id = $this_userdata['user_id']; + $username = $this_userdata['username']; + $username_colour = $this_userdata['user_colour']; + } + //Added Ends + + $username_colour = ($username_colour) ? '#' . $username_colour : ''; + + if ($guest_username === false) + { + $username = ($username) ? $username : $mx_user->lang['GUEST']; + } + else + { + $username = ($user_id && $user_id != ANONYMOUS) ? $username : ((!empty($guest_username)) ? $guest_username : $mx_user->lang['GUEST']); + } + + // Only show the link if not anonymous + if ($user_id && $user_id != ANONYMOUS) + { + // Do not show the link if the user is already logged in but do not have u_viewprofile permissions (relevant for bots mostly). + // For all others the link leads to a login page or the profile. + if ($mx_user->data['user_id'] != ANONYMOUS && !$phpbb_auth->acl_get('u_viewprofile')) + { + $profile_url = ''; + } + else + { + $profile_url = ($custom_profile_url !== false) ? $custom_profile_url : mx3_append_sid(PHPBB_URL . "memberlist.$phpEx", 'mode=viewprofile'); + $profile_url .= '&u=' . (int) $user_id; + } + } + else + { + $profile_url = ''; + } + + switch ($mode) + { + case 'profile': + return $profile_url; + break; + + case 'username': + return $username; + break; + + case 'colour': + return $username_colour; + break; + + case 'full': + default: + + $tpl = ''; + if (!$profile_url && !$username_colour) + { + $tpl = '{USERNAME}'; + } + else if (!$profile_url && $username_colour) + { + $tpl = '{USERNAME}'; + } + else if ($profile_url && !$username_colour) + { + $tpl = '{USERNAME}'; + } + else if ($profile_url && $username_colour) + { + $tpl = '{USERNAME}'; + } + + return str_replace(array('{PROFILE_URL}', '{USERNAME_COLOUR}', '{USERNAME}'), array($profile_url, $username_colour, $username), $tpl); + break; + } + } + + // + // ACP + // + /** + * Enter description here... + * + */ + function load_phpbb_acp_menu() + { + global $phpbb_root_path, $template, $lang, $phpEx, $userdata, $mx_user; + + $template->assign_block_vars('module_phpbb', array( + 'L_PHPBB' => $lang['Phpbb'], + "L_FORUM_INDEX" => $lang['Main_index'], + "L_PREVIEW_FORUM" => $lang['Preview_forum'], + "U_FORUM_INDEX" => mx_append_sid(PHPBB_URL . "index.$phpEx"), + )); + + $menu_cat_id = 0; + + $template->assign_block_vars('module_phpbb.catrow', array( + //+MOD: DHTML Menu for ACP + 'MENU_CAT_ID' => $menu_cat_id, + 'MENU_CAT_ROWS' => 1, + //-MOD: DHTML Menu for ACP + 'ADMIN_CATEGORY' => 'Olympus adminCP') + ); + + $template->assign_block_vars('module_phpbb.catrow.modulerow', array( + "ROW_COLOR" => "#" . $mx_user->theme['td_color1'], + "ROW_CLASS" => $mx_user->theme['td_class1'], + //+MOD: DHTML Menu for ACP + 'ROW_COUNT' => 0, + //-MOD: DHTML Menu for ACP + "ADMIN_MODULE" => 'Go!', + "U_ADMIN_MODULE" => mx_append_sid($phpbb_root_path . 'adm/index.php?sid='.$mx_user->session_id)) + ); + } + + /** + * Enter description here... + * + */ + function load_forum_stats() + { + global $db, $template, $board_config, $portal_config, $phpbb_root_path, $mx_root_path, $lang, $theme, $mx_user, $userdata; + + $template->assign_block_vars("forum_stats", array()); + // + // Get forum statistics + // + $total_posts = phpBB2::get_db_stat('postcount'); + $total_users = phpBB2::get_db_stat('usercount'); + $total_topics = phpBB2::get_db_stat('topiccount'); + + $start_date = phpBB2::create_date($board_config['default_dateformat'], $board_config['board_startdate'], $board_config['board_timezone']); + + $boarddays = ( time() - $board_config['board_startdate'] ) / 86400; + + $posts_per_day = sprintf("%.2f", $total_posts / $boarddays); + $topics_per_day = sprintf("%.2f", $total_topics / $boarddays); + $users_per_day = sprintf("%.2f", $total_users / $boarddays); + + $avatar_dir_size = 0; + + if ($avatar_dir = @opendir($phpbb_root_path . $board_config['avatar_path']) ) + { + while( $file = @readdir($avatar_dir) ) + { + if( $file != "." && $file != ".." ) + { + $avatar_dir_size += @filesize($phpbb_root_path . $board_config['avatar_path'] . "/" . $file); + } + } + @closedir($avatar_dir); + + // + // This bit of code translates the avatar directory size into human readable format + // Borrowed the code from the PHP.net annoted manual, origanally written by: + // Jesse (jesse@jess.on.ca) + // + if($avatar_dir_size >= 1048576) + { + $avatar_dir_size = round($avatar_dir_size / 1048576 * 100) / 100 . " MB"; + } + else if($avatar_dir_size >= 1024) + { + $avatar_dir_size = round($avatar_dir_size / 1024 * 100) / 100 . " KB"; + } + else + { + $avatar_dir_size = $avatar_dir_size . " Bytes"; + } + } + else + { + // Couldn't open Avatar dir. + $avatar_dir_size = $lang['Not_available']; + } + + if($posts_per_day > $total_posts) + { + $posts_per_day = $total_posts; + } + + if($topics_per_day > $total_topics) + { + $topics_per_day = $total_topics; + } + + if($users_per_day > $total_users) + { + $users_per_day = $total_users; + } + + // + // DB size ... MySQL only + // + // This code is heavily influenced by a similar routine + // in phpMyAdmin 2.2.0 + // + if( preg_match("/^mysql/", SQL_LAYER) ) + { + $sql = "SELECT VERSION() AS mysql_version"; + if($result = $db->sql_query($sql)) + { + $row = $db->sql_fetchrow($result); + $version = $row['mysql_version']; + + if( preg_match("/^(3\.23|4\.|5\.)/", $version) ) + { + static $dbname, $dbsize; + $db_name = ( preg_match("/^(3\.23\.[6-9])|(3\.23\.[1-9][1-9])|(4\.)|(5\.)/", $version) ) ? "`$dbname`" : $dbname; + + $sql = "SHOW TABLE STATUS + FROM " . $db_name; + if($result = $db->sql_query($sql)) + { + $tabledata_ary = $db->sql_fetchrowset($result); + + $dbsize = 0; + for($i = 0; $i < count($tabledata_ary); $i++) + { + if( $tabledata_ary[$i]['Type'] != "MRG_MyISAM" ) + { + if( $table_prefix != "" ) + { + if( strstr($tabledata_ary[$i]['Name'], $table_prefix) ) + { + $dbsize += $tabledata_ary[$i]['Data_length'] + $tabledata_ary[$i]['Index_length']; + } + } + else + { + $dbsize += $tabledata_ary[$i]['Data_length'] + $tabledata_ary[$i]['Index_length']; + } + } + } + } // Else we couldn't get the table status. + } + else + { + $dbsize = $lang['Not_available']; + } + } + else + { + $dbsize = $lang['Not_available']; + } + $db->sql_freeresult($result); + } + else if( preg_match("/^mssql/", SQL_LAYER) ) + { + $sql = "SELECT ((SUM(size) * 8.0) * 1024.0) as dbsize + FROM sysfiles"; + if( $result = $db->sql_query($sql) ) + { + $dbsize = ( $row = $db->sql_fetchrow($result) ) ? intval($row['dbsize']) : $lang['Not_available']; + } + else + { + $dbsize = $lang['Not_available']; + } + $db->sql_freeresult($result); + } + else + { + $dbsize = $lang['Not_available']; + } + + if ( is_integer($dbsize) ) + { + if( $dbsize >= 1048576 ) + { + $dbsize = sprintf("%.2f MB", ( $dbsize / 1048576 )); + } + else if( $dbsize >= 1024 ) + { + $dbsize = sprintf("%.2f KB", ( $dbsize / 1024 )); + } + else + { + $dbsize = sprintf("%.2f Bytes", $dbsize); + } + } + + $template->assign_vars(array( + "NUMBER_OF_POSTS" => $total_posts, + "NUMBER_OF_TOPICS" => $total_topics, + "NUMBER_OF_USERS" => $total_users, + "START_DATE" => $start_date, + "POSTS_PER_DAY" => $posts_per_day, + "TOPICS_PER_DAY" => $topics_per_day, + "USERS_PER_DAY" => $users_per_day, + "AVATAR_DIR_SIZE" => $avatar_dir_size, + "DB_SIZE" => $dbsize, + "GZIP_COMPRESSION" => ( $board_config['gzip_compress'] ) ? $lang['ON'] : $lang['OFF']) + ); + } + + /** + * Enter description here... + * + * @return unknown + */ + function phpbb_version_check($force_update = false, $warn_fail = false, $ttl = 86400) + { + global $mx_cache, $board_config, $lang, $phpbb_version_info; + + $errno = 0; + $errstr = $phpbb_version_info = ''; + $phpbb_version_info = $mx_cache->get('versioncheck'); + + if ($fsock = @fsockopen('www.phpbb.com', 80, $errno, $errstr, 10)) + { + //$phpbb_version_info = mx_get_remote_file('www.phpbb.com', '/updatecheck', ((defined('PHPBB_QA')) ? '30x_qa.txt' : '30x.txt'), $errstr, $errno); + if ($phpbb_version_info === false || $force_update) + { + $errstr = ''; + $errno = 0; + + $phpbb_version_info = mx_get_remote_file('version.phpbb.com', '/phpbb', + ((defined('PHPBB_QA')) ? '30x_qa.txt' : '30x.txt'), $errstr, $errno); + } + + if (empty($phpbb_version_info)) + { + $mx_cache->destroy('versioncheck'); + if ($warn_fail) + { + trigger_error($errstr, E_USER_WARNING); + } + return false; + } + + $mx_cache->put('versioncheck', $phpbb_version_info, $ttl); + + $phpbb_version_info = explode("\n", $phpbb_version_info); + //$latest_version = trim($phpbb_version_info[0]); + //$update_link = append_sid($phpbb_root_path . 'install/index.' . $phpEx, 'mode=update'); + $latest_phpbb_head_revision = $version1 = strtolower(trim($phpbb_version_info[0])); + $latest_phpbb_minor_revision = trim($phpbb_version_info[2]); + $latest_phpbb_version = trim($phpbb_version_info[0]) . '.' . trim($phpbb_version_info[1]) . '.' . trim($phpbb_version_info[2]); + $version2 = strtolower($board_config['version']); + $current_phpbb_version = explode(".", $board_config['version']); + $minor_phpbb_revision = $current_phpbb_version[2]; + $operator = '<='; + if (version_compare($version1, $version2, $operator)) + { + $phpbb_version_info = '' . $lang['Version_up_to_date'] . '
'; + } + else + { + $phpbb_version_info = '' . $lang['Version_not_up_to_date']; + $phpbb_version_info .= '
'; + } + } + else + { + if ($errstr) + { + $phpbb_version_info = '
' . sprintf($lang['Latest_version_info'], $latest_phpbb_version) . sprintf($lang['Current_version_info'], $board_config['version']) . '' . sprintf($lang['Connect_socket_error'], $errstr) . '
'; + } + else + { + $phpbb_version_info = '' . $lang['Socket_functions_disabled'] . '
'; + } + } + + $phpbb_version_info .= '' . $lang['Mailing_list_subscribe_reminder'] . '
'; + + return $phpbb_version_info; + } +} + +// +// Now load some bbcodes, to be extended for this backend (see below) +// +include_once($mx_root_path . 'includes/sessions/ascraeus/bbcode.' . $phpEx); // BBCode associated functions + +?> \ No newline at end of file diff --git a/includes/sessions/rhea/functions.php b/includes/sessions/rhea/functions.php new file mode 100644 index 00000000..ef8c96cb --- /dev/null +++ b/includes/sessions/rhea/functions.php @@ -0,0 +1,278 @@ + (empty($mx_user->data)) ? ANONYMOUS : $mx_user->data['user_id'], + 'log_ip' => $mx_user->ip, + 'log_time' => time(), + 'log_operation' => $action, + 'log_data' => $data, + ); + + switch ($mode) + { + case 'admin': + $sql_ary['log_type'] = LOG_ADMIN; + break; + + case 'mod': + $sql_ary += array( + 'log_type' => LOG_MOD, + 'forum_id' => $forum_id, + 'topic_id' => $topic_id + ); + break; + + case 'user': + $sql_ary += array( + 'log_type' => LOG_USERS, + 'reportee_id' => $reportee_id + ); + break; + + case 'critical': + $sql_ary['log_type'] = LOG_CRITICAL; + break; + + default: + return false; + } + + $db->sql_query('INSERT INTO ' . LOG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); + + return $db->sql_nextid(); +} + +/** +* Generate sort selection fields +*/ +function mx_gen_sort_selects(&$limit_days, &$sort_by_text, &$sort_days, &$sort_key, &$sort_dir, &$s_limit_days, &$s_sort_key, &$s_sort_dir, &$u_sort_param) +{ + global $mx_user; + + $sort_dir_text = array('a' => $mx_user->lang['ASCENDING'], 'd' => $mx_user->lang['DESCENDING']); + + // Check if the key is selectable. If not, we reset to the first key found. + // This ensures the values are always valid. + if (!isset($limit_days[$sort_days])) + { + @reset($limit_days); + $sort_days = key($limit_days); + } + + if (!isset($sort_by_text[$sort_key])) + { + @reset($sort_by_text); + $sort_key = key($sort_by_text); + } + + if (!isset($sort_dir_text[$sort_dir])) + { + @reset($sort_dir_text); + $sort_dir = key($sort_dir_text); + } + + $s_limit_days = ''; + + $s_sort_key = ''; + + $s_sort_dir = ''; + + $u_sort_param = "st=$sort_days&sk=$sort_key&sd=$sort_dir"; + + return; +} + +/** +* Get username details for placing into templates. +* +* @param string $mode Can be profile (for getting an url to the profile), username (for obtaining the username), colour (for obtaining the user colour) or full (for obtaining a html string representing a coloured link to the users profile). +* @param int $user_id The users id +* @param string $username The users name +* @param string $username_colour The users colour +* @param string $guest_username optional parameter to specify the guest username. It will be used in favor of the GUEST language variable then. +* @param string $custom_profile_url optional parameter to specify a profile url. The user id get appended to this url as &u={user_id} +* +* @return string A string consisting of what is wanted based on $mode. +*/ +function mx_get_username_string($mode, $user_id, $username, $username_colour = '', $guest_username = false, $custom_profile_url = false) +{ + global $phpbb_root_path, $phpEx, $mx_user, $phpbb_auth; + + $profile_url = ''; + $username_colour = ($username_colour) ? '#' . $username_colour : ''; + + if ($guest_username === false) + { + $username = ($username) ? $username : $mx_user->lang['GUEST']; + } + else + { + $username = ($user_id && $user_id != ANONYMOUS) ? $username : ((!empty($guest_username)) ? $guest_username : $mx_user->lang['GUEST']); + } + + // Only show the link if not anonymous + if ($user_id && $user_id != ANONYMOUS) + { + // Do not show the link if the user is already logged in but do not have u_viewprofile permissions (relevant for bots mostly). + // For all others the link leads to a login page or the profile. + if ($mx_user->data['user_id'] != ANONYMOUS && !$phpbb_auth->acl_get('u_viewprofile')) + { + $profile_url = ''; + } + else + { + $profile_url = ($custom_profile_url !== false) ? $custom_profile_url : mx3_append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile'); + $profile_url .= '&u=' . (int) $user_id; + } + } + else + { + $profile_url = ''; + } + + switch ($mode) + { + case 'profile_url': + case 'profile': + return $profile_url; + break; + + case 'username': + return $username; + break; + + case 'colour': + return $username_colour; + break; + + case 'full': + default: + + $tpl = ''; + if (!$profile_url && !$username_colour) + { + $tpl = '{USERNAME}'; + } + else if (!$profile_url && $username_colour) + { + $tpl = '{USERNAME}'; + } + else if ($profile_url && !$username_colour) + { + $tpl = '{USERNAME}'; + } + else if ($profile_url && $username_colour) + { + $tpl = '{USERNAME}'; + } + + return str_replace(array('{PROFILE_URL}', '{USERNAME_COLOUR}', '{USERNAME}'), array($profile_url, $username_colour, $username), $tpl); + break; + } +} +?> \ No newline at end of file diff --git a/includes/sessions/rhea/index.htm b/includes/sessions/rhea/index.htm new file mode 100644 index 00000000..ee1f723a --- /dev/null +++ b/includes/sessions/rhea/index.htm @@ -0,0 +1,10 @@ + + ++ + + + + + + diff --git a/includes/sessions/rhea/login.php b/includes/sessions/rhea/login.php new file mode 100644 index 00000000..3433bf07 --- /dev/null +++ b/includes/sessions/rhea/login.php @@ -0,0 +1,256 @@ +is_request('login') && ($userdata['user_id'] == ANONYMOUS || $mx_request_vars->is_post('admin')) ) +{ + $username = utf8_clean_string($mx_request_vars->post('username', MX_TYPE_NO_TAGS, '')); + $password = $mx_request_vars->post('password', MX_TYPE_NO_TAGS); + $viewonline = $mx_request_vars->post('viewonline', MX_TYPE_INT, 0); + + $sql = "SELECT * + FROM " . USERS_TABLE . " + WHERE username = '" . str_replace("\\'", "''", $username) . "' + OR username_clean = '" . str_replace("\\'", "''", $username) . "'"; + + if ( !($result = $db->sql_query($sql) ) ) + { + mx_message_die(GENERAL_ERROR, 'Error in obtaining userdata', '', __LINE__, __FILE__, $sql); + } + + if( $row = $db->sql_fetchrow($result) ) + { + //$user_type = $row['user_level']; // phpBB2 + $user_type = $row['user_type']; // phpBB3 + + if( $user_type != ADMIN && $board_config['board_disable'] ) + { + mx_redirect(mx3_append_sid("index.$phpEx", false)); + } + else + { + $user_login_attempts = $row['user_login_attempts']; + + if ( $user_login_attempts && $board_config['login_reset_time'] ) + { + $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_login_attempts = 0 WHERE user_id = ' . $row['user_id']); + $row['user_last_login_try'] = $row['user_login_tries'] = 0; + } + + // Check to see if user is allowed to login again... if his tries are exceeded + if ($user_login_attempt && $board_config['login_reset_time'] && $board_config['max_login_attempts'] && $user_login_attempts >= $board_config['max_login_attempts'] && $userdata['user_level'] != ADMIN) + { + mx_message_die(GENERAL_MESSAGE, sprintf($lang['Login_attempts_exceeded'], $board_config['max_login_attempts'], $board_config['login_reset_time'])); + } + + // If the password convert flag is set we need to convert it + if ($row['user_pass_convert']) + { + // in phpBB2 passwords were used exactly as they were sent, with addslashes applied + $password_old_format = isset($_REQUEST['password']) ? $_REQUEST['password'] : $password; + $password_old_format = (!STRIP) ? addslashes($password_old_format) : $password_old_format; + $password_new_format = ''; + + phpBB3::set_var($password_new_format, stripslashes($password_old_format), 'string'); + + //mx_message_die(CRITICAL_ERROR, "Couldn't start session : login", $password_new_format, ''); + + if ($password == $password_new_format) + { + if (!function_exists('utf8_to_cp1252')) + { + global $mx_root_path, $phpEx; + include_once($mx_root_path . 'includes/utf/data/recode_basic.' . $phpEx); + } + + // cp1252 is phpBB2's default encoding, characters outside ASCII range might work when converted into that encoding + if (md5($password_old_format) == $row['user_password'] || md5(utf8_to_cp1252($password_old_format)) == $row['user_password']) + { + $hash = phpBB3::phpbb_hash($password_new_format); + + // Update the password in the users table to the new format and remove user_pass_convert flag + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_password = \'' . $db->sql_escape($hash) . '\', + user_pass_convert = 0 + WHERE user_id = ' . $row['user_id']; + $db->sql_query($sql); + + $row['user_pass_convert'] = 0; + $row['user_password'] = $hash; + } + else + { + // Although we weren't able to convert this password we have to + // increase login attempt count to make sure this cannot be exploited + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_login_attempts = user_login_attempts + 1 + WHERE user_id = ' . $row['user_id']; + $db->sql_query($sql); + mx_message_die(GENERAL_MESSAGE, 'We are sorry but password convertion failed, please login direct in forums or rewuest a new activation link.'); + return array( + 'status' => LOGIN_ERROR_PASSWORD_CONVERT, + 'error_msg' => 'LOGIN_ERROR_PASSWORD_CONVERT', + 'user_row' => $row, + ); + } + } + } + else + { + // in phpBB2 passwords were used exactly as they were sent, with addslashes applied + $password_old_format = isset($_REQUEST['password']) ? $_REQUEST['password'] : $password; + $password_old_format = (!STRIP) ? addslashes($password_old_format) : $password_old_format; + $password_new_format = ''; + phpBB3::set_var($password_new_format, stripslashes($password_old_format), 'string'); + //mx_message_die(CRITICAL_ERROR, "Couldn't start session : login", $password_new_format, ''); + + if ($password_new_format == $password_old_format) + { + if (!function_exists('utf8_to_cp1252')) + { + global $mx_root_path, $phpEx; + include_once($mx_root_path . 'includes/utf/data/recode_basic.' . $phpEx); + } + + // cp1252 is phpBB2's default encoding, characters outside ASCII range might work when converted into that encoding + if (md5($password_old_format) == $row['user_password'] || md5($password) == $row['user_password'] || phpBB3::phpbb_check_hash($password, $row['user_password'])) + { + $autologin = $mx_request_vars->is_post('autologin'); + $admin = $mx_request_vars->is_post('admin'); + $mx_user->session_create($row['user_id'], $admin, $autologin, $viewonline = true); + $session_id = $mx_user->session_id; + + + // Reset login tries + //$db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_login_tries = 0, user_last_login_try = 0 WHERE user_id = ' . $row['user_id']); // phpBB2 + $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_login_attempts = 0 WHERE user_id = ' . $row['user_id']); // phpBB3 + + if( $session_id ) + { + $fromurl = ( !empty($HTTP_REFERER) ) ? str_replace('&', '&', htmlspecialchars($HTTP_REFERER)) : "index.$phpEx"; + $url = !$mx_request_vars->is_empty_post('redirect') ? str_replace('&', '&', $mx_request_vars->post('redirect', MX_TYPE_NO_TAGS)) : $fromurl; + mx_redirect(mx3_append_sid($url, false, false, $session_id)); + } + else + { + mx_message_die(CRITICAL_ERROR, "Couldn't start session : login", "", __LINE__, __FILE__); + } + } + else + { + // Although we weren't able to convert this password we have to + // increase login attempt count to make sure this cannot be exploited + $sql = ' UPDATE ' . USERS_TABLE . ' + SET user_login_attempts = user_login_attempts + 1 + WHERE user_id = ' . $row['user_id']; + $db->sql_query($sql); + + $redirect = !$mx_request_vars->is_empty_post('redirect') ? str_replace('&', '&', $mx_request_vars->post('redirect', MX_TYPE_NO_TAGS)) : ''; + $redirect = str_replace('?', '&', $redirect); + + if (strstr(urldecode($redirect), "\n") || strstr(urldecode($redirect), "\r")) + { + mx_message_die(GENERAL_ERROR, 'Tried to redirect to potentially insecure url.'); + } + + $template->assign_vars(array( + 'META' => "") + ); + + $message = $lang['Error_login'] . '
' . sprintf($lang['Click_return_login'], "", '') . '
' . sprintf($lang['Click_return_index'], '', ''); + + mx_message_die(GENERAL_MESSAGE, $message); + } + } + // Check password ... + if (!$row['user_pass_convert'] && phpBB3::phpbb_check_hash($password, $row['user_password'])) + { + if ($row['user_login_attempts'] != 0) + { + // Successful, reset login attempts (the user passed all stages) + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_login_attempts = 0 + WHERE user_id = ' . $row['user_id']; + $db->sql_query($sql); + } + + // User inactive... + if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE) + { + mx_message_die(GENERAL_MESSAGE, 'Inactive User'); + } + + // Successful login... set user_login_attempts to zero... + if( $session_id ) + { + $url = !$mx_request_vars->is_empty_post('redirect') ? str_replace('&', '&', $mx_request_vars->post('redirect', MX_TYPE_NO_TAGS)) : "index.$phpEx"; + mx_redirect(mx3_append_sid($url, false)); + } + else + { + mx_message_die(CRITICAL_ERROR, "Couldn't start session : login", "", __LINE__, __FILE__); + } + } + } + } + } + else + { + $redirect = !$mx_request_vars->is_empty_post('redirect') ? str_replace('&', '&', $mx_request_vars->post('redirect', MX_TYPE_NO_TAGS)) : ''; + $redirect = str_replace("?", "&", $redirect); + + if (strstr(urldecode($redirect), "\n") || strstr(urldecode($redirect), "\r")) + { + mx_message_die(GENERAL_ERROR, 'Tried to redirect to potentially insecure url.'); + } + + $template->assign_vars(array( + 'META' => "") + ); + + $message = $lang['Error_login'] . '
' . sprintf($lang['Click_return_login'], "", '') . '
' . sprintf($lang['Click_return_index'], '', ''); + mx_message_die(GENERAL_MESSAGE, $message); + } +} +else if ($mx_request_vars->is_request('logout') && $userdata['session_logged_in'] ) +{ + // session id check + if ($sid == '' || $sid != $userdata['session_id']) + { + mx_message_die(GENERAL_ERROR, 'Invalid_session' . $userdata['session_id']); + } + + if( $userdata['session_logged_in'] ) + { + $mx_user->session_kill(); + } + + if (!$mx_request_vars->is_empty_request('redirect')) + { + $url = $mx_request_vars->post('redirect', MX_TYPE_NO_TAGS); + $url = str_replace('&', '&', $url); + mx_redirect(mx3_append_sid($url, false)); + } + else + { + mx_redirect(mx3_append_sid("index.$phpEx", false)); + } +} +else +{ + $url = !$mx_request_vars->is_empty_post('redirect') ? str_replace('&', '&', $mx_request_vars->post('redirect', MX_TYPE_NO_TAGS)) : "index.$phpEx"; + mx_redirect(mx3_append_sid($url, false)); +} +?> \ No newline at end of file diff --git a/includes/sessions/rhea/session.php b/includes/sessions/rhea/session.php new file mode 100644 index 00000000..f9a8c654 --- /dev/null +++ b/includes/sessions/rhea/session.php @@ -0,0 +1,3800 @@ + $board_config - by Jon + * - replaced $cache = new mx_nothing(); to disable bots() - by Jon + * - removed '?' in the returned $SID string - by Jon + * - in function setup() + * $auth -> $phpbb_auth - by OryNider + * -new globals: $mx_root_path, $mx_cache - by OryNider + * $this->lang_name was redefined to use in + * worst case the new $board_config['phpbb_lang'] + * wich was defined in mx_functions_style.php + * before lang name is expanded - by OryNider + * $template = new mx_Template(); - by OryNider + * - before $this->add_lang($lang_set); the phpBB common language is included + * if fails with $phpbb_root_path added + * - in function set_lang() + * - if empty $this->lang_path will be redefined + * from $phpbb_root_path and new $board_config['phpbb_lang'] + * wich in this case are set as globals - by OryNider + * (similar check has been added in the phpBB3 version too) + * - added function images() to help redefining $images var + * and indexes were is needed - by OryNider + */ + +/** + * Disable bots + * + */ +class mx_nothing +{ + function obtain_bots() + { + return array(); + } +} + +/** +* Session class +* @package MX-Publisher +*/ +class session +{ + var $cookie_data = array(); + var $page = array(); + var $data = array(); + var $browser = ''; + var $forwarded_for = ''; + var $host = ''; + var $session_id = ''; + var $ip = ''; + var $load = 0; + var $time_now = 0; + var $update_session_page = true; + + var $lang = array(); + var $help = array(); + var $theme = array(); + var $date_format; + var $timezone; + var $dst; + + var $lang_name; + var $lang_id = false; + var $lang_path; + var $img_lang; + var $img_array = array(); + + /** + * Load sessions + * @access public + * + */ + function load() + { + global $board_config, $cache; + + $board_config['auth_method'] = 'db'; + $cache = new mx_nothing(); + //define('NEED_SID', 1); + $this->session_begin(); + + // Redefine some MXP stylish userdata + $session_logged_in = $this->data['session_logged_in'] = $this->data['user_id'] != ANONYMOUS ? 1 : 0; + + //print_r($session_logged_in); + if ( $this->data['user_id'] == ANONYMOUS ) + { + $this->data['user_type'] = -1; + } + + switch ($this->data['user_type']) + { + case 3: + $this->data['user_level'] = 1; + break; + case 0: + $this->data['user_level'] = 2; + break; + default: + $this->data['user_level'] = 0; + break; + } + $this->data['session_id'] = $this->session_id; + $this->data['user_session_page'] = $this->data['session_page']; + } + + /** + * Extract current session page + * + * @param string $root_path current root path (phpbb_root_path) + */ + function extract_current_page($root_path) + { + $page_array = array(); + + // First of all, get the request uri... + $script_name = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF'); + $args = (!empty($_SERVER['QUERY_STRING'])) ? explode('&', $_SERVER['QUERY_STRING']) : explode('&', getenv('QUERY_STRING')); + + // If we are unable to get the script name we use REQUEST_URI as a failover and note it within the page array for easier support... + if (!$script_name) + { + $script_name = (!empty($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : getenv('REQUEST_URI'); + $script_name = (($pos = strpos($script_name, '?')) !== false) ? substr($script_name, 0, $pos) : $script_name; + $page_array['failover'] = 1; + } + + // Replace backslashes and doubled slashes (could happen on some proxy setups) + $script_name = str_replace(array('\\', '//'), '/', $script_name); + + // Now, remove the sid and let us get a clean query string... + foreach ($args as $key => $argument) + { + if (strpos($argument, 'sid=') === 0 || strpos($argument, '_f_=') === 0) + { + unset($args[$key]); + } + } + + // The following examples given are for an request uri of {path to the phpbb directory}/adm/index.php?i=10&b=2 + + // The current query string + $query_string = trim(implode('&', $args)); + + // basenamed page name (for example: index.php) + $page_name = basename($script_name); + $page_name = urlencode(htmlspecialchars($page_name)); + + // current directory within the phpBB root (for example: adm) + $root_dirs = explode('/', str_replace('\\', '/', phpBB2::phpbb_realpath($root_path))); + $page_dirs = explode('/', str_replace('\\', '/', phpBB2::phpbb_realpath('./'))); + $intersection = array_intersect_assoc($root_dirs, $page_dirs); + + $root_dirs = array_diff_assoc($root_dirs, $intersection); + $page_dirs = array_diff_assoc($page_dirs, $intersection); + + $page_dir = str_repeat('../', sizeof($root_dirs)) . implode('/', $page_dirs); + + if ($page_dir && substr($page_dir, -1, 1) == '/') + { + $page_dir = substr($page_dir, 0, -1); + } + + // Current page from phpBB root (for example: adm/index.php?i=10&b=2) + $page = (($page_dir) ? $page_dir . '/' : '') . $page_name . (($query_string) ? "?$query_string" : ''); + + // The script path from the webroot to the current directory (for example: /phpBB3/adm/) : always prefixed with / and ends in / + $script_path = trim(str_replace('\\', '/', dirname($script_name))); + + // The script path from the webroot to the phpBB root (for example: /phpBB3/) + $script_dirs = explode('/', $script_path); + array_splice($script_dirs, -sizeof($page_dirs)); + $root_script_path = implode('/', $script_dirs) . (sizeof($root_dirs) ? '/' . implode('/', $root_dirs) : ''); + + // We are on the base level (phpBB root == webroot), lets adjust the variables a bit... + if (!$root_script_path) + { + $root_script_path = ($page_dir) ? str_replace($page_dir, '', $script_path) : $script_path; + } + + $script_path .= (substr($script_path, -1, 1) == '/') ? '' : '/'; + $root_script_path .= (substr($root_script_path, -1, 1) == '/') ? '' : '/'; + + $page_array += array( + 'page_name' => $page_name, + 'page_dir' => $page_dir, + + 'query_string' => $query_string, + 'script_path' => str_replace(' ', '%20', htmlspecialchars($script_path)), + 'root_script_path' => str_replace(' ', '%20', htmlspecialchars($root_script_path)), + + 'page' => $page + ); + + return $page_array; + } + + /** + * Start session management + * + * This is where all session activity begins. We gather various pieces of + * information from the client and server. We test to see if a session already + * exists. If it does, fine and dandy. If it doesn't we'll go on to create a + * new one ... pretty logical heh? We also examine the system load (if we're + * running on a system which makes such information readily available) and + * halt if it's above an admin definable limit. + * + * @param bool $update_session_page if true the session page gets updated. + * This can be set to circumvent certain scripts to update the users last visited page. + */ + function session_begin($update_session_page = true) + { + global $phpEx, $SID, $_SID, $_EXTRA_URL, $db, $board_config, $mx_root_path, $phpbb_root_path, $page_id; + + // Give us some basic information + $this->time_now = time(); + $this->cookie_data = array('u' => 0, 'k' => ''); + $this->update_session_page = $update_session_page; + $this->browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT']) : ''; + $this->referer = (!empty($_SERVER['HTTP_REFERER'])) ? htmlspecialchars((string) $_SERVER['HTTP_REFERER']) : ''; + $this->forwarded_for = (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) ? (string) $_SERVER['HTTP_X_FORWARDED_FOR'] : ''; + $this->host = (!empty($_SERVER['HTTP_HOST'])) ? (string) $_SERVER['HTTP_HOST'] : 'localhost'; + $this->page = $this->extract_current_page($phpbb_root_path); + + // if the forwarded for header shall be checked we have to validate its contents + if ($board_config['forwarded_for_check']) + { + $this->forwarded_for = preg_replace('#, +#', ', ', $this->forwarded_for); + + // Whoa these look impressive! + // The code to generate the following two regular expressions which match valid IPv4/IPv6 addresses + // can be found in the develop directory + $ipv4 = phpBB3::get_preg_expression('ipv4'); //'#^(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$#'; + $ipv6 = phpBB3::get_preg_expression('ipv6'); //'#^(?:(?:(?:[\dA-F]{1,4}:){6}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:::(?:[\dA-F]{1,4}:){5}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:):(?:[\dA-F]{1,4}:){4}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,2}:(?:[\dA-F]{1,4}:){3}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,3}:(?:[\dA-F]{1,4}:){2}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,4}:(?:[\dA-F]{1,4}:)(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,5}:(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,6}:[\dA-F]{1,4})|(?:(?:[\dA-F]{1,4}:){1,7}:))$#i'; + + // split the list of IPs + $ips = explode(', ', $this->forwarded_for); + foreach ($ips as $ip) + { + // check IPv4 first, the IPv6 is hopefully only going to be used very seldomly + if (!empty($ip) && !preg_match($ipv4, $ip) && !preg_match($ipv6, $ip)) + { + // contains invalid data, don't use the forwarded for header + $this->forwarded_for = ''; + break; + } + } + } + else + { + $this->forwarded_for = ''; + } + + // Add forum to the page for tracking online users - also adding a "x" to the end to properly identify the number + $this->page['page'] .= (isset($_REQUEST['f'])) ? ((strpos($this->page['page'], '?') !== false) ? '&' : '?') . '_f_=' . (int) $_REQUEST['f'] . 'x' : ''; + + if (isset($_COOKIE[$board_config['cookie_name'] . '_sid']) || isset($_COOKIE[$board_config['cookie_name'] . '_u'])) + { + $this->cookie_data['u'] = phpBB3::request_var($board_config['cookie_name'] . '_u', 0, false, true); + $this->cookie_data['k'] = phpBB3::request_var($board_config['cookie_name'] . '_k', '', false, true); + $this->session_id = phpBB3::request_var($board_config['cookie_name'] . '_sid', '', false, true); + + // original code: $SID = (defined('NEED_SID')) ? 'sid=' . $this->session_id : 'sid='; + $SID = (defined('NEED_SID')) ? 'sid=' . $this->session_id : ''; + $_SID = (defined('NEED_SID')) ? $this->session_id : ''; + + if (empty($this->session_id)) + { + $this->session_id = $_SID = phpBB3::request_var('sid', ''); + $SID = 'sid=' . $this->session_id; + $this->cookie_data = array('u' => 0, 'k' => ''); + } + } + else + { + $this->session_id = $_SID = phpBB3::request_var('sid', ''); + $SID = 'sid=' . $this->session_id; + } + + $_EXTRA_URL = array(); + + // Why no forwarded_for et al? Well, too easily spoofed. With the results of my recent requests + // it's pretty clear that in the majority of cases you'll at least be left with a proxy/cache ip. + $this->ip = (!empty($_SERVER['REMOTE_ADDR'])) ? htmlspecialchars($_SERVER['REMOTE_ADDR']) : ''; + $this->ip = preg_replace('#[ ]{2,}#', ' ', str_replace(array(',', ' '), ' ', $this->ip)); + + // split the list of IPs + $ips = explode(' ', $this->ip); + + // Default IP if REMOTE_ADDR is invalid + $this->ip = '127.0.0.1'; + + foreach ($ips as $ip) + { + // check IPv4 first, the IPv6 is hopefully only going to be used very seldomly + if (!empty($ip) && !preg_match(phpBB3::get_preg_expression('ipv4'), $ip) && !preg_match(phpBB3::get_preg_expression('ipv6'), $ip)) + { + // Just break + break; + } + + // Quick check for IPv4-mapped address in IPv6 + if (stripos($ip, '::ffff:') === 0) + { + $ipv4 = substr($ip, 7); + + if (preg_match(phpBB3::get_preg_expression('ipv4'), $ipv4)) + { + $ip = $ipv4; + } + } + + // Use the last in chain + $this->ip = $ip; + } + + $this->load = false; + + // Load limit check (if applicable) + if ($board_config['limit_load'] || $board_config['limit_search_load']) + { + if ($load = @file_get_contents('/proc/loadavg')) + { + $this->load = array_slice(explode(' ', $load), 0, 1); + $this->load = floatval($this->load[0]); + } + else + { + set_config('limit_load', '0'); + set_config('limit_search_load', '0'); + } + } + + // Is session_id is set or session_id is set and matches the url param if required + if (!empty($this->session_id) && (!defined('NEED_SID') || (isset($_GET['sid']) && $this->session_id === $_GET['sid'])) ) + { + $sql = 'SELECT u.*, s.* + FROM ' . SESSIONS_TABLE . ' s, ' . USERS_TABLE . " u + WHERE s.session_id = '" . $db->sql_escape($this->session_id) . "' + AND u.user_id = s.session_user_id"; + $result = $db->sql_query($sql); + $this->data = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + // Did the session exist in the DB? + if (isset($this->data['user_id'])) + { + // Validate IP length according to admin ... enforces an IP + // check on bots if admin requires this + //$quadcheck = ($board_config['ip_check_bot'] && $this->data['user_type'] & USER_BOT) ? 4 : $board_config['ip_check']; + + if (strpos($this->ip, ':') !== false && strpos($this->data['session_ip'], ':') !== false) + { + $s_ip = short_ipv6($this->data['session_ip'], $board_config['ip_check']); + $u_ip = short_ipv6($this->ip, $board_config['ip_check']); + } + else + { + $s_ip = implode('.', array_slice(explode('.', $this->data['session_ip']), 0, $board_config['ip_check'])); + $u_ip = implode('.', array_slice(explode('.', $this->ip), 0, $board_config['ip_check'])); + } + + $s_browser = ($board_config['browser_check']) ? strtolower(substr($this->data['session_browser'], 0, 149)) : ''; + $u_browser = ($board_config['browser_check']) ? strtolower(substr($this->browser, 0, 149)) : ''; + + $s_forwarded_for = ($board_config['forwarded_for_check']) ? substr($this->data['session_forwarded_for'], 0, 254) : ''; + $u_forwarded_for = ($board_config['forwarded_for_check']) ? substr($this->forwarded_for, 0, 254) : ''; + + // referer checks + // The @ before $config['referer_validation'] suppresses notices present while running the updater + $check_referer_path = (@$board_config['referer_validation'] == REFERER_VALIDATE_PATH); + $referer_valid = true; + + // we assume HEAD and TRACE to be foul play and thus only whitelist GET + if (@$board_config['referer_validation'] && isset($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) !== 'get') + { + $referer_valid = $this->validate_referer($check_referer_path); + } + + if ($u_ip === $s_ip && $s_browser === $u_browser && $s_forwarded_for === $u_forwarded_for) + { + $session_expired = false; + + // Check whether the session is still valid if we have one + $method = basename(trim($board_config['auth_method'])); + + if ((@include_once $mx_root_path . "includes/shared/phpbb3/includes/auth/auth_" . $method . ".$phpEx") === false) + { + if ((@include_once $mx_root_path . "includes/shared/phpbb3/includes/auth/auth_" . $method . ".$phpEx") === false) + { + mx_message_die(CRITICAL_ERROR, 'File(s1) ' . $mx_root_path . "includes/shared/phpbb3/includes/auth/auth/auth_" . $method . ".$phpEx" . ' couldn\'t be opened.'); + } + } + + $method = 'validate_session_' . $method; + if (function_exists($method)) + { + if (!$method($this->data)) + { + $session_expired = true; + } + } + + if (!$session_expired) + { + // Check the session length timeframe if autologin is not enabled. + // Else check the autologin length... and also removing those having autologin enabled but no longer allowed board-wide. + if (!$this->data['session_autologin']) + { + if ($this->data['session_time'] < $this->time_now - ($board_config['session_length'] + 60)) + { + $session_expired = true; + } + } + else if (!$board_config['allow_autologin'] || ($board_config['max_autologin_time'] && $this->data['session_time'] < $this->time_now - (86400 * (int) $board_config['max_autologin_time']) + 60)) + { + $session_expired = true; + } + } + + if (!$session_expired) + { + // Only update session DB a minute or so after last update or if page changes + if ($this->time_now - $this->data['session_time'] > 60 || ($this->update_session_page && $this->data['session_page'] != $this->page['page'])) + { + $sql_ary = array('session_time' => $this->time_now); + + if ($this->update_session_page) + { + $sql_ary['session_page'] = substr($this->page['page'], 0, 199); + $sql_ary['session_forum_id'] = !empty($this->page['forum']) ? $this->page['forum'] : $page_id; //Added for phpBB 3.0.2 by Ory + } + + $db->sql_return_on_error(true); + + $sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE session_id = '" . $db->sql_escape($this->session_id) . "'"; + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + // If the database is not yet updated, there will be an error due to the session_forum_id + // @todo REMOVE for 3.0.2 + if ($result === false) + { + unset($sql_ary['session_forum_id']); + + $sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE session_id = '" . $db->sql_escape($this->session_id) . "'"; + $db->sql_query($sql); + } + + if ($this->data['user_id'] != ANONYMOUS && !empty($board_config['new_member_post_limit']) && $this->data['user_new'] && $board_config['new_member_post_limit'] <= $this->data['user_posts']) + { + $this->leave_newly_registered(); + } + } + + $this->data['is_registered'] = ($this->data['user_id'] != ANONYMOUS && ($this->data['user_type'] == USER_NORMAL || $this->data['user_type'] == USER_FOUNDER)) ? true : false; + $this->data['is_bot'] = (!$this->data['is_registered'] && $this->data['user_id'] != ANONYMOUS) ? true : false; + $this->data['user_lang'] = basename($this->data['user_lang']); + + return true; + } + } + else + { + // Added logging temporarly to help debug bugs... + if (defined('DEBUG_EXTRA') && $this->data['user_id'] != ANONYMOUS) + { + if ($referer_valid) + { + mx_add_log('critical', 'LOG_IP_BROWSER_FORWARDED_CHECK', $u_ip, $s_ip, $u_browser, $s_browser, htmlspecialchars($u_forwarded_for), htmlspecialchars($s_forwarded_for)); + } + else + { + mx_add_log('critical', 'LOG_REFERER_INVALID', $this->referer); + } + } + } + } + } + // If we reach here then no (valid) session exists. So we'll create a new one + return $this->session_create(); + } + + /** + * Create a new session + * + * If upon trying to start a session we discover there is nothing existing we + * jump here. Additionally this method is called directly during login to regenerate + * the session for the specific user. In this method we carry out a number of tasks; + * garbage collection, (search)bot checking, banned user comparison. Basically + * though this method will result in a new session for a specific user. + */ + function session_create($user_id = false, $set_admin = false, $persist_login = false, $viewonline = true) + { + global $SID, $_SID, $db, $board_config, $cache, $mx_root_path, $phpbb_root_path, $phpEx, $mx_backend; + + $this->data = array(); + + /* Garbage collection ... remove old sessions updating user information + // if necessary. It means (potentially) 11 queries but only infrequently + if ($this->time_now > $board_config['session_last_gc'] + $board_config['session_gc']) + { + $this->session_gc(); + }*/ + + // Do we allow autologin on this board? No? Then override anything + // that may be requested here + if (!$board_config['allow_autologin']) + { + $this->cookie_data['k'] = $persist_login = false; + } + + /** + * Here we do a bot check, oh er saucy! No, not that kind of bot + * check. We loop through the list of bots defined by the admin and + * see if we have any useragent and/or IP matches. If we do, this is a + * bot, act accordingly + */ + $bot = false; + $active_bots = $mx_backend->obtain_bots(); + + foreach ($active_bots as $row) + { + if ($row['bot_agent'] && preg_match('#' . str_replace('\*', '.*?', preg_quote($row['bot_agent'], '#')) . '#i', $this->browser)) + { + $bot = $row['user_id']; + } + + // If ip is supplied, we will make sure the ip is matching too... + if ($row['bot_ip'] && ($bot || !$row['bot_agent'])) + { + // Set bot to false, then we only have to set it to true if it is matching + $bot = false; + + foreach (explode(',', $row['bot_ip']) as $bot_ip) + { + $bot_ip = trim($bot_ip); + + if (!$bot_ip) + { + continue; + } + if (strpos($this->ip, $bot_ip) === 0) + { + $bot = (int) $row['user_id']; + break; + } + } + } + if ($bot) + { + break; + } + } + $method = basename(trim($board_config['auth_method'])); + if ((@include_once $mx_root_path . "includes/shared/phpbb3/includes/auth/auth_" . $method . ".$phpEx") === false) + { + if ((@include_once $mx_root_path . "includes/shared/phpbb3/includes/auth/auth_" . $method . ".$phpEx") === false) + { + mx_message_die(CRITICAL_ERROR, 'File(s2) ' . $mx_root_path . "includes/shared/phpbb3/includes/auth/auth_" . $method . ".$phpEx" . ' couldn\'t be opened.'); + } + } + //$provider = $phpbb_container->get('auth.provider.' . $method); + $method = 'autologin_' . $method; + if (function_exists($method)) + { + $this->data = $method(); + + if (sizeof($this->data)) + { + $this->cookie_data['k'] = ''; + $this->cookie_data['u'] = $this->data['user_id']; + } + } + + // If we're presented with an autologin key we'll join against it. + // Else if we've been passed a user_id we'll grab data based on that + if (isset($this->cookie_data['k']) && $this->cookie_data['k'] && $this->cookie_data['u'] && !sizeof($this->data)) + { + $sql = 'SELECT u.* + FROM ' . USERS_TABLE . ' u, ' . SESSIONS_KEYS_TABLE . ' k + WHERE u.user_id = ' . (int) $this->cookie_data['u'] . ' + AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ") + AND k.user_id = u.user_id + AND k.key_id = '" . $db->sql_escape(md5($this->cookie_data['k'])) . "'"; + $result = $db->sql_query($sql); + $this->data = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + $bot = false; + } + else if ($user_id !== false && !sizeof($this->data)) + { + $this->cookie_data['k'] = ''; + $this->cookie_data['u'] = $user_id; + + $sql = 'SELECT * + FROM ' . USERS_TABLE . ' + WHERE user_id = ' . (int) $this->cookie_data['u'] . ' + AND user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')'; + $result = $db->sql_query($sql); + $this->data = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + $bot = false; + } + + // If no data was returned one or more of the following occurred: + // Key didn't match one in the DB + // User does not exist + // User is inactive + // User is bot + if (!sizeof($this->data) || !is_array($this->data)) + { + $this->cookie_data['k'] = ''; + $this->cookie_data['u'] = ($bot) ? $bot : ANONYMOUS; + + if (!$bot) + { + $sql = 'SELECT * + FROM ' . USERS_TABLE . ' + WHERE user_id = ' . (int) $this->cookie_data['u']; + } + else + { + // We give bots always the same session if it is not yet expired. + $sql = 'SELECT u.*, s.* + FROM ' . USERS_TABLE . ' u + LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id) + WHERE u.user_id = ' . (int) $bot; + } + + $result = $db->sql_query($sql); + $this->data = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + } + + if ($this->data['user_id'] != ANONYMOUS && !$bot) + { + $this->data['session_last_visit'] = (isset($this->data['session_time']) && $this->data['session_time']) ? $this->data['session_time'] : (($this->data['user_lastvisit']) ? $this->data['user_lastvisit'] : time()); + } + else + { + $this->data['session_last_visit'] = $this->time_now; + } + + // Force user id to be integer... + $this->data['user_id'] = (int) $this->data['user_id']; + + // At this stage we should have a filled data array, defined cookie u and k data. + // data array should contain recent session info if we're a real user and a recent + // session exists in which case session_id will also be set + + // Is user banned? Are they excluded? Won't return on ban, exists within method + if ($this->data['user_type'] != USER_FOUNDER) + { + if (!$board_config['forwarded_for_check']) + { + $this->check_ban($this->data['user_id'], $this->ip); + } + else + { + $ips = explode(', ', $this->forwarded_for); + $ips[] = $this->ip; + $this->check_ban($this->data['user_id'], $ips); + } + } + $this->data['is_registered'] = (!$bot && $this->data['user_id'] != ANONYMOUS && ($this->data['user_type'] == USER_NORMAL || $this->data['user_type'] == USER_FOUNDER)) ? true : false; + $this->data['is_bot'] = ($bot) ? true : false; + + // If our friend is a bot, we re-assign a previously assigned session + if ($this->data['is_bot'] && $bot == $this->data['user_id'] && $this->data['session_id']) + { + // Only assign the current session if the ip, browser and forwarded_for match... + if (strpos($this->ip, ':') !== false && strpos($this->data['session_ip'], ':') !== false) + { + $s_ip = short_ipv6($this->data['session_ip'], $board_config['ip_check']); + $u_ip = short_ipv6($this->ip, $board_config['ip_check']); + } + else + { + $s_ip = implode('.', array_slice(explode('.', $this->data['session_ip']), 0, $board_config['ip_check'])); + $u_ip = implode('.', array_slice(explode('.', $this->ip), 0, $board_config['ip_check'])); + } + + $s_browser = ($board_config['browser_check']) ? strtolower(substr($this->data['session_browser'], 0, 149)) : ''; + $u_browser = ($board_config['browser_check']) ? strtolower(substr($this->browser, 0, 149)) : ''; + + $s_forwarded_for = ($board_config['forwarded_for_check']) ? substr($this->data['session_forwarded_for'], 0, 254) : ''; + $u_forwarded_for = ($board_config['forwarded_for_check']) ? substr($this->forwarded_for, 0, 254) : ''; + + if ($u_ip === $s_ip && $s_browser === $u_browser && $s_forwarded_for === $u_forwarded_for) + { + $this->session_id = $this->data['session_id']; + + // Only update session DB a minute or so after last update or if page changes + if ($this->time_now - $this->data['session_time'] > 60 || ($this->update_session_page && $this->data['session_page'] != $this->page['page'])) + { + $this->data['session_time'] = $this->data['session_last_visit'] = $this->time_now; + + $sql_ary = array('session_time' => $this->time_now, 'session_last_visit' => $this->time_now, 'session_admin' => 0); + + if ($this->update_session_page) + { + $sql_ary['session_page'] = substr($this->page['page'], 0, 199); + } + + $sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE session_id = '" . $db->sql_escape($this->session_id) . "'"; + $db->sql_query($sql); + + // Update the last visit time + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_lastvisit = ' . (int) $this->data['session_time'] . ' + WHERE user_id = ' . (int) $this->data['user_id']; + $db->sql_query($sql); + } + + $SID = '?sid='; + $_SID = ''; + return true; + } + else + { + // If the ip and browser does not match make sure we only have one bot assigned to one session + $db->sql_query('DELETE FROM ' . SESSIONS_TABLE . ' WHERE session_user_id = ' . $this->data['user_id']); + } + } + + $session_autologin = (($this->cookie_data['k'] || $persist_login) && $this->data['is_registered']) ? true : false; + $set_admin = ($set_admin && $this->data['is_registered']) ? true : false; + + // Create or update the session + $sql_ary = array( + 'session_user_id' => (int) $this->data['user_id'], + 'session_start' => (int) $this->time_now, + 'session_last_visit' => (int) $this->data['session_last_visit'], + 'session_time' => (int) $this->time_now, + 'session_browser' => (string) substr($this->browser, 0, 149), + 'session_forwarded_for' => (string) $this->forwarded_for, + 'session_ip' => (string) $this->ip, + 'session_autologin' => ($session_autologin) ? 1 : 0, + 'session_admin' => ($set_admin) ? 1 : 0, + 'session_viewonline' => ($viewonline) ? 1 : 0, + ); + + if ($this->update_session_page) + { + $sql_ary['session_page'] = (string) substr($this->page['page'], 0, 199); + } + + $db->sql_return_on_error(true); + + $sql = 'DELETE + FROM ' . SESSIONS_TABLE . ' + WHERE session_id = \'' . $db->sql_escape($this->session_id) . '\' + AND session_user_id = ' . ANONYMOUS; + + if (!defined('IN_ERROR_HANDLER') && (!$this->session_id || !$db->sql_query($sql) || !$db->sql_affectedrows())) + { + // Limit new sessions in 1 minute period (if required) + if (empty($this->data['session_time']) && $board_config['active_sessions']) + { + $sql = 'SELECT COUNT(session_id) AS sessions + FROM ' . SESSIONS_TABLE . ' + WHERE session_time >= ' . ($this->time_now - 60); + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if ((int) $row['sessions'] > (int) $board_config['active_sessions']) + { + header('HTTP/1.1 503 Service Unavailable'); + trigger_error('BOARD_UNAVAILABLE'); + } + } + } + + $this->session_id = $this->data['session_id'] = md5(phpBB3::unique_id()); + + $sql_ary['session_id'] = (string) $this->session_id; + $sql_ary['session_page'] = (string) substr($this->page['page'], 0, 199); + + $sql = 'INSERT INTO ' . SESSIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + + $db->sql_return_on_error(false); + + // Regenerate autologin/persistent login key + if ($session_autologin) + { + $this->set_login_key(); + } + + // refresh data + $SID = '?sid=' . $this->session_id; + $_SID = $this->session_id; + $this->data = array_merge($this->data, $sql_ary); + + if (!$bot) + { + $cookie_expire = $this->time_now + (($board_config['max_autologin_time']) ? 86400 * (int) $board_config['max_autologin_time'] : 31536000); + + $this->set_cookie('u', $this->cookie_data['u'], $cookie_expire); + $this->set_cookie('k', $this->cookie_data['k'], $cookie_expire); + $this->set_cookie('sid', $this->session_id, $cookie_expire); + + unset($cookie_expire); + } + else + { + $this->data['session_time'] = $this->data['session_last_visit'] = $this->time_now; + + // Update the last visit time + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_lastvisit = ' . (int) $this->data['session_time'] . ' + WHERE user_id = ' . (int) $this->data['user_id']; + $db->sql_query($sql); + + $SID = '?sid='; + $_SID = ''; + } + + return true; + } + + /** + * Kills a session + * + * This method does what it says on the tin. It will delete a pre-existing session. + * It resets cookie information (destroying any autologin key within that cookie data) + * and update the users information from the relevant session data. It will then + * grab guest user information. + */ + function session_kill($new_session = true) + { + global $SID, $_SID, $db, $board_config, $mx_root_path, $php_root_path, $phpEx; + + $sql = 'DELETE FROM ' . SESSIONS_TABLE . " + WHERE session_id = '" . $db->sql_escape($this->session_id) . "' + AND session_user_id = " . (int) $this->data['user_id']; + $db->sql_query($sql); + + // Allow connecting logout with external auth method logout + $method = basename(trim($board_config['auth_method'])); + if ((@include_once $mx_root_path . "includes/shared/phpbb3/includes/auth/auth_" . $method . ".$phpEx") === false) + { + if ((@include_once $mx_root_path . "includes/shared/phpbb3/includes/auth/auth_" . $method . ".$phpEx") === false) + { + mx_message_die(CRITICAL_ERROR, 'File(s3) ' . $mx_root_path . "includes/shared/phpbb3/includes/auth/auth_" . $method . ".$phpEx" . ' couldn\'t be opened.'); + } + } + //$provider = $phpbb_container->get('auth.provider.' . $method); + $method = 'logout_' . $method; + if (function_exists($method)) + { + $method($this->data, $new_session); + } + //$provider->logout($this->data, $new_session); + if ($this->data['user_id'] != ANONYMOUS) + { + // Delete existing session, update last visit info first! + if (!isset($this->data['session_time'])) + { + $this->data['session_time'] = time(); + } + + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_lastvisit = ' . (int) $this->data['session_time'] . ' + WHERE user_id = ' . (int) $this->data['user_id']; + $db->sql_query($sql); + + if ($this->cookie_data['k']) + { + $sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE . ' + WHERE user_id = ' . (int) $this->data['user_id'] . " + AND key_id = '" . $db->sql_escape(md5($this->cookie_data['k'])) . "'"; + $db->sql_query($sql); + } + + // Reset the data array + $this->data = array(); + + $sql = 'SELECT * + FROM ' . USERS_TABLE . ' + WHERE user_id = ' . ANONYMOUS; + $result = $db->sql_query($sql); + $this->data = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + } + + $cookie_expire = $this->time_now - 31536000; + $this->set_cookie('u', '', $cookie_expire); + $this->set_cookie('k', '', $cookie_expire); + $this->set_cookie('sid', '', $cookie_expire); + unset($cookie_expire); + + $SID = '?sid='; + $this->session_id = $_SID = ''; + + // To make sure a valid session is created we create one for the anonymous user + if ($new_session) + { + $this->session_create(ANONYMOUS); + } + + return true; + } + + /** + * Session garbage collection + * + * This looks a lot more complex than it really is. Effectively we are + * deleting any sessions older than an admin definable limit. Due to the + * way in which we maintain session data we have to ensure we update user + * data before those sessions are destroyed. In addition this method + * removes autologin key information that is older than an admin defined + * limit. + */ + function session_gc() + { + global $db, $board_config; + + if (!$this->time_now) + { + $this->time_now = time(); + } + + // Firstly, delete guest sessions + $sql = 'DELETE FROM ' . SESSIONS_TABLE . ' + WHERE session_user_id = ' . ANONYMOUS . ' + AND session_time < ' . (int) ($this->time_now - $board_config['session_length']); + $db->sql_query($sql); + + // Get expired sessions, only most recent for each user + $sql = 'SELECT session_user_id, session_page, MAX(session_time) AS recent_time + FROM ' . SESSIONS_TABLE . ' + WHERE session_time < ' . ($this->time_now - $board_config['session_length']) . ' + GROUP BY session_user_id, session_page'; + $result = $db->sql_query_limit($sql, 10); + + $del_user_id = array(); + $del_sessions = 0; + + while ($row = $db->sql_fetchrow($result)) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_lastvisit = ' . (int) $row['recent_time'] . ", user_lastpage = '" . $db->sql_escape($row['session_page']) . "' + WHERE user_id = " . (int) $row['session_user_id']; + $db->sql_query($sql); + + $del_user_id[] = (int) $row['session_user_id']; + $del_sessions++; + } + $db->sql_freeresult($result); + + if (sizeof($del_user_id)) + { + // Delete expired sessions + $sql = 'DELETE FROM ' . SESSIONS_TABLE . ' + WHERE ' . $db->sql_in_set('session_user_id', $del_user_id) . ' + AND session_time < ' . ($this->time_now - $board_config['session_length']); + $db->sql_query($sql); + } + + if ($del_sessions < 10) + { + // Less than 10 sessions, update gc timer ... else we want gc + // called again to delete other sessions + set_config('session_last_gc', $this->time_now, true); + } + + if ($board_config['max_autologin_time']) + { + $sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE . ' + WHERE last_login < ' . (time() - (86400 * (int) $board_config['max_autologin_time'])); + $db->sql_query($sql); + } + + return; + } + + /** + * Sets a cookie + * + * Sets a cookie of the given name with the specified data for the given length of time. + */ + function set_cookie($name, $cookiedata, $cookietime) + { + global $board_config; + + $name_data = rawurlencode($board_config['cookie_name'] . '_' . $name) . '=' . rawurlencode($cookiedata); + $expire = gmdate('D, d-M-Y H:i:s \\G\\M\\T', $cookietime); + $domain = (!$board_config['cookie_domain'] || $board_config['cookie_domain'] == 'localhost' || $board_config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $board_config['cookie_domain']; + + header('Set-Cookie: ' . $name_data . '; expires=' . $expire . '; path=' . $board_config['cookie_path'] . $domain . ((!$board_config['cookie_secure']) ? '' : '; secure') . '; HttpOnly', false); + } + + /** + * Check for banned user + * + * Checks whether the supplied user is banned by id, ip or email. If no parameters + * are passed to the method pre-existing session data is used. If $return is false + * this routine does not return on finding a banned user, it outputs a relevant + * message and stops execution. + * + * @param string|array $user_ips Can contain a string with one IP or an array of multiple IPs + */ + function check_ban($user_id = false, $user_ips = false, $user_email = false, $return = false) + { + global $board_config, $db; + + if (defined('IN_CHECK_BAN')) + { + return; + } + + $banned = false; + + $sql = 'SELECT ban_ip, ban_userid, ban_email, ban_exclude, ban_give_reason, ban_end + FROM ' . BANLIST_TABLE . ' + WHERE (ban_end >= ' . time() . ' OR ban_end = 0)'; + + // Determine which entries to check, only return those + if ($user_email === false) + { + $sql .= " AND ban_email = ''"; + } + + if ($user_ips === false) + { + $sql .= " AND (ban_ip = '' OR ban_exclude = 1)"; + } + + if ($user_id === false) + { + $sql .= ' AND (ban_userid = 0 OR ban_exclude = 1)'; + } + else + { + $sql .= ' AND (ban_userid = ' . $user_id; + + if ($user_email !== false) + { + $sql .= " OR ban_email <> ''"; + } + + if ($user_ips !== false) + { + $sql .= " OR ban_ip <> ''"; + } + + $sql .= ')'; + } + + $result = $db->sql_query($sql); + + $ban_triggered_by = 'user'; + while ($row = $db->sql_fetchrow($result)) + { + $ip_banned = false; + if (!empty($row['ban_ip'])) + { + if (!is_array($user_ips)) + { + $ip_banned = preg_match('#^' . str_replace('\*', '.*?', preg_quote($row['ban_ip'], '#')) . '$#i', $user_ips); + } + else + { + foreach ($user_ips as $user_ip) + { + if (preg_match('#^' . str_replace('\*', '.*?', preg_quote($row['ban_ip'], '#')) . '$#i', $user_ip)) + { + $ip_banned = true; + break; + } + } + } + } + + if ((!empty($row['ban_userid']) && intval($row['ban_userid']) == $user_id) || + $ip_banned || + (!empty($row['ban_email']) && preg_match('#^' . str_replace('\*', '.*?', preg_quote($row['ban_email'], '#')) . '$#i', $user_email))) + { + if (!empty($row['ban_exclude'])) + { + $banned = false; + break; + } + else + { + $banned = true; + $ban_row = $row; + + if (!empty($row['ban_userid']) && intval($row['ban_userid']) == $user_id) + { + $ban_triggered_by = 'user'; + } + else if (!empty($row['ban_ip']) && preg_match('#^' . str_replace('\*', '.*?', preg_quote($row['ban_ip'], '#')) . '$#i', $user_ips)) + { + $ban_triggered_by = 'ip'; + } + else + { + $ban_triggered_by = 'email'; + } + + // Don't break. Check if there is an exclude rule for this user + } + } + } + $db->sql_freeresult($result); + + if ($banned && !$return) + { + global $template; + + // If the session is empty we need to create a valid one... + if (empty($this->session_id)) + { + $this->session_create(ANONYMOUS); + } + + // Initiate environment ... since it won't be set at this stage + $this->setup(); + + // Logout the user, banned users are unable to use the normal 'logout' link + if ($this->data['user_id'] != ANONYMOUS) + { + $this->session_kill(); + } + + // We show a login box here to allow founders accessing the board if banned by IP + if (defined('IN_LOGIN') && $this->data['user_id'] == ANONYMOUS) + { + global $phpEx; + + $this->setup('ucp'); + $this->data['is_registered'] = $this->data['is_bot'] = false; + + // Set as a precaution to allow login_box() handling this case correctly as well as this function not being executed again. + define('IN_CHECK_BAN', 1); + + login_box("index.$phpEx"); + + // The false here is needed, else the user is able to circumvent the ban. + $this->session_kill(false); + } + + // Ok, we catch the case of an empty session id for the anonymous user... + // This can happen if the user is logging in, banned by username and the login_box() being called "again". + if (empty($this->session_id) && defined('IN_CHECK_BAN')) + { + $this->session_create(ANONYMOUS); + } + + + // Determine which message to output + $till_date = ($ban_row['ban_end']) ? $this->format_date($ban_row['ban_end']) : ''; + $message = ($ban_row['ban_end']) ? 'BOARD_BAN_TIME' : 'BOARD_BAN_PERM'; + + $message = sprintf($this->lang[$message], $till_date, '', ''); + $message .= ($ban_row['ban_give_reason']) ? '
' . sprintf($this->lang['BOARD_BAN_REASON'], $ban_row['ban_give_reason']) : ''; + $message .= '
' . $this->lang['BAN_TRIGGERED_BY_' . strtoupper($ban_triggered_by)] . ''; + + trigger_error($message); + } + + return ($banned) ? true : false; + } + + /** + * Check if ip is blacklisted + * This should be called only where absolutly necessary + * + * Only IPv4 (rbldns does not support AAAA records/IPv6 lookups) + * + * @author satmd (from the php manual) + * @param string $mode register/post - spamcop for example is ommitted for posting + * @return false if ip is not blacklisted, else an array([checked server], [lookup]) + */ + function check_dnsbl($mode, $ip = false) + { + if ($ip === false) + { + $ip = $this->ip; + } + + $dnsbl_check = array( + 'list.dsbl.org' => 'http://dsbl.org/listing?', + 'sbl-xbl.spamhaus.org' => 'http://www.spamhaus.org/query/bl?ip=', + ); + + if ($mode == 'register') + { + $dnsbl_check['bl.spamcop.net'] = 'http://spamcop.net/bl.shtml?'; + } + + if ($ip) + { + $quads = explode('.', $ip); + $reverse_ip = $quads[3] . '.' . $quads[2] . '.' . $quads[1] . '.' . $quads[0]; + + // Need to be listed on all servers... + $listed = true; + $info = array(); + + foreach ($dnsbl_check as $dnsbl => $lookup) + { + if (phpbb_checkdnsrr($reverse_ip . '.' . $dnsbl . '.', 'A') === true) + { + $info = array($dnsbl, $lookup . $ip); + } + else + { + $listed = false; + } + } + + if ($listed) + { + return $info; + } + } + + return false; + } + + /** + * Check if URI is blacklisted + * This should be called only where absolutly necessary, for example on the submitted website field + * This function is not in use at the moment and is only included for testing purposes, it may not work at all! + * This means it is untested at the moment and therefore commented out + * + * @param string $uri URI to check + * @return true if uri is on blacklist, else false. Only blacklist is checked (~zero FP), no grey lists + function check_uribl($uri) + { + // Normally parse_url() is not intended to parse uris + // We need to get the top-level domain name anyway... change. + $uri = parse_url($uri); + + if ($uri === false || empty($uri['host'])) + { + return false; + } + + $uri = trim($uri['host']); + + if ($uri) + { + // One problem here... the return parameter for the "windows" method is different from what + // we expect... this may render this check useless... + if (phpbb_checkdnsrr($uri . '.multi.uribl.com.', 'A') === true) + { + return true; + } + } + + return false; + } + */ + + /** + * Set/Update a persistent login key + * + * This method creates or updates a persistent session key. When a user makes + * use of persistent (formerly auto-) logins a key is generated and stored in the + * DB. When they revisit with the same key it's automatically updated in both the + * DB and cookie. Multiple keys may exist for each user representing different + * browsers or locations. As with _any_ non-secure-socket no passphrase login this + * remains vulnerable to exploit. + */ + function set_login_key($user_id = false, $key = false, $user_ip = false) + { + global $board_config, $db; + + $user_id = ($user_id === false) ? $this->data['user_id'] : $user_id; + $user_ip = ($user_ip === false) ? $this->ip : $user_ip; + $key = ($key === false) ? (($this->cookie_data['k']) ? $this->cookie_data['k'] : false) : $key; + + $key_id = phpBB3::unique_id(hexdec(substr($this->session_id, 0, 8))); + + $sql_ary = array( + 'key_id' => (string) md5($key_id), + 'last_ip' => (string) $this->ip, + 'last_login' => (int) time() + ); + + if (!$key) + { + $sql_ary += array( + 'user_id' => (int) $user_id + ); + } + + if ($key) + { + $sql = 'UPDATE ' . SESSIONS_KEYS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE user_id = ' . (int) $user_id . " + AND key_id = '" . $db->sql_escape(md5($key)) . "'"; + } + else + { + $sql = 'INSERT INTO ' . SESSIONS_KEYS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); + } + $db->sql_query($sql); + + $this->cookie_data['k'] = $key_id; + + return false; + } + + /** + * Reset all login keys for the specified user + * + * This method removes all current login keys for a specified (or the current) + * user. It will be called on password change to render old keys unusable + */ + function reset_login_keys($user_id = false) + { + global $board_config, $db; + + $user_id = ($user_id === false) ? $this->data['user_id'] : $user_id; + + $sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE . ' + WHERE user_id = ' . (int) $user_id; + $db->sql_query($sql); + + // Let's also clear any current sessions for the specified user_id + // If it's the current user then we'll leave this session intact + $sql_where = 'session_user_id = ' . (int) $user_id; + $sql_where .= ($user_id === $this->data['user_id']) ? " AND session_id <> '" . $db->sql_escape($this->session_id) . "'" : ''; + + $sql = 'DELETE FROM ' . SESSIONS_TABLE . " + WHERE $sql_where"; + $db->sql_query($sql); + + // We're changing the password of the current user and they have a key + // Lets regenerate it to be safe + if ($user_id === $this->data['user_id'] && $this->cookie_data['k']) + { + $this->set_login_key($user_id); + } + } + + /** + * Check if the request originated from the same page. + * @param bool $check_script_path If true, the path will be checked as well + */ + function validate_referer($check_script_path = false) + { + global $board_config; + + // no referer - nothing to validate, user's fault for turning it off (we only check on POST; so meta can't be the reason) + if (empty($this->referer) || empty($this->host)) + { + return true; + } + + $host = htmlspecialchars($this->host); + $ref = substr($this->referer, strpos($this->referer, '://') + 3); + + if (!(stripos($ref, $host) === 0) && (!$board_config['force_server_vars'] || !(stripos($ref, $board_config['server_name']) === 0))) + { + return false; + } + else if ($check_script_path && rtrim($this->page['root_script_path'], '/') !== '') + { + $ref = substr($ref, strlen($host)); + $server_port = (!empty($_SERVER['SERVER_PORT'])) ? (int) $_SERVER['SERVER_PORT'] : (int) getenv('SERVER_PORT'); + + if ($server_port !== 80 && $server_port !== 443 && stripos($ref, ":$server_port") === 0) + { + $ref = substr($ref, strlen(":$server_port")); + } + + if (!(stripos(rtrim($ref, '/'), rtrim($this->page['root_script_path'], '/')) === 0)) + { + return false; + } + } + + return true; + } + + function unset_admin() + { + global $db; + $sql = 'UPDATE ' . SESSIONS_TABLE . ' + SET session_admin = 0 + WHERE session_id = \'' . $db->sql_escape($this->session_id) . '\''; + $db->sql_query($sql); + } + + /** ******************************************************************************************************* + * Include the User class + ******************************************************************************************************* */ + + /** + * Setup basic user-specific items (style, language, ...) + * Note: We've split original phpbb3 setup() method into setup() and setup_style() + */ + function setup($lang_set = false, $style = false) + { + global $db, $template, $board_config, $userdata, $phpbb_auth, $phpEx, $phpbb_root_path, $mx_root_path, $mx_cache; + global $mx_request_vars, $portal_config; //added for mxp + global $lang; //added for mxp + + $session_lang = ''; + /* + * Added here for reference and future implementation of a lang block in mx_coreblocks were board_config can be taken from portal_config + * + if ($board_config['lang_select_enable'] || $board_config['lang_click_enable']) + { + $session_lang_save = phpBB3::request_var('session_lang_save', false); + if (isset($session_lang_save) && $session_lang_save && $this->data['session_lang']) + { + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_lang = '" . $this->data['session_lang'] . "' + WHERE user_id = " . $this->data['user_id']; + $db->sql_query($sql); + } + + $session_lang_reset = phpBB3::request_var('session_lang_reset', false); + if (isset($session_lang_reset) && $session_lang_reset) + { + $session_lang = ''; + } + else + { + $session_lang = phpBB3::request_var('session_lang', ''); + } + + if ((isset($session_lang) && $session_lang) || $session_lang_reset) + { + $sql = 'UPDATE ' . SESSIONS_TABLE . " + SET session_lang = '" . $session_lang . "' + WHERE session_id = '" . $this->session_id . "'"; + $db->sql_query($sql); + } + elseif (isset($this->data['session_lang']) && $this->data['session_lang']) + { + $session_lang = $this->data['session_lang']; + } + } + + if (($board_config['lang_select_enable'] || $board_config['lang_click_enable']) && isset($session_lang) && $session_lang) + { + $this->data['user_lang'] = $session_lang; + $this->lang_name = (file_exists($this->lang_path . $this->data['user_lang'] . "/common.$phpEx")) ? $this->data['user_lang'] : basename($this->encode_lang($this->lang['default_lang'])); + + if ($this->data['user_id'] != ANONYMOUS) + { + $this->date_format = $this->data['user_dateformat']; + $this->timezone = $this->data['user_timezone'] * 3600; + $this->dst = $this->data['user_dst'] * 3600; + } + else + { + $this->date_format = $board_config['default_dateformat']; + $this->timezone = $board_config['board_timezone'] * 3600; + $this->dst = $board_config['board_dst'] * 3600; + } + } + */ + $lang_set = !$lang_set ? (defined('IN_ADMIN') ? 'acp/common' : 'common') : $lang_set; + + if ($this->data['session_logged_in']) + { + $this->lang_name = (file_exists($phpbb_root_path . 'language/' . $this->encode_lang($this->data['user_lang']) . "/common.$phpEx")) ? $this->encode_lang($this->data['user_lang']) : ((file_exists($phpbb_root_path . 'language/' . $this->encode_lang($this->lang['default_lang']) . "/common.$phpEx")) ? $this->encode_lang($this->lang['default_lang']) : 'en'); + $this->lang_path = $phpbb_root_path . 'language/' . $this->lang_name . '/'; + + $this->date_format = $this->data['user_dateformat']; + $this->timezone = $this->data['user_timezone'] * 3600; + $this->dst = $this->data['user_dst'] * 3600; + } + else + { + $this->lang_name = (file_exists($phpbb_root_path . 'language/' . $this->encode_lang($this->lang['default_lang']) . "/common.$phpEx")) ? $this->encode_lang($this->lang['default_lang']) : 'en'; + $this->lang_path = $phpbb_root_path . 'language/' . $this->lang_name . '/'; + $this->date_format = $board_config['default_dateformat']; + $this->timezone = $board_config['board_timezone'] * 3600; + $this->dst = $board_config['board_dst'] * 3600; + + /** + * If a guest user is surfing, we try to guess his/her language first by obtaining the browser language + * If re-enabled we need to make sure only those languages installed are checked + * Commented out so we do not loose the code. + * language checking added 2008-08-15 by Martin Truckenbrodt + **/ + if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) + { + $lang_iso_xx_yy = array(); + $lang_iso_xx = array(); + $accept_lang_xx_yy = array(); + $accept_lang_xx = array(); + + $sql = 'SELECT lang_iso FROM ' . LANG_TABLE; + $result = $db->sql_query($sql, 3600); + + while ($row = $db->sql_fetchrow($result)) + { + if (file_exists($phpbb_root_path . 'language/' . $row['lang_iso'] . "/common.$phpEx")) + { + $lang_iso_xx_yy[] = $row['lang_iso']; + if (strlen($row['lang_iso']) > 4) + { + $lang_iso_xx[$row['lang_iso']] = substr($row['lang_iso'], 0, 2); + } + } + } + $accept_lang_ary = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); + + foreach ($accept_lang_ary as $accept_lang) + { + // Set correct format ... guess full xx_yy form + $accept_lang_xx_yy = basename(substr($accept_lang, 0, 2) . '_' . strtolower(substr($accept_lang, 3, 2))); + // Set correct format ... guess only xx form + $accept_lang_xx = basename(substr($accept_lang, 0, 2)); + + // browser xx-YY == board xx_yy and + // browser xx == board xx + if (in_array($accept_lang_xx_yy, $lang_iso_xx_yy)) + { + $this->lang_name = $board_config['default_lang'] = $accept_lang_xx_yy; + break; + } + // browser xx-YY => xx == board xx + else if (in_array($accept_lang_xx, $lang_iso_xx_yy)) + { + $this->lang_name = $board_config['default_lang'] = $accept_lang_xx; + break; + } + // browser xx == board xx_yy => xx + else if (in_array($accept_lang_xx, $lang_iso_xx) && $lang_iso_xx != '') + { + $this->lang_name = $board_config['default_lang'] = array_search($accept_lang_xx, $lang_iso_xx); + break; + } + // board default language + else + { + $this->lang_name = (file_exists($phpbb_root_path . 'language/' . $this->encode_lang($this->lang['default_lang']) . "/common.$phpEx")) ? $this->encode_lang($this->lang['default_lang']) : 'en'; + } + } + $this->data['user_lang'] = $this->lang_name; + } + /* + */ + } + + /* We include common language file here to not load it every time a custom language file is included + $lang = &$this->lang; + */ + $include_result = (defined('DEBUG_EXTRA')) ? "" : "@"; // Do not suppress error if in DEBUG_EXTRA mode + if (("$include_result".include $this->lang_path . "common.$phpEx") === false) + { + //this will fix the path for anonymouse users + if ((@include $phpbb_root_path . $this->lang_path . "common.$phpEx") === false) + { + die('Language file ' . $this->lang_path . "common.$phpEx" . ' couldn\'t be opened.'); + } + } + + // + // We include common language file here to not load it every time a custom language file is included + // + $this->add_lang($lang_set); + + unset($lang_set); + } + + /** + * Enter description here... + * Note: We've split original phpbb3 setup() method into setup() and setup_style() + */ + function setup_style() + { + global $db, $template, $board_config, $userdata, $phpbb_auth, $phpEx, $phpbb_root_path, $mx_root_path, $mx_cache; + global $mx_request_vars, $portal_config, $board_config, $mx_backend; //added for mxp + + if (!empty($_GET['style']) && $phpbb_auth->acl_get('a_styles')) + { + global $SID, $_EXTRA_URL; + $style = phpBB3::request_var('style', 0); + // BEGIN Styles_Demo MOD for phpBB Block + $style_value = ''; + $SID .= '&style=' . $style; + $_EXTRA_URL = array('style=' . $style); + } + else + { + $style = $this->style; // From main style init. Should be correct and valid. + $style_value = $this->style_name; + // BEGIN Styles_Demo MOD for phpBB Block + /* */ + if(!$board_config['override_user_style'] && ($this->data['user_id'] != ANONYMOUS)) + { + // Set up style + $user_style = $this->data['user_style'] ? $this->data['user_style'] : $this->phpbb_style['style_id']; + //If user have other style in mxp then the one from phpBB not to have forum page and modules graphics will be messaed up + //Anonymouse users should see all block graphic corect + //Query phpBB style_id corepondent to mxp themes_id + $sql = "SELECT s.style_id, s.style_name + FROM " . MX_THEMES_TABLE . " AS m, " . STYLES_TABLE . " AS s, " . STYLES_TEMPLATE_TABLE . " AS t + WHERE m.themes_id = " . (int) $user_style . " + AND t.template_path = m.template_name + AND t.template_id = s.template_id"; + if ($row = $db->sql_fetchrow($db->sql_query($sql))) + { + $style = $row['style_id']; //User style + $style_value = $row['style_name']; //User style name + } + else + { + $style = $this->data['user_style'] ? $this->data['user_style'] : $board_config['default_style']; + } + } + else + { + $default_style = $portal_config['default_style']; + //If user have other style in mxp then the one from phpBB not to have forum page and modules graphics will be messaed up + //Anonymouse users should see all block graphic corect + //Query phpBB style_id corepondent to mxp themes_id + $sql = "SELECT s.style_id, s.style_name + FROM " . MX_THEMES_TABLE . " AS m, " . STYLES_TABLE . " AS s, " . STYLES_TEMPLATE_TABLE . " AS t + WHERE m.themes_id = " . (int) $default_style . " + AND t.template_path = m.template_name + AND t.template_id = s.template_id"; + if ($row = $db->sql_fetchrow($db->sql_query($sql))) + { + $style = $row['style_id']; //User style + $style_value = $row['style_name']; //User style name + } + else + { + $style = $this->data['user_style'] ? $this->data['user_style'] : $board_config['default_style']; + } + } + /* */ + // Set up style Temp code should be removed after bugtraking + //$style = ($style) ? $style : ((!$board_config['override_user_style'] && $this->data['user_id'] != ANONYMOUS) ? $this->data['user_style'] : $this->phpbb_style['style_id']); + } + + if (isset($_GET['demostyle'])) + { + $style_value = phpBB3::request_var('demostyle', ''); + if (intval($style_value) == 0) + { + //Query phpBB style_id corepondent to mxp style_name + //Any Demo Style here should work also for portal and forums + //Any Demo Style Name should be supported using same guild lines for portal as for forums for e.g. with spaces etc. + $sql = "SELECT s.style_id, s.style_name + FROM " . MX_THEMES_TABLE . " AS m, " . STYLES_TABLE . " AS s, " . STYLES_TEMPLATE_TABLE . " AS t + WHERE s.style_active = 1 AND s.style_name = '$style_value' + AND s.style_name = m.style_name + AND t.template_id = s.template_id"; + if(!$row = @$db->sql_fetchrow(@$db->sql_query($sql))) + { + die('Could not find style name '. $style_value . '!'); + } + else + { + $style_value = $row['style_id']; + } + } + else + { + //Query phpBB style_id corepondent to mxp themes_id + //Any Demo Style here should work also for portal and forums + //Any Demo Style Name should be supported using same guild lines for portal as for forums for e.g. with spaces etc. + $sql = "SELECT s.style_id, s.style_name + FROM " . MX_THEMES_TABLE . " AS m, " . STYLES_TABLE . " AS s, " . STYLES_TEMPLATE_TABLE . " AS t + WHERE m.themes_id = " . (int) $style_value . " + AND s.style_name = m.style_name + AND t.template_id = s.template_id"; + if(!$row = $db->sql_fetchrow($db->sql_query($sql))) + { + die('style_id ' . $style_value . ' not found'); + } + } + $this->set_cookie('change_style', $style_value, time() + 31536000); + } + elseif (isset($_COOKIE[$board_config['cookie_name'] . '_change_style'])) + { + $style_value = $_COOKIE[$board_config['cookie_name'] . '_change_style']; + } + + //Change the value before query + if (!empty($style_value)) + { + $style = $style_value; + } + + //We should never get this, temp fix for GoogleBot-2.1 crawler + //Remove this Deguging Code after solved + if ((intval($style) == 0) && empty($style_value)) + { + $style_value = 'prosilver'; + } + $phpbb_style = $style; + $phpbb_style_value = $style_value; + + // END Styles_Demo MOD + if (isset($style_value)) + { + //Query phpBB style_name + $sql = "SELECT s.style_id, s.style_name, t.template_storedb, t.template_path, t.template_id, t.bbcode_bitfield, c.theme_path, c.theme_name, c.theme_storedb, c.theme_id, i.imageset_path, i.imageset_id, i.imageset_name + FROM " . STYLES_TABLE . " AS s, " . STYLES_TEMPLATE_TABLE . " AS t, " . STYLES_THEME_TABLE . " AS c, " . STYLES_IMAGESET_TABLE . " i + WHERE s.style_active = 1 AND s.style_name = '$style_value' + AND t.template_id = s.template_id + AND c.theme_id = s.theme_id + AND i.imageset_id = s.imageset_id"; + if(($result = $db->sql_query($sql)) && ($row = $db->sql_fetchrow($result))) + { + $style = $row['style_id']; + $style_value = $row['style_name']; + } + else + { + mx_message_die(CRITICAL_ERROR, "Could not query database for phpbb_styles info style_name [$style]", "", __LINE__, __FILE__, $sql); + } + } + elseif (intval($style) !== 0) + { + //Query phpBB style_id get from main style init. Should be correct and valid. + $sql = "SELECT s.style_id, s.style_name, t.template_storedb, t.template_path, t.template_id, t.bbcode_bitfield, c.theme_path, c.theme_name, c.theme_storedb, c.theme_id, i.imageset_path, i.imageset_id, i.imageset_name + FROM " . MX_THEMES_TABLE . " AS m, " . STYLES_TABLE . " AS s, " . STYLES_TEMPLATE_TABLE . " AS t, " . STYLES_THEME_TABLE . " AS c, " . STYLES_IMAGESET_TABLE . " i + WHERE s.style_id = " . (int) $style . " + AND s.style_name = m.style_name + AND t.template_id = s.template_id + AND c.theme_id = s.theme_id + AND i.imageset_id = s.imageset_id"; + if(($result = $db->sql_query($sql)) && ($row = $db->sql_fetchrow($result))) + { + $style = $row['style_id']; + $style_value = $row['style_name']; + // MXP themes_id = $row['themes_id'] + } + else + { + mx_message_die(CRITICAL_ERROR, "Could not query database for phpbb_styles info style_id [$style]", "", __LINE__, __FILE__, $sql); + } + } + + $this->theme = is_array($this->theme) ? array_merge($this->theme, $row) : $row; + $db->sql_freeresult($result); + + // User has wrong style + if (!$this->theme && $style == $this->data['user_style']) + { + $style = $this->data['user_style'] = $board_config['default_style']; + + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_style = $style + WHERE user_id = {$this->data['user_id']}"; + $db->sql_query($sql); + + $sql = 'SELECT s.style_id, s.style_name, t.template_storedb, t.template_path, t.template_id, t.bbcode_bitfield, c.theme_path, c.theme_name, c.theme_storedb, c.theme_id, i.imageset_path, i.imageset_id, i.imageset_name + FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c, ' . STYLES_IMAGESET_TABLE . " i + WHERE s.style_id = $style + AND t.template_id = s.template_id + AND c.theme_id = s.theme_id + AND i.imageset_id = s.imageset_id"; + $result = $db->sql_query($sql, 3600); + $this->theme = is_array($this->theme) ? array_merge($this->theme, $db->sql_fetchrow($result)) : $db->sql_fetchrow($result); + $db->sql_freeresult($result); + $style = $this->theme['style_id']; + $style_value = $this->theme['style_name']; + } + + if (!$this->theme) + { + trigger_error('Could not get style data', E_USER_ERROR); + } + + // Now parse the cfg file and cache it + $parsed_items = $mx_backend->obtain_cfg_items($this->theme); + + // We are only interested in the theme configuration for now + $parsed_items = $parsed_items['theme']; + + $check_for = array( + 'parse_css_file' => (int) 0, + 'pagination_sep' => (string) ', ' + ); + + foreach ($check_for as $key => $default_value) + { + $this->theme[$key] = (isset($parsed_items[$key])) ? $parsed_items[$key] : $default_value; + settype($this->theme[$key], gettype($default_value)); + + if (is_string($default_value)) + { + $this->theme[$key] = htmlspecialchars($this->theme[$key]); + } + } + + // If the style author specified the theme needs to be cached + // (because of the used paths and variables) than make sure it is the case. + // For example, if the theme uses language-specific images it needs to be stored in db. + if (!$this->theme['theme_storedb'] && $this->theme['parse_css_file']) + { + $this->theme['theme_storedb'] = 1; + + $stylesheet = file_get_contents("{$phpbb_root_path}styles/{$this->theme['theme_path']}/theme/stylesheet.css"); + // Match CSS imports + $matches = array(); + preg_match_all('/@import url\(["\'](.*)["\']\);/i', $stylesheet, $matches); + if (sizeof($matches)) + { + $content = ''; + foreach ($matches[0] as $idx => $match) + { + if ($content = @file_get_contents("{$phpbb_root_path}styles/{$this->theme['theme_path']}/theme/" . $matches[1][$idx])) + { + $content = trim($content); + } + else + { + $content = ''; + } + $stylesheet = str_replace($match, $content, $stylesheet); + } + unset($content); + } + + $stylesheet = str_replace('./', 'styles/' . $this->theme['theme_path'] . '/theme/', $stylesheet); + + $sql_ary = array( + 'theme_data' => $stylesheet, + 'theme_mtime' => time(), + 'theme_storedb' => 1 + ); + + $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE theme_id = ' . $this->theme['theme_id']; + $db->sql_query($sql); + + unset($sql_ary); + } + + $template->set_template(); + + $this->img_lang = (file_exists($phpbb_root_path . 'styles/' . $this->theme['imageset_path'] . '/imageset/' . $this->lang_name)) ? $this->lang_name : $this->encode_lang($board_config['default_lang']); + + $sql = 'SELECT image_name, image_filename, image_lang, image_height, image_width + FROM ' . STYLES_IMAGESET_DATA_TABLE . ' + WHERE imageset_id = ' . $this->theme['imageset_id'] . " + AND image_filename <> '' + AND image_lang IN ('" . $db->sql_escape($this->img_lang) . "', '')"; + $result = $db->sql_query($sql, 3600); + + $localised_images = false; + while ($row = $db->sql_fetchrow($result)) + { + if ($row['image_lang']) + { + $localised_images = true; + } + + $this->img_array[$row['image_name']] = $row; + } + $db->sql_freeresult($result); + // there were no localised images, try to refresh the localised imageset for the user's language + if (!$localised_images) + { + // Attention: this code ignores the image definition list from acp_styles and just takes everything + // that the config file contains + $sql_ary = array(); + + $db->sql_transaction('begin'); + + $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . ' + WHERE imageset_id = ' . $this->theme['imageset_id'] . ' + AND image_lang = \'' . $db->sql_escape($this->img_lang) . '\''; + $result = $db->sql_query($sql); + + if (@file_exists("{$phpbb_root_path}styles/{$this->theme['imageset_path']}/imageset/{$this->img_lang}/imageset.cfg")) + { + $cfg_data_imageset_data = phpBB3::parse_cfg_file("{$phpbb_root_path}styles/{$this->theme['imageset_path']}/imageset/{$this->img_lang}/imageset.cfg"); + foreach ($cfg_data_imageset_data as $image_name => $value) + { + if (strpos($value, '*') !== false) + { + if (substr($value, -1, 1) === '*') + { + list($image_filename, $image_height) = explode('*', $value); + $image_width = 0; + } + else + { + list($image_filename, $image_height, $image_width) = explode('*', $value); + } + } + else + { + $image_filename = $value; + $image_height = $image_width = 0; + } + + if (strpos($image_name, 'img_') === 0 && $image_filename) + { + $image_name = substr($image_name, 4); + $sql_ary[] = array( + 'image_name' => (string) $image_name, + 'image_filename' => (string) $image_filename, + 'image_height' => (int) $image_height, + 'image_width' => (int) $image_width, + 'imageset_id' => (int) $this->theme['imageset_id'], + 'image_lang' => (string) $this->img_lang, + ); + } + } + } + + if (sizeof($sql_ary)) + { + $db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary); + $db->sql_transaction('commit'); + $mx_cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE); + + mx_add_log('admin', 'LOG_IMAGESET_LANG_REFRESHED', $this->theme['imageset_name'], $this->img_lang); + } + else + { + $db->sql_transaction('commit'); + mx_add_log('admin', 'LOG_IMAGESET_LANG_MISSING', $this->theme['imageset_name'], $this->img_lang); + } + } + // If this function got called from the error handler we are finished here. + if (defined('IN_ERROR_HANDLER')) + { + return; + } + // Disable board if the install/ directory is still present + // For the brave development army we do not care about this, else we need to comment out this everytime we develop locally + if (!defined('DEBUG_EXTRA') && !defined('ADMIN_START') && !defined('IN_INSTALL') && !defined('IN_LOGIN') && file_exists($phpbb_root_path . 'install')) + { + // Adjust the message slightly according to the permissions + if ($phpbb_auth->acl_gets('a_', 'm_') || $phpbb_auth->acl_getf_global('m_')) + { + $message = 'REMOVE_INSTALL'; + } + else + { + $message = (!empty($portal_config['disabled_message'])) ? $portal_config['disabled_message'] : 'BOARD_DISABLE'; + } + trigger_error($message); + } + // Is portal disabled and user not an admin or moderator? + if (($portal_config['portal_status'] == '0') && !defined('IN_LOGIN') && !$phpbb_auth->acl_gets('a_', 'm_') && !$phpbb_auth->acl_getf_global('m_')) + { + @header('HTTP/1.1 503 Service Unavailable'); + // Is board disabled and user not an admin or moderator? + if($board_config['board_disable_mess_st']) + { + $message_st = $board_config['board_disable_message']; + } + else + { + $message_st = (!empty($lang['Board_disabled'])) ? $lang['Board_disabled'] : 'BOARD_DISABLE'; + } + $message = (!empty($portal_config['disabled_message'])) ? $portal_config['disabled_message'] : $message_st; + trigger_error($message); + } + // Is load exceeded? + if ($board_config['limit_load'] && $this->load !== false) + { + if ($this->load > floatval($board_config['limit_load']) && !defined('IN_LOGIN')) + { + // Set board disabled to true to let the admins/mods get the proper notification + $board_config['board_disable'] = '1'; + $portal_config['portal_status'] = '0'; + if (!$phpbb_auth->acl_gets('a_', 'm_') && !$phpbb_auth->acl_getf_global('m_')) + { + @header('HTTP/1.1 503 Service Unavailable'); + trigger_error('BOARD_UNAVAILABLE'); + } + } + } + if (isset($this->data['session_viewonline'])) + { + // Make sure the user is able to hide his session + if (!$this->data['session_viewonline']) + { + // Reset online status if not allowed to hide the session... + if (!$phpbb_auth->acl_get('u_hideonline')) + { + $sql = 'UPDATE ' . SESSIONS_TABLE . ' + SET session_viewonline = 1 + WHERE session_user_id = ' . $this->data['user_id']; + $db->sql_query($sql); + $this->data['session_viewonline'] = 1; + } + } + else if (!$this->data['user_allow_viewonline']) + { + // the user wants to hide and is allowed to -> cloaking device on. + if ($phpbb_auth->acl_get('u_hideonline')) + { + $sql = 'UPDATE ' . SESSIONS_TABLE . ' + SET session_viewonline = 0 + WHERE session_user_id = ' . $this->data['user_id']; + $db->sql_query($sql); + $this->data['session_viewonline'] = 0; + } + } + } + // Does the user need to change their password? If so, redirect to the + // ucp profile reg_details page ... of course do not redirect if we're already in the ucp + if (!defined('IN_ADMIN') && !defined('ADMIN_START') && $board_config['chg_passforce'] && $this->data['is_registered'] && $phpbb_auth->acl_get('u_chgpasswd') && $this->data['user_passchg'] < time() - ($board_config['chg_passforce'] * 86400)) + { + if (strpos($this->page['query_string'], 'mode=reg_details') === false && $this->page['page_name'] != "ucp.$phpEx") + { + mx_redirect(mx_append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=profile&mode=reg_details')); + } + } + return; + } + + /** + * Add Language Items - use_db and use_help are assigned where needed (only use them to force inclusion) + * + * @param mixed $lang_set specifies the language entries to include + * @param bool $use_db internal variable for recursion, do not use + * @param bool $use_help internal variable for recursion, do not use + * + * Examples: + *+ * $lang_set = array('posting', 'help' => 'faq'); + * $lang_set = array('posting', 'viewtopic', 'help' => array('bbcode', 'faq')) + * $lang_set = array(array('posting', 'viewtopic'), 'help' => array('bbcode', 'faq')) + * $lang_set = 'posting' + * $lang_set = array('help' => 'faq', 'db' => array('help:faq', 'posting')) + *
+ */ + function add_lang($lang_set, $use_db = false, $use_help = false) + { + global $phpEx; + + if (is_array($lang_set)) + { + foreach ($lang_set as $key => $lang_file) + { + // Please do not delete this line. + // We have to force the type here, else [array] language inclusion will not work + $key = (string) $key; + + if ($key == 'db') + { + $this->add_lang($lang_file, true, $use_help); + } + else if ($key == 'help') + { + $this->add_lang($lang_file, $use_db, true); + } + else if (!is_array($lang_file)) + { + $this->set_lang($this->lang, $this->help, $lang_file, $use_db, $use_help); + } + else + { + $this->add_lang($lang_file, $use_db, $use_help); + } + } + unset($lang_set); + } + elseif ($lang_set) + { + $this->set_lang($this->lang, $this->help, $lang_set, $use_db, $use_help); + } + } + + /** + * Set language entry (called by add_lang) + * @access private + */ + function set_lang(&$lang, &$help, $lang_file, $use_db = false, $use_help = false) + { + global $phpbb_root_path, $phpEx; + + // Make sure the language path is set (if the user setup did not happen it is not set) + if (!$this->lang_path) + { + global $board_config; + + $this->lang_path = $phpbb_root_path . 'language/' . basename($board_config['phpbb_lang']) . '/'; + } + + // $lang == $this->lang + // $help == $this->help + // - add appropriate variables here, name them as they are used within the language file... + if (!$use_db) + { + if ($use_help && strpos($lang_file, '/') !== false) + { + $language_filename = $this->lang_path . substr($lang_file, 0, stripos($lang_file, '/') + 1) . 'help_' . substr($lang_file, stripos($lang_file, '/') + 1) . '.' . $phpEx; + } + else + { + $language_filename = $this->lang_path . (($use_help) ? 'help_' : '') . $lang_file . '.' . $phpEx; + } + + //fix for mxp + if ((@include $language_filename) === false) + { + //this will fix the path for anonymouse users + if ((@include $phpbb_root_path . $language_filename) === false) + { + die('Language file ' . $language_filename . ' couldn\'t be opened.'); + } + } + } + else + { + // Get Database Language Strings + // Put them into $lang if nothing is prefixed, put them into $help if help: is prefixed + // For example: help:faq, posting + die("You should not use db with MX-Publisher!"); + } + + // We include common language file here to not load it every time a custom language file is included + $this->lang = &$lang; + } + + /** + * Format user date + * + * @param int $gmepoch unix timestamp + * @param string $format date format in date() notation. | used to indicate relative dates, for example |d m Y|, h:i is translated to Today, h:i. + * @param bool $forcedate force non-relative date format. + * + * @return mixed translated date + */ + function format_date($gmepoch, $format = false, $forcedate = false) + { + static $midnight; + static $date_cache; + + $format = (!$format) ? $this->date_format : $format; + $now = time(); + $delta = $now - $gmepoch; + + if (!isset($date_cache[$format])) + { + // Is the user requesting a friendly date format (i.e. 'Today 12:42')? + $date_cache[$format] = array( + 'is_short' => strpos($format, '|'), + 'format_short' => substr($format, 0, strpos($format, '|')) . '||' . substr(strrchr($format, '|'), 1), + 'format_long' => str_replace('|', '', $format), + // Filter out values that are not strings (e.g. arrays) for strtr(). + 'lang' => array_filter($this->lang['datetime'], 'is_string'), + ); + + // Short representation of month in format? Some languages use different terms for the long and short format of May + if ((strpos($format, '\M') === false && strpos($format, 'M') !== false) || (strpos($format, '\r') === false && strpos($format, 'r') !== false)) + { + $date_cache[$format]['lang']['May'] = $this->lang['datetime']['May_short']; + } + } + + // Zone offset + $zone_offset = $this->timezone + $this->dst; + + // Show date <= 1 hour ago as 'xx min ago' but not greater than 60 seconds in the future + // A small tolerence is given for times in the future but in the same minute are displayed as '< than a minute ago' + if ($delta <= 3600 && $delta > -60 && ($delta >= -5 || (($now / 60) % 60) == (($gmepoch / 60) % 60)) && $date_cache[$format]['is_short'] !== false && !$forcedate && isset($this->lang['datetime']['AGO'])) + { + return $this->lang(array('datetime', 'AGO'), max(0, (int) floor($delta / 60))); + } + + if (!$midnight) + { + list($d, $m, $y) = explode(' ', gmdate('j n Y', time() + $zone_offset)); + $midnight = gmmktime(0, 0, 0, $m, $d, $y) - $zone_offset; + } + + if ($date_cache[$format]['is_short'] !== false && !$forcedate && !($gmepoch < $midnight - 86400 || $gmepoch > $midnight + 172800)) + { + $day = false; + + if ($gmepoch > $midnight + 86400) + { + $day = 'TOMORROW'; + } + else if ($gmepoch > $midnight) + { + $day = 'TODAY'; + } + else if ($gmepoch > $midnight - 86400) + { + $day = 'YESTERDAY'; + } + + if ($day !== false) + { + return str_replace('||', $this->lang['datetime'][$day], strtr(@gmdate($date_cache[$format]['format_short'], $gmepoch + $zone_offset), $date_cache[$format]['lang'])); + } + } + + return strtr(@gmdate($date_cache[$format]['format_long'], $gmepoch + $zone_offset), $date_cache[$format]['lang']); + } + + /** + * Get language id currently used by the user + **/ + function get_iso_lang_id() + { + global $board_config, $db; + + if (!empty($this->lang_id)) + { + return $this->lang_id; + } + + if (!$this->lang_name) + { + $this->lang_name = $board_config['default_lang']; + } + + $sql = 'SELECT lang_id + FROM ' . LANG_TABLE . " + WHERE lang_iso = '" . $db->sql_escape($this->lang_name) . "'"; + $result = $db->sql_query($sql); + $this->lang_id = (int) $db->sql_fetchfield('lang_id'); + $db->sql_freeresult($result); + + return $this->lang_id; + } + + /** + * Get users profile fields + */ + function get_profile_fields($user_id) + { + global $db; + + if (isset($this->profile_fields)) + { + return; + } + + $sql = 'SELECT * + FROM ' . PROFILE_FIELDS_DATA_TABLE . " + WHERE user_id = $user_id"; + $result = $db->sql_query_limit($sql, 1); + $this->profile_fields = (!($row = $db->sql_fetchrow($result))) ? array() : $row; + $db->sql_freeresult($result); + } + + /** + * Gets the user's info + * + * Will take the users email, username or member id and return their data + * + * @param int || string $username the user's email address username or member id + * @return array $results containing the user info || bool false + * @since 0.1.2 + */ + function load_user($user, $force_str = false) + { + if (!is_numeric($user) || $force_str) + { + $user = phpBB2::phpbb_clean_username($user); + } + else + { + $user = intval($user); + } + + //$this->data = array(); + + // we'll try id || email, then username + if (is_numeric($user)) + { + // number is most likely a member id + $this->data = get_user_by_id($user); + } + else + { + // the email can't be purely numeric + $this->data = get_user_by_email($user); + } + + if (empty($this->data)) + { + $this->data = get_user_by_username($user); + } + /* + if (empty($this->data)) + { + return false; + } + else + { + return $this->data; + } + */ + } + + /** + * Load user helper + * + * @param array $user_ids + */ + function load_users(array $user_ids) + { + $user_ids[] = ANONYMOUS; + + // Make user_ids unique and convert to integer. + $user_ids = array_map('intval', array_unique($user_ids)); + + // Do not load users we already have in $this->users + $user_ids = array_diff($user_ids, array_keys($this->users)); + + if (sizeof($user_ids)) + { + $sql = 'SELECT * + FROM ' . USERS_TABLE . ' + WHERE ' . $db->sql_in_set('user_id', $user_ids); + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $this->users[$row['user_id']] = $row; + } + $db->sql_freeresult($result); + } + } + + /** + * Gets the user's info from their email address + * + * Will take the users email address and return an array containing all the + * user's information in the db. Will return false on failure + * + * @param string $email the user's email address + * @return array $results containing the user info || bool false + * @since 0.1.0 + */ + function get_user_by_email($email_address = '') + { + global $db; + if ('' == $email_address || !is_string($email_address) || 2 > count(explode('@', $email_address))) + { + return false; + } + $sql = $db->sql_build_query('SELECT', ' + SELECT * FROM ' . USERS_TABLE . ' + WHERE email_address = {string:email_address}', + array('email_address' => $email_address, )); + $result = $db->sql_query_limit($sql, 1); + $return = $db->sql_fetchrow($result); + if (!$return) + { + $db->sql_freeresult($result); + //trigger_error($mx_user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING); + } + if (empty($return)) + { + return false; + } + else + { + // return all the results. + return $return; + } + } + + /** + * Gets the user's info from their member id + * + * Will take the users member id and return an array containing all the + * user's information in the db. Will return false on failure + * + * @param int $id the user's member id + * @return array $results containing the user info || bool false + * @since 0.1.2 + */ + function get_user_by_id($user_id = '') + { + global $db; + if ('' == $user_id || !is_numeric($user_id)) + { + return false; + } + else + { + $id = intval($user_id); + if (0 == $user_id) + { + return false; + } + } + $sql = $db->sql_build_query('SELECT', ' + SELECT * FROM ' . USERS_TABLE . ' + WHERE user_id = {int:user_id}', + array('user_id' => $user_id, )); + $result = $db->sql_query_limit($sql, 1); + $return = $db->sql_fetchrow($result); + if (!$return) + { + $db->sql_freeresult($result); + //trigger_error($mx_user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING); + } + if (empty($return)) + { + return false; + } + else + { + // return all the results. + return $return; + } + } + + /** + * Gets the user's info from their member name (username) + * + * Will take the users member name and return an array containing all the + * user's information in the db. Will return false on failure + * + * @param string $username the user's member name + * @return array $results containing the user info || bool false + * @since 0.1.0 + */ + function get_user_by_name($user_name = '') + { + global $db; + if ('' == $user_name || !is_string($user_name)) + { + return false; + } + $sql = $db->sql_build_query('SELECT', ' + SELECT * FROM ' . USERS_TABLE . ' + WHERE user_name = {string:user_name}', + array('user_name' => $user_name, )); + $result = $db->sql_query_limit($sql, 1); + $return = $db->sql_fetchrow($result); + if (!$return) + { + $db->sql_freeresult($result); + //trigger_error($mx_user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING); + } + if (empty($return)) + { + return false; + } + else + { + // return all the results. + return $return; + } + } + + /** + * Specify/Get images + */ + function images($img, $alt = '', $width = false, $suffix = '', $type = 'src') + { + static $imgs; + global $phpbb_root_path, $mx_root_path; + $img_data = &$imgs[$img]; + + if (empty($img_data)) + { + if (!isset($this->img_array[$img])) + { + // Do not fill the image to let designers decide what to do if the image is empty + $img_data = ''; + return $img_data; + } + $img_data['image_lang'] = $this->img_array[$img]['image_lang']; + $img_data['src'] = (!empty($img_data['image_lang']) ? (PHPBB_URL . 'styles/' . $this->theme['imageset_path'] . '/theme/' . $img_data['image_lang'] . '/' . $this->img_array[$img]['image_filename']) : (PHPBB_URL . 'styles/' . $this->theme['imageset_path'] . '/theme/images/' . $this->img_array[$img]['image_filename'])); + $img_data['width'] = $this->img_array[$img]['image_width']; + $img_data['height'] = $this->img_array[$img]['image_height']; + } + + $alt = (!empty($this->lang[$alt])) ? $this->lang[$alt] : $alt; + + switch ($type) + { + case 'full_tag': + $use_width = ($width === false) ? $img_data['width'] : $width; + + return ''; + break; + + case 'width': + return ($width === false) ? $img_data['width'] : $width; + break; + + case 'height': + return $img_data['height']; + break; + + default: + return $img_data['src']; + break; + } + } + + /** + * Specify/Get image + */ + function img($img, $alt = '', $width = false, $suffix = '', $type = 'full_tag') + { + static $imgs; + global $phpbb_root_path, $mx_root_path; + + $img_data = &$imgs[$img]; + + if (empty($img_data)) + { + if (!isset($this->img_array[$img])) + { + // Do not fill the image to let designers decide what to do if the image is empty + $img_data = ''; + return $img_data; + } + $img_data['src'] = (!empty($this->img_array[$img]['image_lang']) ? (PHPBB_URL . 'styles/' . $this->theme['imageset_path'] . '/theme/' . $this->img_array[$img]['image_lang'] . '/' . $this->img_array[$img]['image_filename']) : (PHPBB_URL . 'styles/' . $this->theme['imageset_path'] . '/theme/images/' . $this->img_array[$img]['image_filename'])); + $img_data['width'] = $this->img_array[$img]['image_width']; + $img_data['height'] = $this->img_array[$img]['image_height']; + } + + $alt = (!empty($this->lang[$alt])) ? $this->lang[$alt] : $alt; + //die($img_data); + switch ($type) + { + case 'src': + return $img_data['src']; + break; + + case 'width': + return ($width === false) ? $img_data['width'] : $width; + break; + + case 'height': + return $img_data['height']; + break; + + default: + $use_width = ($width === false) ? $img_data['width'] : $width; + + return '
'; + break; + } + } + + /** + * Get option bit field from user options + */ + function optionget($key, $data = false) + { + if (!isset($this->keyvalues[$key])) + { + $var = ($data) ? $data : $this->data['user_options']; + $this->keyvalues[$key] = ($var & 1 << $this->keyoptions[$key]) ? true : false; + } + + return $this->keyvalues[$key]; + } + + /** + * Set option bit field for user options + */ + function optionset($key, $value, $data = false) + { + $var = ($data) ? $data : $this->data['user_options']; + + if ($value && !($var & 1 << $this->keyoptions[$key])) + { + $var += 1 << $this->keyoptions[$key]; + } + else if (!$value && ($var & 1 << $this->keyoptions[$key])) + { + $var -= 1 << $this->keyoptions[$key]; + } + else + { + return ($data) ? $var : false; + } + + if (!$data) + { + $this->data['user_options'] = $var; + return true; + } + else + { + return $var; + } + } + + /** + * encode_lang + * + * $default_lang = $mx_user->encode_lang($board_config['default_lang']); + * + * @param unknown_type $lang + * @return unknown + */ + function encode_lang($lang) + { + switch($lang) + { + case 'afar': + $lang_name = 'aa'; + break; + case 'abkhazian': + $lang_name = 'ab'; + break; + case 'avestan': + $lang_name = 'ae'; + break; + case 'afrikaans': + $lang_name = 'af'; + break; + case 'akan': + $lang_name = 'ak'; + break; + case 'amharic': + $lang_name = 'am'; + break; + case 'aragonese': + $lang_name = 'an'; + break; + case 'arabic': + $lang_name = 'ar'; + break; + case 'assamese': + $lang_name = 'as'; + break; + case 'avaric': + $lang_name = 'av'; + break; + case 'aymara': + $lang_name = 'ay'; + break; + case 'azerbaijani': + $lang_name = 'az'; + break; + case 'bashkir': + $lang_name = 'ba'; + break; + case 'belarusian': + $lang_name = 'be'; + break; + case 'bulgarian': + $lang_name = 'bg'; + break; + case 'bihari': + $lang_name = 'bh'; + break; + case 'bislama': + $lang_name = 'bi'; + break; + case 'bambara': + $lang_name = 'bm'; + break; + case 'bengali': + $lang_name = 'bn'; + break; + case 'tibetan': + $lang_name = 'bo'; + break; + case 'breton': + $lang_name = 'br'; + break; + case 'bosnian': + $lang_name = 'bs'; + break; + case 'catalan': + $lang_name = 'ca'; + break; + case 'chechen': + $lang_name = 'ce'; + break; + case 'chamorro': + $lang_name = 'ch'; + break; + case 'corsican': + $lang_name = 'co'; + break; + case 'cree': + $lang_name = 'cr'; + break; + case 'czech': + $lang_name = 'cs'; + break; + case 'slavonic': + $lang_name = 'cu'; + break; + case 'chuvash': + $lang_name = 'cv'; + break; + case 'welsh_cymraeg': + $lang_name = 'cy'; + break; + case 'danish': + $lang_name = 'da'; + break; + case 'german': + $lang_name = 'de'; + break; + case 'divehi': + $lang_name = 'dv'; + break; + case 'dzongkha': + $lang_name = 'dz'; + break; + case 'ewe': + $lang_name = 'ee'; + break; + case 'greek': + $lang_name = 'el'; + break; + case 'hebrew': + $lang_name = 'he'; + break; + case 'english': + $lang_name = 'en'; + break; + case 'english_us': + $lang_name = 'en_us'; + break; + case 'esperanto': + $lang_name = 'eo'; + break; + case 'spanish': + $lang_name = 'es'; + break; + case 'estonian': + $lang_name = 'et'; + break; + case 'basque': + $lang_name = 'eu'; + break; + case 'persian': + $lang_name = 'fa'; + break; + case 'fulah': + $lang_name = 'ff'; + break; + case 'finnish': + $lang_name = 'fi'; + break; + case 'fijian': + $lang_name = 'fj'; + break; + case 'faroese': + $lang_name = 'fo'; + break; + case 'french': + $lang_name = 'fr'; + break; + case 'frisian': + $lang_name = 'fy'; + break; + case 'irish': + $lang_name = 'ga'; + break; + case 'scottish': + $lang_name = 'gd'; + break; + case 'galician': + $lang_name = 'gl'; + break; + case 'guaraní': + $lang_name = 'gn'; + break; + case 'gujarati': + $lang_name = 'gu'; + break; + case 'manx': + $lang_name = 'gv'; + break; + case 'hausa': + $lang_name = 'ha'; + break; + case 'hebrew': + $lang_name = 'he'; + break; + case 'hindi': + $lang_name = 'hi'; + break; + case 'hiri_motu': + $lang_name = 'ho'; + break; + case 'croatian': + $lang_name = 'hr'; + break; + case 'haitian': + $lang_name = 'ht'; + break; + case 'hungarian': + $lang_name = 'hu'; + break; + case 'armenian': + $lang_name = 'hy'; + break; + case 'herero': + $lang_name = 'hz'; + break; + case 'interlingua': + $lang_name = 'ia'; + break; + case 'indonesian': + $lang_name = 'id'; + break; + case 'interlingue': + $lang_name = 'ie'; + break; + case 'igbo': + $lang_name = 'ig'; + break; + case 'sichuan_yi': + $lang_name = 'ii'; + break; + case 'inupiaq': + $lang_name = 'ik'; + break; + case 'ido': + $lang_name = 'io'; + break; + case 'icelandic': + $lang_name = 'is'; + break; + case 'italian': + $lang_name = 'it'; + break; + case 'inuktitut': + $lang_name = 'iu'; + break; + case 'japanese': + $lang_name = 'ja'; + break; + case 'javanese': + $lang_name = 'jv'; + break; + case 'georgian': + $lang_name = 'ka'; + break; + case 'kongo': + $lang_name = 'kg'; + break; + case 'kikuyu': + $lang_name = 'ki'; + break; + case 'kwanyama': + $lang_name = 'kj'; + break; + case 'kazakh': + $lang_name = 'kk'; + break; + case 'kalaallisut': + $lang_name = 'kl'; + break; + case 'khmer': + $lang_name = 'km'; + break; + case 'kannada': + $lang_name = 'kn'; + break; + case 'korean': + $lang_name = 'ko'; + break; + case 'kanuri': + $lang_name = 'kr'; + break; + case 'kashmiri': + $lang_name = 'ks'; + break; + case 'kurdish': + $lang_name = 'ku'; + break; + case 'kv': + $lang_name = 'komi'; + break; + case 'cornish_kernewek': + $lang_name = 'kw'; + break; + case 'kirghiz': + $lang_name = 'ky'; + break; + case 'latin': + $lang_name = 'la'; + break; + case 'luxembourgish': + $lang_name = 'lb'; + break; + case 'ganda': + $lang_name = 'lg'; + break; + case 'limburgish': + $lang_name = 'li'; + break; + case 'lingala': + $lang_name = 'ln'; + break; + case 'lao': + $lang_name = 'lo'; + break; + case 'lithuanian': + $lang_name = 'lt'; + break; + case 'luba-katanga': + $lang_name = 'lu'; + break; + case 'latvian': + $lang_name = 'lv'; + break; + case 'malagasy': + $lang_name = 'mg'; + break; + case 'marshallese': + $lang_name = 'mh'; + break; + case 'maori': + $lang_name = 'mi'; + break; + case 'macedonian': + $lang_name = 'mk'; + break; + case 'malayalam': + $lang_name = 'ml'; + break; + case 'mongolian': + $lang_name = 'mn'; + break; + case 'moldavian': + $lang_name = 'mo'; + break; + case 'marathi': + $lang_name = 'mr'; + break; + case 'malay': + $lang_name = 'ms'; + break; + case 'maltese': + $lang_name = 'mt'; + break; + case 'burmese': + $lang_name = 'my'; + break; + case 'nauruan': + $lang_name = 'na'; + break; + case 'norwegian': + $lang_name = 'nb'; + break; + case 'ndebele': + $lang_name = 'nd'; + break; + case 'nepali': + $lang_name = 'ne'; + break; + case 'ndonga': + $lang_name = 'ng'; + break; + case 'dutch': + $lang_name = 'nl'; + break; + case 'norwegian_nynorsk': + $lang_name = 'nn'; + break; + case 'norwegian': + $lang_name = 'no'; + break; + case 'southern_ndebele': + $lang_name = 'nr'; + break; + case 'navajo': + $lang_name = 'nv'; + break; + case 'chichewa': + $lang_name = 'ny'; + break; + case 'occitan': + $lang_name = 'oc'; + break; + case 'ojibwa': + $lang_name = 'oj'; + break; + case 'oromo': + $lang_name = 'om'; + break; + case 'oriya': + $lang_name = 'or'; + break; + case 'ossetian': + $lang_name = 'os'; + break; + case 'panjabi': + $lang_name = 'pa'; + break; + case 'pali': + $lang_name = 'pi'; + break; + case 'polish': + $lang_name = 'pl'; + break; + case 'pashto': + $lang_name = 'ps'; + break; + case 'portuguese': + $lang_name = 'pt'; + break; + case 'portuguese_brasil': + $lang_name = 'pt_br'; + break; + case 'quechua': + $lang_name = 'qu'; + break; + case 'romansh': + $lang_name = 'rm'; + break; + case 'kirundi': + $lang_name = 'rn'; + break; + case 'romanian': + $lang_name = 'ro'; + break; + case 'russian': + $lang_name = 'ru'; + break; + case 'kinyarwanda': + $lang_name = 'rw'; + break; + case 'sanskrit': + $lang_name = 'sa'; + break; + case 'sardinian': + $lang_name = 'sc'; + break; + case 'sindhi': + $lang_name = 'sd'; + break; + case 'northern_sami': + $lang_name = 'se'; + break; + case 'sango': + $lang_name = 'sg'; + break; + case 'serbo-croatian': + $lang_name = 'sh'; + break; + case 'sinhala': + $lang_name = 'si'; + break; + case 'slovak': + $lang_name = 'sk'; + break; + case 'slovenian': + $lang_name = 'sl'; + break; + case 'samoan': + $lang_name = 'sm'; + break; + case 'shona': + $lang_name = 'sn'; + break; + case 'somali': + $lang_name = 'so'; + break; + case 'albanian': + $lang_name = 'sq'; + break; + case 'serbian': + $lang_name = 'sr'; + break; + case 'swati': + $lang_name = 'ss'; + break; + case 'sotho': + $lang_name = 'st'; + break; + case 'sundanese': + $lang_name = 'su'; + break; + case 'swedish': + $lang_name = 'sv'; + break; + case 'swahili': + $lang_name = 'sw'; + break; + case 'tamil': + $lang_name = 'ta'; + break; + case 'telugu': + $lang_name = 'te'; + break; + case 'tajik': + $lang_name = 'tg'; + break; + case 'thai': + $lang_name = 'th'; + break; + case 'tigrinya': + $lang_name = 'ti'; + break; + case 'turkmen': + $lang_name = 'tk'; + break; + case 'tagalog': + $lang_name = 'tl'; + break; + case 'tswana': + $lang_name = 'tn'; + break; + case 'tonga': + $lang_name = 'to'; + break; + case 'turkish': + $lang_name = 'tr'; + break; + case 'tsonga': + $lang_name = 'ts'; + break; + case 'tatar': + $lang_name = 'tt'; + break; + case 'twi': + $lang_name = 'tw'; + break; + case 'tahitian': + $lang_name = 'ty'; + break; + case 'uighur': + $lang_name = 'ug'; + break; + case 'ukrainian': + $lang_name = 'uk'; + break; + case 'urdu': + $lang_name = 'ur'; + break; + case 'uzbek': + $lang_name = 'uz'; + break; + case 'venda': + $lang_name = 've'; + break; + case 'vietnamese': + $lang_name = 'vi'; + break; + case 'volapuk': + $lang_name = 'vo'; + break; + case 'walloon': + $lang_name = 'wa'; + break; + case 'wolof': + $lang_name = 'wo'; + break; + case 'xhosa': + $lang_name = 'xh'; + break; + case 'yiddish': + $lang_name = 'yi'; + break; + case 'yoruba': + $lang_name = 'yo'; + break; + case 'zhuang': + $lang_name = 'za'; + break; + case 'chinese': + $lang_name = 'zh'; + break; + case 'chinese_simplified': + $lang_name = 'zh_cmn_hans'; + break; + case 'chinese_traditional': + $lang_name = 'zh_cmn_hant'; + break; + case 'zulu': + $lang_name = 'zu'; + break; + default: + $lang_name = $lang; + break; + } + return $lang_name; + } + + /** + * decode_lang + * + * $default_lang = $mx_user->decode_lang($board_config['default_lang']); + * + * @param unknown_type $lang + * @return unknown + */ + function decode_lang($lang) + { + switch($lang) + { + case 'aa': + $lang_name = 'afar'; + break; + case 'ab': + $lang_name = 'abkhazian'; + break; + case 'ae': + $lang_name = 'avestan'; + break; + case 'af': + $lang_name = 'afrikaans'; + break; + case 'ak': + $lang_name = 'akan'; + break; + case 'am': + $lang_name = 'amharic'; + break; + case 'an': + $lang_name = 'aragonese'; + break; + case 'ar': + $lang_name = 'arabic'; + break; + case 'as': + $lang_name = 'assamese'; + break; + case 'av': + $lang_name = 'avaric'; + break; + case 'ay': + $lang_name = 'aymara'; + break; + case 'az': + $lang_name = 'azerbaijani'; + break; + case 'ba': + $lang_name = 'bashkir'; + break; + case 'be': + $lang_name = 'belarusian'; + break; + case 'bg': + $lang_name = 'bulgarian'; + break; + case 'bh': + $lang_name = 'bihari'; + break; + case 'bi': + $lang_name = 'bislama'; + break; + case 'bm': + $lang_name = 'bambara'; + break; + case 'bn': + $lang_name = 'bengali'; + break; + case 'bo': + $lang_name = 'tibetan'; + break; + case 'br': + $lang_name = 'breton'; + break; + case 'bs': + $lang_name = 'bosnian'; + break; + case 'ca': + $lang_name = 'catalan'; + break; + case 'ce': + $lang_name = 'chechen'; + break; + case 'ch': + $lang_name = 'chamorro'; + break; + case 'co': + $lang_name = 'corsican'; + break; + case 'cr': + $lang_name = 'cree'; + break; + case 'cs': + $lang_name = 'czech'; + break; + case 'cu': + $lang_name = 'slavonic'; + break; + case 'cv': + $lang_name = 'chuvash'; + break; + case 'cy': + $lang_name = 'welsh_cymraeg'; + break; + case 'da': + $lang_name = 'danish'; + break; + case 'de': + $lang_name = 'german'; + break; + case 'dv': + $lang_name = 'divehi'; + break; + case 'dz': + $lang_name = 'dzongkha'; + break; + case 'ee': + $lang_name = 'ewe'; + break; + case 'el': + $lang_name = 'greek'; + break; + case 'he': + $lang_name = 'hebrew'; + break; + case 'en': + $lang_name = 'english'; + break; + case 'en_us': + $lang_name = 'english'; + break; + case 'eo': + $lang_name = 'esperanto'; + break; + case 'es': + $lang_name = 'spanish'; + break; + case 'et': + $lang_name = 'estonian'; + break; + case 'eu': + $lang_name = 'basque'; + break; + case 'fa': + $lang_name = 'persian'; + break; + case 'ff': + $lang_name = 'fulah'; + break; + case 'fi': + $lang_name = 'finnish'; + break; + case 'fj': + $lang_name = 'fijian'; + break; + case 'fo': + $lang_name = 'faroese'; + break; + case 'fr': + $lang_name = 'french'; + break; + case 'fy': + $lang_name = 'frisian'; + break; + case 'ga': + $lang_name = 'irish'; + break; + case 'gd': + $lang_name = 'scottish'; + break; + case 'gl': + $lang_name = 'galician'; + break; + case 'gn': + $lang_name = 'guaraní'; + break; + case 'gu': + $lang_name = 'gujarati'; + break; + case 'gv': + $lang_name = 'manx'; + break; + case 'ha': + $lang_name = 'hausa'; + break; + case 'he': + $lang_name = 'hebrew'; + break; + case 'hi': + $lang_name = 'hindi'; + break; + case 'ho': + $lang_name = 'hiri_motu'; + break; + case 'hr': + $lang_name = 'croatian'; + break; + case 'ht': + $lang_name = 'haitian'; + break; + case 'hu': + $lang_name = 'hungarian'; + break; + case 'hy': + $lang_name = 'armenian'; + break; + case 'hz': + $lang_name = 'herero'; + break; + case 'ia': + $lang_name = 'interlingua'; + break; + case 'id': + $lang_name = 'indonesian'; + break; + case 'ie': + $lang_name = 'interlingue'; + break; + case 'ig': + $lang_name = 'igbo'; + break; + case 'ii': + $lang_name = 'sichuan_yi'; + break; + case 'ik': + $lang_name = 'inupiaq'; + break; + case 'io': + $lang_name = 'ido'; + break; + case 'is': + $lang_name = 'icelandic'; + break; + case 'it': + $lang_name = 'italian'; + break; + case 'iu': + $lang_name = 'inuktitut'; + break; + case 'ja': + $lang_name = 'japanese'; + break; + case 'jv': + $lang_name = 'javanese'; + break; + case 'ka': + $lang_name = 'georgian'; + break; + case 'kg': + $lang_name = 'kongo'; + break; + case 'ki': + $lang_name = 'kikuyu'; + break; + case 'kj': + $lang_name = 'kwanyama'; + break; + case 'kk': + $lang_name = 'kazakh'; + break; + case 'kl': + $lang_name = 'kalaallisut'; + break; + case 'km': + $lang_name = 'khmer'; + break; + case 'kn': + $lang_name = 'kannada'; + break; + case 'ko': + $lang_name = 'korean'; + break; + case 'kr': + $lang_name = 'kanuri'; + break; + case 'ks': + $lang_name = 'kashmiri'; + break; + case 'ku': + $lang_name = 'kurdish'; + break; + case 'kv': + $lang_name = 'komi'; + break; + case 'kw': + $lang_name = 'cornish_kernewek'; + break; + case 'ky': + $lang_name = 'kirghiz'; + break; + case 'la': + $lang_name = 'latin'; + break; + case 'lb': + $lang_name = 'luxembourgish'; + break; + case 'lg': + $lang_name = 'ganda'; + break; + case 'li': + $lang_name = 'limburgish'; + break; + case 'ln': + $lang_name = 'lingala'; + break; + case 'lo': + $lang_name = 'lao'; + break; + case 'lt': + $lang_name = 'lithuanian'; + break; + case 'lu': + $lang_name = 'luba-katanga'; + break; + case 'lv': + $lang_name = 'latvian'; + break; + case 'mg': + $lang_name = 'malagasy'; + break; + case 'mh': + $lang_name = 'marshallese'; + break; + case 'mi': + $lang_name = 'maori'; + break; + case 'mk': + $lang_name = 'macedonian'; + break; + case 'ml': + $lang_name = 'malayalam'; + break; + case 'mn': + $lang_name = 'mongolian'; + break; + case 'mo': + $lang_name = 'moldavian'; + break; + case 'mr': + $lang_name = 'marathi'; + break; + case 'ms': + $lang_name = 'malay'; + break; + case 'mt': + $lang_name = 'maltese'; + break; + case 'my': + $lang_name = 'burmese'; + break; + case 'na': + $lang_name = 'nauruan'; + break; + case 'nb': + $lang_name = 'norwegian'; + break; + case 'nd': + $lang_name = 'ndebele'; + break; + case 'ne': + $lang_name = 'nepali'; + break; + case 'ng': + $lang_name = 'ndonga'; + break; + case 'nl': + $lang_name = 'dutch'; + break; + case 'nn': + $lang_name = 'norwegian_nynorsk'; + break; + case 'no': + $lang_name = 'norwegian'; + break; + case 'nr': + $lang_name = 'southern_ndebele'; + break; + case 'nv': + $lang_name = 'navajo'; + break; + case 'ny': + $lang_name = 'chichewa'; + break; + case 'oc': + $lang_name = 'occitan'; + break; + case 'oj': + $lang_name = 'ojibwa'; + break; + case 'om': + $lang_name = 'oromo'; + break; + case 'or': + $lang_name = 'oriya'; + break; + case 'os': + $lang_name = 'ossetian'; + break; + case 'pa': + $lang_name = 'panjabi'; + break; + case 'pi': + $lang_name = 'pali'; + break; + case 'pl': + $lang_name = 'polish'; + break; + case 'ps': + $lang_name = 'pashto'; + break; + case 'pt': + $lang_name = 'portuguese'; + break; + case 'pt_br': + $lang_name = 'portuguese_brasil'; + break; + case 'qu': + $lang_name = 'quechua'; + break; + case 'rm': + $lang_name = 'romansh'; + break; + case 'rn': + $lang_name = 'kirundi'; + break; + case 'ro': + $lang_name = 'romanian'; + break; + case 'ru': + $lang_name = 'russian'; + break; + case 'rw': + $lang_name = 'kinyarwanda'; + break; + case 'sa': + $lang_name = 'sanskrit'; + break; + case 'sc': + $lang_name = 'sardinian'; + break; + case 'sd': + $lang_name = 'sindhi'; + break; + case 'se': + $lang_name = 'northern_sami'; + break; + case 'sg': + $lang_name = 'sango'; + break; + case 'sh': + $lang_name = 'serbo-croatian'; + break; + case 'si': + $lang_name = 'sinhala'; + break; + case 'sk': + $lang_name = 'slovak'; + break; + case 'sl': + $lang_name = 'slovenian'; + break; + case 'sm': + $lang_name = 'samoan'; + break; + case 'sn': + $lang_name = 'shona'; + break; + case 'so': + $lang_name = 'somali'; + break; + case 'sq': + $lang_name = 'albanian'; + break; + case 'sr': + $lang_name = 'serbian'; + break; + case 'ss': + $lang_name = 'swati'; + break; + case 'st': + $lang_name = 'sotho'; + break; + case 'su': + $lang_name = 'sundanese'; + break; + case 'sv': + $lang_name = 'swedish'; + break; + case 'sw': + $lang_name = 'swahili'; + break; + case 'ta': + $lang_name = 'tamil'; + break; + case 'te': + $lang_name = 'telugu'; + break; + case 'tg': + $lang_name = 'tajik'; + break; + case 'th': + $lang_name = 'thai'; + break; + case 'ti': + $lang_name = 'tigrinya'; + break; + case 'tk': + $lang_name = 'turkmen'; + break; + case 'tl': + $lang_name = 'tagalog'; + break; + case 'tn': + $lang_name = 'tswana'; + break; + case 'to': + $lang_name = 'tonga'; + break; + case 'tr': + $lang_name = 'turkish'; + break; + case 'ts': + $lang_name = 'tsonga'; + break; + case 'tt': + $lang_name = 'tatar'; + break; + case 'tw': + $lang_name = 'twi'; + break; + case 'ty': + $lang_name = 'tahitian'; + break; + case 'ug': + $lang_name = 'uighur'; + break; + case 'uk': + $lang_name = 'ukrainian'; + break; + case 'ur': + $lang_name = 'urdu'; + break; + case 'uz': + $lang_name = 'uzbek'; + break; + case 've': + $lang_name = 'venda'; + break; + case 'vi': + $lang_name = 'vietnamese'; + break; + case 'vo': + $lang_name = 'volapuk'; + break; + case 'wa': + $lang_name = 'walloon'; + break; + case 'wo': + $lang_name = 'wolof'; + break; + case 'xh': + $lang_name = 'xhosa'; + break; + case 'yi': + $lang_name = 'yiddish'; + break; + case 'yo': + $lang_name = 'yoruba'; + break; + case 'za': + $lang_name = 'zhuang'; + break; + case 'zh': + $lang_name = 'chinese'; + break; + case 'zh_cmn_hans': + $lang_name = 'chinese_simplified'; + break; + case 'zh_cmn_hant': + $lang_name = 'chinese_traditional'; + break; + case 'zu': + $lang_name = 'zulu'; + break; + default: + $lang_name = $lang; + break; + } + return $lang_name; + } +} +?> \ No newline at end of file diff --git a/includes/sessions/smf2/CVS/Entries b/includes/sessions/smf2/CVS/Entries new file mode 100644 index 00000000..8aedbb5b --- /dev/null +++ b/includes/sessions/smf2/CVS/Entries @@ -0,0 +1,10 @@ +/auth.php/1.1/Sun May 18 06:26:59 2014// +/bbcode.php/1.1/Sun May 18 06:26:59 2014// +/constants.php/1.1/Sun May 18 06:26:59 2014// +/core.php/1.2/Mon Jul 7 20:36:53 2014// +/functions.php/1.1/Sun May 18 06:26:59 2014// +/index.htm/1.1/Fri May 16 18:06:26 2014// +/login.php/1.1/Sun May 18 06:26:59 2014// +/readme.html/1.1/Sun May 18 06:26:59 2014// +/session.php/1.1/Sun May 18 06:26:59 2014// +D diff --git a/includes/sessions/smf2/CVS/Entries.Extra b/includes/sessions/smf2/CVS/Entries.Extra new file mode 100644 index 00000000..b82b2f6f --- /dev/null +++ b/includes/sessions/smf2/CVS/Entries.Extra @@ -0,0 +1,9 @@ +/auth.php////*//// +/bbcode.php////*//// +/constants.php////*//// +/core.php////*//// +/functions.php////*//// +/index.htm////*//// +/login.php////*//// +/readme.html////*//// +/session.php////*//// diff --git a/includes/sessions/smf2/CVS/Entries.Extra.Old b/includes/sessions/smf2/CVS/Entries.Extra.Old new file mode 100644 index 00000000..e69de29b diff --git a/includes/sessions/smf2/CVS/Entries.Old b/includes/sessions/smf2/CVS/Entries.Old new file mode 100644 index 00000000..e69de29b diff --git a/includes/sessions/smf2/CVS/Repository b/includes/sessions/smf2/CVS/Repository new file mode 100644 index 00000000..3ed4d5e3 --- /dev/null +++ b/includes/sessions/smf2/CVS/Repository @@ -0,0 +1 @@ +core/includes/sessions/smf2 diff --git a/includes/sessions/smf2/CVS/Root b/includes/sessions/smf2/CVS/Root new file mode 100644 index 00000000..6ab1483d --- /dev/null +++ b/includes/sessions/smf2/CVS/Root @@ -0,0 +1 @@ +:pserver:anonymous@mxbb.cvs.sourceforge.net:/cvsroot/mxbb diff --git a/includes/sessions/smf2/core.php b/includes/sessions/smf2/core.php index 412f01bd..1a2b3aa4 100644 --- a/includes/sessions/smf2/core.php +++ b/includes/sessions/smf2/core.php @@ -68,6 +68,9 @@ function validate_backend() str_replace("//", "/", $phpbb_root_path); str_replace("//", "/", $smf_root_path); + // Define backend template extension + //$tplEx = 'php'; + $tplEx = 'html'; // SMF Is Intalled $portal_backend_valid_file = @file_exists($smf_root_path . "Settings.$phpEx"); @@ -111,11 +114,7 @@ function validate_backend() 'character_set' => $db_character_set, ); - - // Define backend template extension - //$tplEx = 'php'; - $tplEx = 'html'; - + // Most database systems have not set UTF-8 as their default input charset. if (!empty($db_character_set)) { @@ -168,6 +167,11 @@ function setup_backend() define('PHPBB_URL', $server_url_phpbb); define('BOARD_URL', $server_url_smf); + // Define backend template extension + //$tplEx = 'php'; + $tplEx = 'html'; + if (!defined('TPL_EXT')) define('TPL_EXT', $tplEx); + // Now sync Configs - In SMF mode, we rely on native configs, thus we need to sync mxp and smf settings $this->sync_board_config_keys(); //$this->sync_userdata(); diff --git a/includes/shared/phpbb2/admin/index.htm b/includes/shared/phpbb2/admin/index.htm new file mode 100644 index 00000000..ee1f723a --- /dev/null +++ b/includes/shared/phpbb2/admin/index.htm @@ -0,0 +1,10 @@ + + +
+ + + + + + + diff --git a/includes/shared/phpbb2/admin/index.php b/includes/shared/phpbb2/admin/index.php new file mode 100644 index 00000000..ee1f723a --- /dev/null +++ b/includes/shared/phpbb2/admin/index.php @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/includes/shared/phpbb2/includes/functions.php b/includes/shared/phpbb2/includes/functions.php index 730076b7..6aa64615 100644 --- a/includes/shared/phpbb2/includes/functions.php +++ b/includes/shared/phpbb2/includes/functions.php @@ -25,12 +25,397 @@ // Class phpBB2 - function container // class phpBB2 -{ - public static function get_db_stat($mode) +{ + protected $template; + protected $mx_user; + protected $db; + protected $mx_request_vars; + protected $mx_cache; + protected $board_config; + protected $php_ext; + protected $root_path; + protected $mx_root_path; + protected $module_root_path; + protected $phpbb_root_path; + + public function phpBB2() + { + global $template, $mx_user, $db, $mx_cache, $mx_request_vars, $board_config, $phpEx, $phpbb_root_path, $mx_root_path, $module_root_path; + + $this->template = $template; + $this->user = $mx_user; + $this->db = $db; + $this->request = $mx_request_vars; + $this->cache = $mx_cache; + $this->config = $board_config; + $this->php_ext = $phpEx; + $this->root_path = $mx_root_path; + $this->mx_root_path = $mx_root_path; + $this->module_root_path = $module_root_path; + $this->phpbb_root_path = $phpbb_root_path; + + if (!defined('PHPBB_USE_BOARD_URL_PATH')) + { + define('PHPBB_USE_BOARD_URL_PATH', true); + } + } + + /** + * set_var + * + * Set variable, used by {@link request_var the request_var function} + * + * @access private + */ + function set_var(&$result, $var, $type, $multibyte = false) + { + settype($var, $type); + $result = $var; + + if ($type == 'string') + { + $result = trim(htmlspecialchars(str_replace(array("\r\n", "\r", "\0"), array("\n", "\n", ''), $result), ENT_COMPAT, 'UTF-8')); + + if (!empty($result)) + { + // Make sure multibyte characters are wellformed + if ($multibyte) + { + if (!preg_match('/^./u', $result)) + { + $result = ''; + } + } + else + { + // no multibyte, allow only ASCII (0-127) + $result = preg_replace('/[\x80-\xFF]/', '?', $result); + } + } + + $result = (STRIP) ? stripslashes($result) : $result; + } + } + /** + * Function: _read() from class mx_request_vars + * autor John Olson + * Get the value of the specified request var (post or get) and force the result to be + * of specified type. It might also transform the result (stripslashes, htmlspecialchars) for security + * purposes. It all depends on the $type argument. + * If the specified request var does not exist, then the default ($dflt) value is returned. + * Note the $type argument behaves as a bit array where more than one option can be specified by OR'ing + * the passed argument. This is tipical practice in languages like C, but it can also be done with PHP. + * + * @access private + * @param unknown_type $var + * @param unknown_type $type + * @param unknown_type $dflt + * @return unknown + */ + function read_var($var, $dflt = '', $type = 0, $not_null = false) + { + if(($type & (64|128)) == 0) + { + $type |= (64|128); + } + + if(($type & 64) && isset($_POST[$var]) || ($type & 128) && isset($_GET[$var])) + { + $val = ( ($type & 64) && isset($_POST[$var]) ? $_REQUEST[$var] : $_GET[$var]); + if(!($type & 16)) + { + if(is_array($val)) + { + foreach($val as $k => $v) + { + $val[$k] = trim(stripslashes($v)); + } + } + else + { + $val = trim(stripslashes($val)); + } + } + } + else if(($type & 64) && isset($HTTP_POST_VARS[$var]) || ($type & 128) && isset($HTTP_GET_VARS[$var])) + { + $val = ( ($type & 64) && isset($HTTP_POST_VARS[$var]) ? $HTTP_REQUEST_VARS[$var] : $HTTP_GET_VARS[$var]); + if(!($type & 16)) + { + if(is_array($val)) + { + foreach($val as $k => $v) + { + $val[$k] = trim(stripslashes($v)); + } + } + else + { + $val = trim(stripslashes($val)); + } + } + } + else + { + $val = $dflt; + } + + if($type & 1) // integer + { + return $not_null && empty($val) ? $dflt : intval($val); + } + + if($type & 2) // float + { + return $not_null && empty($val) ? $dflt : floatval($val); + } + + if($type & 8) // ie username + { + if( is_array($val) ) + { + foreach( $val as $k => $v ) + { + $val[$k] = htmlspecialchars(strip_tags(ltrim(rtrim($v, " \t\n\r\0\x0B\\")))); + } + } + else + { + $val = htmlspecialchars(strip_tags(ltrim(rtrim($val, " \t\n\r\0\x0B\\")))); + } + } + elseif($type & 4) // no slashes nor html + { + if(is_array($val)) + { + foreach( $val as $k => $v ) + { + $val[$k] = htmlspecialchars(ltrim(rtrim($v, " \t\n\r\0\x0B\\"))); + } + } + else + { + $val = htmlspecialchars(ltrim(rtrim($val, " \t\n\r\0\x0B\\"))); + } + } + + if($type & 32) + { + if(is_array($val)) + { + foreach($val as $k => $v) + { + $val[$k] = str_replace(($type & 16 ? "\'" : "'"), "''", $v); + } + } + else + { + $val = str_replace(($type & 16 ? "\'" : "'"), "''", $val); + } + } + return $not_null && empty($val) ? $dflt : $val; + } + /** + * request_var + * + * Used to get passed variable + */ + function request_var($var_name, $default, $multibyte = false, $cookie = false) + { + if (($cookie == false) && isset($_COOKIE[$var_name])) + { + if (empty($_GET[$var_name]) && empty($_POST[$var_name])) + { + return (is_array($default)) ? array() : $default; + } + $_REQUEST[$var_name] = isset($_POST[$var_name]) ? $_POST[$var_name] : $_GET[$var_name]; + } + + $super_global = ($cookie) ? '_COOKIE' : '_REQUEST'; + if (!isset($GLOBALS[$super_global][$var_name]) || is_array($GLOBALS[$super_global][$var_name]) != is_array($default)) + { + return (is_array($default)) ? array() : $default; + } + + $var = $GLOBALS[$super_global][$var_name]; + if (!is_array($default)) + { + $type = gettype($default); + } + else + { + list($key_type, $type) = each($default); + $type = gettype($type); + $key_type = gettype($key_type); + if ($type == 'array') + { + reset($default); + $default = current($default); + list($sub_key_type, $sub_type) = each($default); + $sub_type = gettype($sub_type); + $sub_type = ($sub_type == 'array') ? 'NULL' : $sub_type; + $sub_key_type = gettype($sub_key_type); + } + } + + if (is_array($var)) + { + $_var = $var; + $var = array(); + + foreach ($_var as $k => $v) + { + set_var($k, $k, $key_type); + if ($type == 'array' && is_array($v)) + { + foreach ($v as $_k => $_v) + { + if (is_array($_v)) + { + $_v = null; + } + set_var($_k, $_k, $sub_key_type, $multibyte); + set_var($var[$k][$_k], $_v, $sub_type, $multibyte); + } + } + else + { + if ($type == 'array' || is_array($v)) + { + $v = null; + } + set_var($var[$k], $v, $type, $multibyte); + } + } + } + else + { + set_var($var, $var, $type, $multibyte); + } + + return $var; + } + + /** + * Is POST var? + * + * Boolean method to check for existence of POST variable. + * * autor John Olson + * @access public + * @param string $var + * @return boolean + */ + function is_post($var) + { + global $_POST; + // Note: _x and _y are used by (at least IE) to return the mouse position at onclick of INPUT TYPE="img" elements. + return (isset($_POST[$var]) || ( isset($_POST[$var.'_x']) && isset($_POST[$var.'_y']))) ? 1 : 0; + } + + /** + * Is GET var? + * + * Boolean method to check for existence of GET variable. + * * autor John Olson + * @access public + * @param string $var + * @return boolean + */ + function is_get($var) + { + global $_GET; + return isset($_GET[$var]) ? 1 : 0 ; + } + + /** + * Is REQUEST (either GET or POST) var? + * + * Boolean method to check for existence of any REQUEST (both) variable. + * * autor John Olson + * @access public + * @param string $var + * @return boolean + */ + function is_request($var) + { + return (is_get($var) || is_post($var)) ? 1 : 0; + } + + /** + * Is POST var empty? + * * autor John Olson + * Boolean method to check if POST variable is empty + * as it might be set but still be empty. + * + * @access public + * @param string $var + * @return boolean + */ + + function is_empty_post($var) + { + global $_POST; + + return (empty($_POST[$var]) && ( empty($_POST[$var.'_x']) || empty($_POST[$var.'_y']))) ? 1 : 0 ; + } + + /** + * Is GET var empty? + * * autor John Olson + * Boolean method to check if GET variable is empty + * as it might be set but still be empty + * + * @access public + * @param string $var + * @return boolean + */ + function is_empty_get($var) + { + global $_GET; + return empty($_GET[$var]) ? 1 : 0 ; + } + + /** + * Is REQUEST empty (GET and POST) var? + * * autor John Olson + * Boolean method to check if REQUEST (both) variable is empty. + * + * @access public + * @param string $var + * @return boolean + */ + function is_empty_request($var) + { + return (is_empty_get($var) && is_empty_post($var)) ? 1 : 0; + } + + /** + * Set config value. Creates missing config entry. + */ + function set_config($config_name, $config_value) + { + global $db, $board_config; + + $sql = 'UPDATE ' . CONFIG_TABLE . " + SET config_value = '" . $db->sql_escape($config_value) . "' + WHERE config_name = '" . $db->sql_escape($config_name) . "'"; + $db->sql_query($sql); + + if (!$db->sql_affectedrows() && !isset($board_config[$config_name])) + { + $sql = 'INSERT INTO ' . CONFIG_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'config_name' => $config_name, + 'config_value' => $config_value)); + $db->sql_query($sql); + } + $config[$config_name] = $config_value; + } + + function get_db_stat($mode) { global $db; - switch( $mode ) + switch($mode) { case 'usercount': $sql = "SELECT COUNT(user_id) AS total @@ -53,34 +438,34 @@ public static function get_db_stat($mode) break; } - if ( !($result = $db->sql_query($sql)) ) + if (!($result = $db->sql_query($sql))) { return false; } $row = $db->sql_fetchrow($result); - switch ( $mode ) + switch ($mode) { case 'usercount': return $row['total']; - break; + break; case 'newestuser': return $row; - break; + break; case 'postcount': return $row['post_total']; - break; + break; case 'topiccount': return $row['topic_total']; - break; + break; } return false; } // added at phpBB 2.0.11 to properly format the username - public static function phpbb_clean_username($username) + function phpbb_clean_username($username) { $username = substr(htmlspecialchars(str_replace("\'", "'", trim($username))), 0, 25); $username = self::phpbb_rtrim($username, "\\"); @@ -93,13 +478,13 @@ public static function phpbb_clean_username($username) * This function is a wrapper for ltrim, as charlist is only supported in php >= 4.1.0 * Added in phpBB 2.0.18 */ - public static function phpbb_ltrim($str, $charlist = false) + function phpbb_ltrim($str, $charlist = false) { if ($charlist === false) { return ltrim($str); } - + $php_version = explode('.', PHP_VERSION); // php version < 4.1.0 @@ -119,13 +504,13 @@ public static function phpbb_ltrim($str, $charlist = false) } // added at phpBB 2.0.12 to fix a bug in PHP 4.3.10 (only supporting charlist in php >= 4.1.0) - public static function phpbb_rtrim($str, $charlist = false) + function phpbb_rtrim($str, $charlist = false) { if ($charlist === false) { return rtrim($str); } - + $php_version = explode('.', PHP_VERSION); // php version < 4.1.0 @@ -144,6 +529,79 @@ public static function phpbb_rtrim($str, $charlist = false) return $str; } + /** + * Generates an alphanumeric random string of given length + * + * @return string + */ + function gen_rand_string($num_chars = 8) + { + // [a, z] + [0, 9] = 36 + return substr(strtoupper(base_convert(unique_id(), 16, 36)), 0, $num_chars); + } + + /** + * Generates a user-friendly alphanumeric random string of given length + * We remove 0 and O so users cannot confuse those in passwords etc. + * + * @return string + */ + function gen_rand_string_friendly($num_chars = 8) + { + $rand_str = unique_id(); + + // Remove Z and Y from the base_convert(), replace 0 with Z and O with Y + // [a, z] + [0, 9] - {z, y} = [a, z] + [0, 9] - {0, o} = 34 + $rand_str = str_replace(array('0', 'O'), array('Z', 'Y'), strtoupper(base_convert($rand_str, 16, 34))); + + return substr($rand_str, 0, $num_chars); + } + + /** + * Return unique id + */ + function unique_id() + { + return bin2hex(random_bytes(8)); + } + + /** + * Wrapper for mt_rand() which allows swapping $min and $max parameters. + * + * PHP does not allow us to swap the order of the arguments for mt_rand() anymore. + * (since PHP 5.3.4, see http://bugs.php.net/46587) + * + * @param int $min Lowest value to be returned + * @param int $max Highest value to be returned + * + * @return int Random integer between $min and $max (or $max and $min) + */ + function phpbb_mt_rand($min, $max) + { + return ($min > $max) ? mt_rand($max, $min) : mt_rand($min, $max); + } + + /** + * Wrapper for getdate() which returns the equivalent array for UTC timestamps. + * + * @param int $time Unix timestamp (optional) + * + * @return array Returns an associative array of information related to the timestamp. + * See http://www.php.net/manual/en/function.getdate.php + */ + function phpbb_gmgetdate($time = false) + { + if ($time === false) + { + $time = time(); + } + + // getdate() interprets timestamps in local time. + // What follows uses the fact that getdate() and + // date('Z') balance each other out. + return getdate($time - date('Z')); + } + /** * Our own generator of random values * This uses a constantly changing value as the base for generating the values @@ -151,23 +609,23 @@ public static function phpbb_rtrim($str, $charlist = false) * With thanks to Anthrax101 for the inspiration on this one * Added in phpBB 2.0.20 */ - public static function dss_rand() + function dss_rand() { global $db, $board_config, $dss_seeded; $val = $board_config['rand_seed'] . microtime(); $val = md5($val); $board_config['rand_seed'] = md5($board_config['rand_seed'] . $val . 'a'); - + if($dss_seeded !== true) { $sql = "UPDATE " . CONFIG_TABLE . " SET config_value = '" . $board_config['rand_seed'] . "' WHERE config_name = 'rand_seed'"; - - if( !$db->sql_query($sql) ) + + if(!$db->sql_query($sql)) { - mx_message_die(GENERAL_ERROR, "Unable to reseed PRNG", "", __LINE__, __FILE__, $sql); + $this->message_die(GENERAL_ERROR, "Unable to reseed PRNG", "", __LINE__, __FILE__, $sql); } $dss_seeded = true; @@ -175,87 +633,1138 @@ public static function dss_rand() return substr($val, 4, 16); } + // - // Get Userdata, $user can be username or user_id. If force_str is true, the username will be forced. + // Get Userdata, $mx_user can be username or user_id. If force_str is true, the username will be forced. // - public static function get_userdata($user, $force_str = false) + function get_userdata($mx_user, $force_str = false) { global $db; - if (!is_numeric($user) || $force_str) + if (!is_numeric($mx_user) || $force_str) { - $user = self::phpbb_clean_username($user); + $mx_user = $this->phpbb_clean_username($mx_user); } else { - $user = intval($user); + $mx_user = intval($mx_user); } $sql = "SELECT * - FROM " . USERS_TABLE . " + FROM " . USERS_TABLE . " WHERE "; - $sql .= ( ( is_integer($user) ) ? "user_id = $user" : "username = '" . str_replace("\'", "''", $user) . "'" ) . " AND user_id <> " . ANONYMOUS; - if ( !($result = $db->sql_query($sql)) ) + $sql .= ((is_integer($mx_user)) ? "user_id = $mx_user" : "username = '" . str_replace("\'", "''", $mx_user) . "'") . " AND user_id <> " . ANONYMOUS; + if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Tried obtaining data for a non-existent user', '', __LINE__, __FILE__, $sql); } - return ( $row = $db->sql_fetchrow($result) ) ? $row : false; + return ($row = $db->sql_fetchrow($result)) ? $row : false; + } + + /** + * obtain_phpbb_config + * + * @access public + * @param boolean $use_cache + * @return unknown + */ + function obtain_phpbb_config($use_cache = true) + { + global $db, $mx_cache, $phpEx; + + if (($config = $mx_cache->get('phpbb_config')) && ($use_cache) ) + { + return $config; + } + else + { + if (!defined('CONFIG_TABLE')) + { + global $table_prefix, $phpbb_root_path; + + require $phpbb_root_path. "includes/constants.$phpEx"; + } + + $sql = "SELECT * + FROM " . CONFIG_TABLE; + + if ( !( $result = $db->sql_query( $sql ) ) ) + { + if (!function_exists('message_die')) + { + die("Couldnt query config information, Allso this hosting or server is using a cache optimizer not compatible with MX-Publisher or just lost connection to database wile query."); + } + else + { + $this->message_die( GENERAL_ERROR, 'Couldnt query config information', '', __LINE__, __FILE__, $sql ); + } + } + + while ( $row = $db->sql_fetchrow($result) ) + { + $config[$row['config_name']] = $row['config_value']; + } + $db->sql_freeresult($result); + + if ($use_cache) + { + $mx_cache->put('phpbb_config', $config); + } + return $config; + } + } + + /** + * Enter description here... + * + * @return unknown + */ + function generate_group_select_sql() + { + $sql = "SELECT group_id, group_name + FROM " . GROUPS_TABLE . " + WHERE group_single_user <> " . TRUE . " + ORDER BY group_name ASC"; + return $sql; + } + + /** + * Enter description here... + * + * @return unknown + */ + function generate_session_online_sql($guest = false) + { + if ($guest) + { + $sql = "SELECT * + FROM " . SESSIONS_TABLE . " + WHERE session_logged_in = 0 + AND session_time >= " . ( time() - 300 ) . " + ORDER BY session_time DESC"; + } + else + { + $sql = "SELECT u.*, s.* + FROM " . USERS_TABLE . " u, " . SESSIONS_TABLE . " s + WHERE s.session_logged_in = " . TRUE . " + AND u.user_id = s.session_user_id + AND u.user_id <> " . ANONYMOUS . " + AND s.session_time >= " . ( time() - 300 ) . " + ORDER BY u.user_session_time DESC"; + } + return $sql; + } + + /** + * Enter description here... + * + * @return unknown + */ + function get_phpbb_version() + { + global $board_config; + + return '2' . $board_config['version']; } - public static function make_jumpbox($action, $match_forum_id = 0) + /** + * {@inheritdoc} + */ + function mx_chmod($files, $perms = null, $recursive = false, $force_chmod_link = false) { - global $template, $userdata, $lang, $db, $nav_links, $phpEx, $SID; + if (is_null($perms)) + { + // Default to read permission for compatibility reasons + $perms = self::CHMOD_READ; + } + + // Check if we got a permission flag + if ($perms > self::CHMOD_ALL) + { + $file_perm = $perms; - // $is_auth = auth(AUTH_VIEW, AUTH_LIST_ALL, $userdata); + // Extract permissions + //$owner = ($file_perm >> 6) & 7; // This will be ignored + $group = ($file_perm >> 3) & 7; + $other = ($file_perm >> 0) & 7; + + // Does any permissions provided? if so we add execute bit for directories + $group = ($group !== 0) ? ($group | self::CHMOD_EXECUTE) : $group; + $other = ($other !== 0) ? ($other | self::CHMOD_EXECUTE) : $other; + + // Compute directory permissions + $dir_perm = (self::CHMOD_ALL << 6) + ($group << 3) + ($other << 3); + } + else + { + // Add execute bit to owner if execute bit is among perms + $owner_perm = (self::CHMOD_READ | self::CHMOD_WRITE) | ($perms & self::CHMOD_EXECUTE); + $file_perm = ($owner_perm << 6) + ($perms << 3) + ($perms << 0); + + // Compute directory permissions + $perm = ($perms !== 0) ? ($perms | self::CHMOD_EXECUTE) : $perms; + $dir_perm = (($owner_perm | self::CHMOD_EXECUTE) << 6) + ($perm << 3) + ($perm << 0); + } + + // Symfony's filesystem component does not support extra execution flags on directories + // so we need to implement it again + foreach ($this->to_iterator($files) as $file) + { + if ($recursive && is_dir($file) && !is_link($file)) + { + $this->mx_chmod(new \FilesystemIterator($file), $perms, true); + } + + // Don't chmod links as mostly those require 0777 and that cannot be changed + if (is_dir($file) || (is_link($file) && $force_chmod_link)) + { + if (true !== @chmod($file, $dir_perm)) + { + throw new filesystem_exception('CANNOT_CHANGE_FILE_PERMISSIONS', $file, array()); + } + } + else if (is_file($file)) + { + if (true !== @chmod($file, $file_perm)) + { + throw new filesystem_exception('CANNOT_CHANGE_FILE_PERMISSIONS', $file, array()); + } + } + } + } + /** + * {@inheritdoc} + */ + function mx_chown($files, $mx_user, $recursive = false) + { + try + { + @chown($files, $mx_user, $recursive); + } + catch (IOException $e) + { + // Try to recover filename + // By the time this is written that is at the end of the message + $error = trim($e->getMessage()); + $file = substr($error, strrpos($error, ' ')); + + throw new filesystem_exception('CANNOT_CHANGE_FILE_GROUP', $file, array(), $e); + } + } + + /** + * {@inheritdoc} + */ + function mx_chgrp($files, $group, $recursive = false) + { + try + { + @chgrp($files, $group, $recursive); + } + catch (IOException $e) + { + // Try to recover filename + // By the time this is written that is at the end of the message + $error = trim($e->getMessage()); + $file = substr($error, strrpos($error, ' ')); + + throw new filesystem_exception('CANNOT_CHANGE_FILE_GROUP', $file, array(), $e); + } + } + + /** + * Global function for chmodding directories and files for internal use + * + * This function determines owner and group whom the file belongs to and user and group of PHP and then set safest possible file permissions. + * The function determines owner and group from common.php file and sets the same to the provided file. + * The function uses bit fields to build the permissions. + * The function sets the appropiate execute bit on directories. + * + * Supported constants representing bit fields are: + * + * CHMOD_ALL - all permissions (7) + * CHMOD_READ - read permission (4) + * CHMOD_WRITE - write permission (2) + * CHMOD_EXECUTE - execute permission (1) + * + * NOTE: The function uses POSIX extension and fileowner()/filegroup() functions. If any of them is disabled, this function tries to build proper permissions, by calling is_readable() and is_writable() functions. + * + * @param string $filename The file/directory to be chmodded + * @param int $perms Permissions to set + * + * @return bool true on success, otherwise false + * + * @deprecated 3.2.0-dev use \phpbb\filesystem\filesystem::phpbb_chmod() instead + */ + + function phpbb_chmod($files, $perms = null, $recursive = false, $force_chmod_link = false) + { + static $_chmod_info; + + if (is_null($perms)) + { + // Default to read permission for compatibility reasons + $perms = self::CHMOD_READ; + } + + if (empty($_chmod_info)) + { + if (!function_exists('fileowner') || !function_exists('filegroup')) + { + $_chmod_info['process'] = false; + } + else + { + $common_php_owner = @fileowner(__FILE__); + $common_php_group = @filegroup(__FILE__); + + // And the owner and the groups PHP is running under. + $php_uid = (function_exists('posic_getuid')) ? @posix_getuid() : false; + $php_gids = (function_exists('posix_getgroups')) ? @posix_getgroups() : false; + + // If we are unable to get owner/group, then do not try to set them by guessing + if (!$php_uid || empty($php_gids) || !$common_php_owner || !$common_php_group) + { + $_chmod_info['process'] = false; + } + else + { + $_chmod_info = array( + 'process' => true, + 'common_owner' => $common_php_owner, + 'common_group' => $common_php_group, + 'php_uid' => $php_uid, + 'php_gids' => $php_gids, + ); + } + } + } + + if ($_chmod_info['process']) + { + try + { + foreach ($this->to_iterator($files) as $file) + { + $file_uid = @fileowner($file); + $file_gid = @filegroup($file); + + // Change owner + if ($file_uid !== $_chmod_info['common_owner']) + { + $this->mx_chown($file, $_chmod_info['common_owner'], $recursive); + } + + // Change group + if ($file_gid !== $_chmod_info['common_group']) + { + $this->mx_chgrp($file, $_chmod_info['common_group'], $recursive); + } + + clearstatcache(); + $file_uid = @fileowner($file); + $file_gid = @filegroup($file); + } + } + + catch (filesystem_exception $e) + { + $_chmod_info['process'] = false; + } + } + + // Still able to process? + if ($_chmod_info['process']) + { + if ($file_uid === $_chmod_info['php_uid']) + { + $php = 'owner'; + } + else if (in_array($file_gid, $_chmod_info['php_gids'])) + { + $php = 'group'; + } + else + { + // Since we are setting the everyone bit anyway, no need to do expensive operations + $_chmod_info['process'] = false; + } + } + + // We are not able to determine or change something + if (!$_chmod_info['process']) + { + $php = 'other'; + } + + switch ($php) + { + case 'owner': + try + { + $this->mx_chmod($files, $perms, $recursive, $force_chmod_link); + clearstatcache(); + if ($this->is_readable($files) && $this->is_writable($files)) + { + break; + } + } + catch (filesystem_exception $e) + { + // Do nothing + } + case 'group': + try + { + mx_chmod($files, $perms, $recursive, $force_chmod_link); + clearstatcache(); + if ((!($perms & self::CHMOD_READ) || $this->is_readable($files, $recursive)) && (!($perms & self::CHMOD_WRITE) || $this->is_writable($files, $recursive))) + { + break; + } + } + catch (filesystem_exception $e) + { + // Do nothing + } + case 'other': + default: + $this->mx_chmod($files, $perms, $recursive, $force_chmod_link); + break; + } + } + + /** + * Enter description here... + * + * @return unknown + */ + function confirm_backend() + { + return 'phpbb2'; + } + + // Server functions (building urls, redirecting...) + + /** + * Append session id to url. + * This function supports hooks. + * + * @param string $url The url the session id needs to be appended to (can have params) + * @param mixed $params String or array of additional url parameters + * @param bool $is_amp Is url using & (true) or & (false) + * @param string $session_id Possibility to use a custom session id instead of the global one + * @param bool $is_route Is url generated by a route. + * + * @return string The corrected url. + * + * Examples: + * + * append_sid("{$phpbb_root_path}viewtopic.$phpEx?t=1&f=2"); + * append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=1&f=2'); + * append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=1&f=2', false); + * append_sid("{$phpbb_root_path}viewtopic.$phpEx", array('t' => 1, 'f' => 2)); + *
+ * + */ + function append_sid($url, $params = false, $is_amp = true, $session_id = false, $is_route = false) + { + global $SID, $mx_user, $_EXTRA_URL; + + // + // Obtain number of new private messages + // if user is logged in + if(isset($mx_user) || is_object($mx_user)) + { + $SID = $mx_user->session_id; + } + + if ($params === '' || (is_array($params) && empty($params))) + { + // Do not append the ? if the param-list is empty anyway. + $params = false; + } + + // Update the root path with the correct relative web path + if ($is_route === true) + { + $url = $this->generate_board_url(); + } + + $append_sid_overwrite = false; + + if ($append_sid_overwrite) + { + return $append_sid_overwrite; + } + + $params_is_array = is_array($params); //array ( [f] => 1 [t] => 3 [start] => 0 [quickmod] => 1 [redirect] => '') + + // Get anchor + $anchor = ''; + if (strpos($url, '#') !== false) + { + list($url, $anchor) = explode('#', $url, 2); + $anchor = '#' . $anchor; + } + else if (!$params_is_array && strpos($params, '#') !== false) + { + list($params, $anchor) = explode('#', $params, 2); + $anchor = '#' . $anchor; + } + + // Handle really simple cases quickly + if ($SID == '' && $session_id === false && empty($_EXTRA_URL) && !$params_is_array && !$anchor) + { + if ($params === false) + { + return $url; + } + + $url_delim = (strpos($url, '?') === false) ? '?' : (($is_amp) ? '&' : '&'); + return $url . ($params !== false ? $url_delim. $params : ''); + } + + // Assign sid if session id is not specified + if ($session_id === false) + { + $session_id = $SID; + } + + $amp_delim = ($is_amp) ? '&' : '&'; + $url_delim = (strpos($url, '?') === false) ? '?' : $amp_delim; + + // Appending custom url parameter? + $append_url = (!empty($_EXTRA_URL)) ? implode($amp_delim, $_EXTRA_URL) : ''; + + // Use the short variant if possible ;) + if ($params === false) + { + // Append session id + if (!$session_id) + { + return $url . (($append_url) ? $url_delim . $append_url : '') . $anchor; + } + else + { + return $url . (($append_url) ? $url_delim . $append_url . $amp_delim : $url_delim) . 'sid=' . $session_id . $anchor; + } + } + + // Build string if parameters are specified as array + if (is_array($params)) + { + $output = array(); + + foreach ($params as $key => $item) + { + if ($item === NULL) + { + continue; + } + + if ($key == '#') + { + $anchor = '#' . $item; + continue; + } + + $output[] = $key . '=' . $item; + } + + $params = implode($amp_delim, $output); + } + + // Append session id and parameters (even if they are empty) + // If parameters are empty, the developer can still append his/her parameters without caring about the delimiter + $url = $url . (($append_url) ? $url_delim . $append_url . $amp_delim : $url_delim) . $params . ((!$session_id) ? '' : $amp_delim . 'sid=' . $session_id) . $anchor; + + if (!empty($SID) && !preg_match('#sid=#', $url)) + { + $url .= $SID; + } + } + + /** + * Returns url from the session/current page with an re-appended SID with optionally stripping vars from the url + */ + function build_url($strip_vars = false) + { + global $mx_user, $phpEx, $phpbb_root_path; + + // Append SID + $redirect = $this->append_sid('index.'.$phpEx, false, false); + + // Add delimiter if not there... + if (strpos($redirect, '?') === false) + { + $redirect .= '?'; + } + + // Strip vars... + if ($strip_vars !== false && strpos($redirect, '?') !== false) + { + if (!is_array($strip_vars)) + { + $strip_vars = array($strip_vars); + } + + $query = $_query = array(); + + $args = substr($redirect, strpos($redirect, '?') + 1); + $args = ($args) ? explode('&', $args) : array(); + $redirect = substr($redirect, 0, strpos($redirect, '?')); + + foreach ($args as $argument) + { + $arguments = explode('=', $argument); + $key = $arguments[0]; + unset($arguments[0]); + + if ($key === '') + { + continue; + } + + $query[$key] = implode('=', $arguments); + } + + // Strip the vars off + foreach ($strip_vars as $strip) + { + if (isset($query[$strip])) + { + unset($query[$strip]); + } + } + + // Glue the remaining parts together... already urlencoded + foreach ($query as $key => $value) + { + $_query[] = $key . '=' . $value; + } + $query = implode('&', $_query); + + $redirect .= ($query) ? '?' . $query : ''; + } + + // We need to be cautious here. + // On some situations, the redirect path is an absolute URL, sometimes a relative path + // For a relative path, let's prefix it with $phpbb_root_path to point to the correct location, + // else we use the URL directly. + $url_parts = @parse_url($redirect); + + // URL + if ($url_parts !== false && !empty($url_parts['scheme']) && !empty($url_parts['host'])) + { + return str_replace('&', '&', $redirect); + } + + return $phpbb_root_path . str_replace('&', '&', $redirect); + } + + /** + * Generate board url (example: http://www.example.com/phpBB) + * + * @param bool $without_script_path if set to true the script path gets not appended (example: http://www.example.com) + * + * @return string the generated board url + */ + function generate_board_url($without_script_path = false) + { + global $board_config, $userdata, $mx_user; + + $server_name = !empty($board_config['server_name']) ? preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($board_config['server_name'])) : 'localhost'; + $server_protocol = ($board_config['cookie_secure'] ) ? 'https://' : 'http://'; + $server_port = (($board_config['server_port']) && ($board_config['server_port'] <> 80)) ? ':' . trim($board_config['server_port']) . '/' : ((!empty($_SERVER['SERVER_PORT'])) ? (int) $_SERVER['SERVER_PORT'] : (int) getenv('SERVER_PORT')); + $script_name_phpbb = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($board_config['script_path'])) . '/'; + $server_url = $server_protocol . str_replace("//", "/", $server_name . $server_port . $server_name . '/'); //On some server the slash is not added and this trick will fix it + + // Forcing server vars is the only way to specify/override the protocol + if (!$server_name) + { + $server_protocol = ($board_config['server_protocol']) ? $board_config['server_protocol'] : (($board_config['cookie_secure']) ? 'https://' : 'http://'); + $server_name = $board_config['server_name']; + $server_port = (int) $board_config['server_port']; + $script_path = $board_config['script_path']; + + $url = $server_protocol . $server_name; + $cookie_secure = $board_config['cookie_secure']; + } + else + { + // Do not rely on cookie_secure, users seem to think that it means a secured cookie instead of an encrypted connection + $cookie_secure = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 1 : 0; + $url = (($cookie_secure) ? 'https://' : 'http://') . $server_name; + + $script_path = $url; + } + + if ($server_port && (($cookie_secure && $server_port <> 443) || (!$cookie_secure && $server_port <> 80))) + { + // HTTP HOST can carry a port number (we fetch $mx_user->host, but for old versions this may be true) + if (strpos($server_name, ':') === false) + { + $url .= ':' . $server_port; + } + } + + if (!$without_script_path) + { + $url .= $script_path; + } + + // Strip / from the end + if (substr($url, -1, 1) == '/') + { + $url = substr($url, 0, -1); + } + + return $url; + } + + /* + * Creates a full server path + * for icy templates + */ + function create_server_url($without_script_path = false) + { + // usage: $server_url = create_server_url(); + global $board_config; + + $server_protocol = ($board_config['cookie_secure']) ? 'https://' : 'http://'; + $server_name = preg_replace('#^\/?(.*?)\/?$#', '\1', trim($board_config['server_name'])); + $server_port = ($board_config['server_port'] <> 80) ? ':' . trim($board_config['server_port']) : ''; + $script_name = preg_replace('/^\/?(.*?)\/?$/', '\1', trim($board_config['script_path'])); + $script_name = ($script_name == '') ? '' : '/' . $script_name; + $server_url = $server_protocol . $server_name . $server_port . ($without_script_path ? '' : $script_name); + while(substr($server_url, -1, 1) == '/') + { + $server_url = substr($server_url, 0, -1); + } + $server_url = $server_url . '/'; + + return $server_url; + } + + /** + * Get username details for placing into templates. + * + * @param string $mode Can be profile (for getting an url to the profile), username (for obtaining the username), colour (for obtaining the user colour) or full (for obtaining a html string representing a coloured link to the users profile). + * @param int $mx_user_id The users id + * @param string $username The users name + * @param string $username_colour The users colour + * @param string $guest_username optional parameter to specify the guest username. It will be used in favor of the GUEST language variable then. + * @param string $custom_profile_url optional parameter to specify a profile url. The user id get appended to this url as &u={user_id} + * + * @return string A string consisting of what is wanted based on $mode. + */ + function get_username_string($mode, $mx_user_id, $username = false, $mx_user_colour = false, $guest_username = false, $custom_profile_url = false) + { + global $mx_user, $lang, $phpEx; + + $lang['Guest'] = !$guest_username ? $lang['Guest'] : $guest_username; + + $this_userdata = get_userdata($mx_user_id, false); + $topic_poster_style = 'style="font-weight : bold;"'; + + $username = ($username) ? $username : $this_userdata['username']; + + if ($this_userdata['user_level'] == ADMIN) + { + $mx_user_colour = ($mx_user_colour) ? $mx_user_colour : $mx_user->theme['fontcolor3']; + $mx_user_style = 'style="color:#' . $mx_user_colour . '; font-weight : bold;"'; + } + else if ($this_userdata['user_level'] == MOD) + { + $mx_user_colour = ($mx_user_colour) ? $mx_user_colour : $mx_user->theme['fontcolor2']; + $mx_user_style = 'style="color:#' . $mx_user_colour . '; font-weight : bold;"'; + } + else + { + $mx_user_colour = ($mx_user_colour) ? $mx_user_colour : $mx_user->theme['fontcolor1']; + $mx_user_style = 'style="color:#' . $mx_user_colour . '; font-weight : bold;"'; + } + // print_r(substr($mx_user_colour, 0, 3) . substr($mx_user_colour, 3, 2)); + // Only show the link if not anonymous + if ($mx_user_id != ANONYMOUS) + { + $profile_url = $this->append_sid(PHPBB_URL . "profile.$phpEx?mode=viewprofile&u=" . (int) $mx_user_id); + $full_url = '' . $username . ''; + } + else + { + $profile_url = $lang['Guest']; + $full_url = $lang['Guest']; + } + + switch ($mode) + { + case 'profile': + return $profile_url; + break; + + case 'username': + return $username; + break; + + case 'colour': + return $mx_user_colour; + break; + + case 'full': + default: + return $full_url; + break; + } + } + + /** + * Get user avatar + * + * @param array $mx_user_row Row from the users table + * @param string $alt Optional language string for alt tag within image, can be a language key or text + * @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP + * @param bool $lazy If true, will be lazy loaded (requires JS) + * + * @return string Avatar html + */ + function phpbb_get_user_avatar($mx_user_row, $alt = 'USER_AVATAR', $ignore_config = false, $lazy = false) + { + return phpbb_get_avatar($mx_user_row, $alt, $ignore_config, $lazy); + } + + /** + * Get group avatar + * + * @param array $group_row Row from the groups table + * @param string $alt Optional language string for alt tag within image, can be a language key or text + * @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP + * @param bool $lazy If true, will be lazy loaded (requires JS) + * + * @return string Avatar html + */ + function phpbb_get_group_avatar($mx_user_row, $alt = 'GROUP_AVATAR', $ignore_config = false, $lazy = false) + { + return phpbb_get_avatar($mx_user_row, $alt, $ignore_config, $lazy); + } + + /** + * Build gravatar URL for output on page + * + * @param array $row User data or group data that has been cleaned with + * \phpbb\avatar\manager::clean_row + * @return string Gravatar URL + */ + function get_gravatar_url($row) + { + $url = '//secure.gravatar.com/avatar/'; + + $url .= md5(strtolower(trim($row['avatar']))); + + if ($row['avatar_width'] || $row['avatar_height']) + { + $url .= '?s=' . max($row['avatar_width'], $row['avatar_height']); + } + + return $url; + } + + /** + * Get avatar + * + * @param array $row Row cleaned by \phpbb\avatar\manager::clean_row + * @param string $alt Optional language string for alt tag within image, can be a language key or text + * @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP + * @param bool $lazy If true, will be lazy loaded (requires JS) + * + * @return string Avatar html + */ + function phpbb_get_avatar($row, $alt, $ignore_config = false, $lazy = false) + { + global $mx_user, $board_config, $mx_cache, $phpbb_root_path, $phpEx; + + if (!$mx_user->optionget('viewavatars') && !$ignore_config) + { + return ''; + } + + $row = array( + 'avatar' => isset($row['avatar']) ? $row['avatar'] : $row['user_avatar'], + 'avatar_type' => isset($row['avatar_type']) ? $row['avatar_type'] : $row['user_avatar_type'], + 'avatar_width' => isset($row['avatar_width']) ? $row['avatar_width'] : (isset($row['user_avatar_width']) ? $row['user_avatar_width'] : '120'), + 'avatar_height' => isset($row['avatar_height']) ? $row['avatar_height'] : (isset($row['user_avatar_height']) ? $row['user_avatar_height'] : '120'), + ); + + $avatar_data = array( + 'src' => $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], + ); + + + $driver = $row['avatar_type']; + $html = ''; + + if ($driver) + { + $html = ''; + + if (!empty($html)) + { + return $html; + } + + $root_path = $this->generate_board_url(); + + $avatar_data = array( + 'src' => $root_path . $board_config['avatar_gallery_path'] . '/' . $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], + ); + } + else + { + $avatar_data['src'] = ''; + } + + if (!empty($avatar_data['src'])) + { + if ($lazy) + { + // Determine board url - we may need it later + $board_url = $this->generate_board_url() . '/'; + // This path is sent with the base template paths in the assign_vars() + // call below. We need to correct it in case we are accessing from a + // controller because the web paths will be incorrect otherwise. + + $web_path = $board_url; + + if (is_dir($phpbb_root_path . $mx_user->template_path . $mx_user->template_name . '/theme/images/')) + { + $theme_images = "{$web_path}{$mx_user->template_path}" . rawurlencode($mx_user->template_name) . '/theme/images'; + } + elseif (is_dir($phpbb_root_path . $mx_user->template_path . $mx_user->template_name . '/images/')) + { + $theme_images = "{$web_path}{$mx_user->template_path}" . rawurlencode($mx_user->template_name . '/images'); + } + $src = 'src="' . $theme_images . '/no_avatar.gif" data-src="' . $avatar_data['src'] . '"'; + } + else + { + $src = 'src="' . $avatar_data['src'] . '"'; + } + + $html = '
lang[$alt])) ? $mx_user->lang[$alt] : $alt) . '" />'; + } + return $html; + } + + /** + * Get user rank title and image + * + * @param array $mx_user_data the current stored users data + * @param int $mx_user_posts the users number of posts + * + * @return array An associative array containing the rank title (title), the rank image as full img tag (img) and the rank image source (img_src) + * + * Note: since we do not want to break backwards-compatibility, this function will only properly assign ranks to guests if you call it for them with user_posts == false + */ + function phpbb_get_user_rank($mx_user_data, $mx_user_posts, &$rank_title = null, &$rank_img = null, &$rank_img_src = null) + { + global $ranks, $config, $phpbb_root_path; + + $mx_user_rank_data = array( + 'title' => $rank_title ? $rank_title : null, + 'img' => $rank_img ? $rank_img : null, + 'img_src' => $rank_img_src ? $rank_img_src : null, + ); + + if (empty($ranks)) + { + global $mx_cache; + $ranks = $mx_cache->obtain_ranks(); + } + + if (!empty($mx_user_data)) + { + $mx_user_rank_data['title'] = (isset($ranks['special'][$mx_user_data['user_rank']]['rank_title'])) ? $ranks['special'][$mx_user_data['user_rank']]['rank_title'] : ''; + $mx_user_rank_data['img_src'] = (!empty($ranks['special'][$mx_user_data['user_rank']]['rank_image'])) ? $phpbb_root_path . $config['ranks_path'] . '/' . $ranks['special'][$mx_user_data['user_rank']]['rank_image'] : ''; + $mx_user_rank_data['img'] = (!empty($ranks['special'][$mx_user_data['user_rank']]['rank_image'])) ? '
' : ''; + + } + else if ($mx_user_posts !== false) + { + if (!empty($ranks['normal'])) + { + foreach ($ranks['normal'] as $rank) + { + if ($mx_user_posts >= $rank['rank_min']) + { + $mx_user_rank_data['title'] = $rank['rank_title']; + $mx_user_rank_data['img'] = (!empty($rank['rank_image'])) ? '
' : ''; + $mx_user_rank_data['img_src'] = (!empty($rank['rank_image'])) ? $phpbb_root_path . $config['ranks_path'] . '/' . $rank['rank_image'] : ''; + break; + } + } + } + } + + return $mx_user_rank_data; + } + + /** + * Generate sort selection fields + */ + function gen_sort_selects(&$limit_days, &$sort_by_text, &$sort_days, &$sort_key, &$sort_dir, &$s_limit_days, &$s_sort_key, &$s_sort_dir, &$u_sort_param, $def_st = false, $def_sk = false, $def_sd = false) + { + global $mx_user, $phpbb_dispatcher; + + $sort_dir_text = array('a' => $mx_user->lang('Ascending'), 'd' => $mx_user->lang('Descending')); + + $sorts = array( + 'st' => array( + 'key' => 'sort_days', + 'default' => $def_st, + 'options' => $limit_days, + 'output' => &$s_limit_days, + ), + + 'sk' => array( + 'key' => 'sort_key', + 'default' => $def_sk, + 'options' => $sort_by_text, + 'output' => &$s_sort_key, + ), + + 'sd' => array( + 'key' => 'sort_dir', + 'default' => $def_sd, + 'options' => $sort_dir_text, + 'output' => &$s_sort_dir, + ), + ); + $u_sort_param = ''; + + foreach ($sorts as $name => $sort_ary) + { + $key = $sort_ary['key']; + $selected = ${$sort_ary['key']}; + + // Check if the key is selectable. If not, we reset to the default or first key found. + // This ensures the values are always valid. We also set $sort_dir/sort_key/etc. to the + // correct value, else the protection is void. ;) + if (!isset($sort_ary['options'][$selected])) + { + if ($sort_ary['default'] !== false) + { + $selected = ${$key} = $sort_ary['default']; + } + else + { + @reset($sort_ary['options']); + $selected = ${$key} = key($sort_ary['options']); + } + } + + $sort_ary['output'] = ''; + + $u_sort_param .= ($selected !== $sort_ary['default']) ? ((strlen($u_sort_param)) ? '&' : '') . "{$name}={$selected}" : ''; + } + + return; + } + + /** + * Generate Jumpbox + */ + function make_jumpbox($action, $match_forum_id = 0) + { + $list = array(); + return $this->make_jumpbox_ref($action, $match_forum_id, $list); + } + + function make_jumpbox_ref($action, $match_forum_id, &$forums_list) + { + global $template, $mx_user, $lang, $db, $nav_links, $phpEx, $SID; $sql = "SELECT c.cat_id, c.cat_title, c.cat_order - FROM " . CATEGORIES_TABLE . " c, " . FORUMS_TABLE . " f - WHERE f.cat_id = c.cat_id - GROUP BY c.cat_id, c.cat_title, c.cat_order - ORDER BY c.cat_order"; - if ( !($result = $db->sql_query($sql)) ) + FROM " . CATEGORIES_TABLE . " c, " . FORUMS_TABLE . " f + WHERE f.cat_id = c.cat_id + GROUP BY c.cat_id, c.cat_title, c.cat_order + ORDER BY c.cat_order"; + if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, "Couldn't obtain category list.", "", __LINE__, __FILE__, $sql); } $category_rows = array(); - while ( $row = $db->sql_fetchrow($result) ) + while ($row = $db->sql_fetchrow($result)) { $category_rows[] = $row; } - if ( $total_categories = count($category_rows) ) + if ($total_categories = count($category_rows)) { - $sql = "SELECT * - FROM " . FORUMS_TABLE . " - ORDER BY cat_id, forum_order"; - if ( !($result = $db->sql_query($sql)) ) + $sql = "SELECT f.*, f.forum_id, f.forum_name, f.forum_parent, f.cat_id as forum_type, f.forum_id as left_id, f.forum_id as right_id + FROM " . FORUMS_TABLE . " f + ORDER BY f.cat_id, f.forum_order"; + if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not obtain forums information', '', __LINE__, __FILE__, $sql); } $boxstring = '