<?php
global $xoops_config;
if (!is_object($xoops_config)){ // is call other modules
	require_once dirname(dirname(dirname(dirname(dirname( __FILE__ ))))) .'/class/config_from_xoops.class.php' ;
	$xoops_config = new ConfigFromXoops;
}

function get_xoops_config($config_name,$module_dir){
	global $xoops_db;
	
	$modules_db = get_xoops_prefix() . 'modules';
	$config_db = get_xoops_prefix() . 'config';

	$moduleID = $xoops_db->get_var("SELECT mid FROM $modules_db WHERE dirname = '$module_dir'");
	if (empty($moduleID)) return null;
	$conf_value = $xoops_db->get_var("SELECT conf_value FROM $config_db WHERE (conf_modid = $moduleID) AND (conf_name = '$config_name')");
	if (empty($conf_value)) return null;
	return  $conf_value;
}

// xoops db
function get_xpress_dir_path()
{
	return ABSPATH;
}

function get_xpress_dir_name()
{
	return basename(ABSPATH);
}

function get_wp_prefix_only()
{
	$dir_name = get_xpress_dir_name();
	$prefix = $dir_name;
	if ($prefix == 'wordpress') $prefix = 'wp';
	
	$prefix = $prefix . '_';
	return $prefix;
}

function get_xoops_prefix()
{
	global $xoops_config;
	$ret =$xoops_config->xoops_db_prefix . '_';
	return $ret;
}

function get_xoops_trust_path()
{
	global $xoops_config;
	$ret =$xoops_config->xoops_trust_path;
	return $ret;
}

function get_xoops_root_path()
{
	global $xoops_config;
	$ret =$xoops_config->xoops_root_path;
	return $ret;
}

function get_wp_prefix()
{
	$prefix = get_xoops_prefix() . get_wp_prefix_only();
	return $prefix;
}
function get_xoops_url()
{
	global $xoops_config;
	$ret =$xoops_config->xoops_url ;
	return $ret;
}

function get_xpress_url()
{
	global $xoops_config;
	$ret =$xoops_config->module_url ;
	return $ret;
}

function get_xpress_modid()
{
	global $xoops_db;
	
	$modulename = get_xpress_dir_name();	
	$sql = "SELECT mid FROM " . get_xoops_prefix() . "modules WHERE dirname = '$modulename'";
	$mid = $xoops_db->get_var($sql);
	return $mid;	
}

function get_xpress_db_version()
{
	include get_xpress_dir_path() . '/wp-includes/version.php';
	return $wp_db_version;
}

function is_xpress_mobile()
{
	//ktai_style
 	if (function_exists('is_ktai')){
 		if (is_ktai()) {
 //			$file_path = $GLOBALS['xoopsModuleConfig']["ktai_style_tmpdir"] . '/comments.php';
			return true;
		}
	}
	
	//mobg
	if (function_exists('is_mobile')) {
		if (is_mobile()){
			return true;
		}
	}
	if (
	  preg_match("/DoCoMo/", $_SERVER['HTTP_USER_AGENT']) ||
	  preg_match("/softbank/", $_SERVER['HTTP_USER_AGENT']) ||
	  preg_match("/vodafone/", $_SERVER['HTTP_USER_AGENT']) ||
	  preg_match("/J-PHONE/", $_SERVER['HTTP_USER_AGENT']) ||
	  preg_match("/UP\.Browser/", $_SERVER['HTTP_USER_AGENT']) ||
	  preg_match("/ASTEL/", $_SERVER['HTTP_USER_AGENT']) ||
	  preg_match("/PDXGW/", $_SERVER['HTTP_USER_AGENT'])
	) 
	{
		return true;
	} else {
		return false;
	}
}

?>