prefix = get_xoops_prefix();
$xoops_db->tables = array('modules', 'newblocks', 'users');
$xpress_config = new XPressME_Class();
require_once dirname( __FILE__ ).'/include/pluggable-override.php' ;
require_once dirname( __FILE__ ).'/include/functions_for_wp_old.php' ;
function my_plugin_menu()
{
	global $xpress_config,$xoops_config;
	
	$plugin_url = WP_PLUGIN_URL."/xpressme/";
	// Add a new top-level menu:
	add_menu_page('XPressME','XPressME', 8, __FILE__, 'display_option_page' , $plugin_url.'/images/menu_icon.png');
	// Add submenus to the custom top-level menu:
	add_submenu_page(__FILE__, __('Display Settings', 'xpressme'), __('Display Settings', 'xpressme'), 8, __FILE__, 'display_option_page');
	add_submenu_page(__FILE__, __('Integration Settings', 'xpressme'), __('Integration Settings', 'xpressme'), 8, 'integration_option_page', 'integration_option_page');
	add_submenu_page(__FILE__, __('Other Settings', 'xpressme'), __('Other Settings', 'xpressme'), 8, 'other_option_page', 'other_option_page');
//	if (function_exists('wp_remote_get'))
		add_submenu_page(__FILE__, __('Upgrade', 'xpressme'), __('Upgrade', 'xpressme'), 8, 'upgrade_page', 'upgrade_page');
	add_submenu_page(__FILE__, __('to XOOPS Admin', 'xpressme'), __('to XOOPS Admin', 'xpressme'), 8,  'redirect_xoops_admin', 'redirect_xoops_admin');
}
add_action('admin_menu', 'my_plugin_menu');
add_filter("upload_dir",array(&$xpress_config, 'xpress_upload_filter'),	1);		// Change wp-include/wp_upload_dir()
if (!$xpress_config->is_save_post_revision){
	remove_action( 'pre_post_update', 'wp_save_post_revision' );			// Not Save Post Revision
}
add_action("wp_meta" , "wp_meta_add_xpress_menu");			// add xpress menu  in wp_meta
	
//Site URL check
add_filter('option_home',			"safe_site_url_filter");
add_filter('option_siteurl',		"safe_site_url_filter");
	
//XOOPS Bloack Cache Refresh
add_action("comment_post",	"block_cache_refresh");
add_action("edit_comment",	"block_cache_refresh");
add_action("wp_set_comment_status","block_cache_refresh"); //wp_delete_comment() at deleted
add_action("deleted_post",	"block_cache_refresh");
add_action("publish_post",	"block_cache_refresh");
add_action("edit_post",		"block_cache_refresh");
add_action("private_to_published",	"block_cache_refresh");
add_action("transition_post_status", "block_cache_refresh");
add_action("the_content",	"set_post_views_count");
//XOOPS notifiction
require_once dirname( __FILE__ ).'/include/notify_functions.php' ;
add_action("transition_post_status",	"onaction_publish_post_notify" ,10 , 3);
//	add_action("edit_post",	"onaction_edit_post_notify");
add_action("comment_post",	"onaction_comment_notify");
//	add_action("approve_comment" , "onaction_comment_apobe_notify");
add_action("wp_set_comment_status" , "onaction_comment_apobe_notify");
// user data sync  user_sync_to_xoops($user_id)
require_once dirname( __FILE__ ).'/include/user_sync_xoops.php' ;
add_action('profile_update', 'user_sync_to_xoops');
add_action('user_register', 'user_sync_to_xoops');
//require_once('../include/custom_functions.php');
//D3Forum Comment Integration
if ($xpress_config->is_use_d3forum){
	require_once dirname( __FILE__ ).'/include/d3forum_comment_synchro.php' ;
	add_action("comment_post",	"onaction_comment_post");
	add_action("edit_comment",	"onaction_edit_comment");
	add_action("delete_comment","onaction_delete_comment");
	add_action("delete_post",	"onaction_delete_post");
	add_action("wp_set_comment_status" , "onaction_comment_apobe");
	
	
	add_filter('comments_template', "disp_d3forum_comments" );
}
//The trackback and the pingback are excluded from the count of the comment. 
add_filter('get_comments_number', 'xpress_comment_count', 0);
// Query filter for  MultiUser
add_filter('query','xpress_query_filter');
//add_action("init", "xpress_set_author_cookie");
if(xpress_is_wp_version('<','2.1')){
	// It is called before parse_request() makes $GET. 
	add_action("query_vars", "xpress_set_author_cookie");
} else {
	// It is called at the end of parse_request(). 
	add_filter('request', 'xpress_set_author_cookie');
}
// SQL debug windows
add_filter('query', array(&$xpress_config, 'xpress_sql_debug'));
add_action('admin_footer', array(&$xpress_config, 'displayDebugLog'));
add_action('wp_footer', array(&$xpress_config, 'displayDebugLog'));
function redirect_xoops_admin()
{
	global $xoops_config,$xpress_config;
	$xoops_admin_url = $xoops_config->module_url . '/admin/index.php';
	wp_redirect($xoops_admin_url);
}
function display_option_page()
{
	global $xoops_config,$xpress_config;
	
		$xoops_admin_url = $xoops_config->module_url . '/admin/index.php';
		$do_message ='';
		if (!empty($_POST['submit_update'])) {
			$xpress_config->ReadPostData($_POST);
			$xpress_config->SettingValueWrite('update');
		} else if (isset($_POST['submit_reset'])) {
			$xpress_config->setDefault();
			$xpress_config->SettingValueWrite('update');
		}
		
		echo	'
'."\n";
		echo		'
'."\n";
		echo		'
' . __('XPressME Display Setting', 'xpressme') . "
\n";
//		echo 		'
';
		echo		'
\n" ;
		echo	"
'."\n";
		echo		'
'."\n";
		echo		'
' . __('XPressME Integration Setting', 'xpressme') . "
\n";
//		echo 		'
';
		echo		'
\n" ;
		echo	"
'."\n";
		echo		'
'."\n";
		echo		'
' . __('XPressME Other Setting', 'xpressme') . "
\n";
//		echo 		'
';
		echo		'
\n" ;
		echo	"
'."\n";
	echo		'
'."\n";
	echo		'
' . __('XPressME Upgrade', 'xpressme') . "
\n";
	
	if(get_xpress_latest_version()){
		$latest = get_option('xpressme_latest_version');
		if ($latest) {
			$site_url=$latest['url'];
			$package=$latest['package'];
			$latest_version=$latest['latest_version'];
			$check_time=$latest['check_time'];
		}
		if (version_compare($xpress_version, $latest_version, '>')){
				echo '
';
				printf(__('You are using a XPressME Integration Kit development version (%1$s). Cool! Please stay updated.', 'xpressme') , $xpress_version , $site_url);
				echo '
';
		} else if (version_compare($xpress_version, $latest_version, '<')) {
			echo	'
'. __('There is a new version of XPressME Integration Kit available for upgrade', 'xpressme') . '
';
			echo '
';
	//		printf(__('You can upgrade to version %s automatically or download the package and install it manually:'),$latest_version);
			printf(__('You can upgrade to version %s download the package and install it manually:', 'xpressme'),$latest_version);
			echo '
';
			echo '
';
			printf(__('Download %s', 'xpressme') , $latest_version);
			echo '';
		} else {
			echo	'
'. __('You have the latest version of XPressME Integration Kit. You do not need to upgrade', 'xpressme') . '
';
		}
	} else {
		echo '
';
		printf(__('There is no response from version check API now. sorry, please confirm it after.', 'xpressme'),$check_url);
		echo	"
$msg 
";
		}
	}
}
add_action( 'admin_notices', 'xpress_update_check', 3 );
include_once dirname( __FILE__ ).'/include/dashboard_feed.php' ;
?>