<?php
/*
 * XPressME - WordPress for XOOPS
 *
 * @copyright	XPressME Project http://www.toemon.com
 * @license		http://www.fsf.org/copyleft/gpl.html GNU public license
 * @author		toemon
 * @package		module::xpress
 */

/* 
 * There is a function that detects the kind of the page that the access is here. 
 */

function is_xpress_index_page_call(){
	$xpress_root_index = basename(dirname(dirname( __FILE__ ))) . '/index.php';
	$php_script_name = $_SERVER['SCRIPT_NAME'];
	$php_query_string = $_SERVER['QUERY_STRING'];
	if (strstr($php_script_name,$xpress_root_index) !== false) {
		if (strstr($php_query_string,'preview') === false) return true; else return false;;
	} else  {
		return false;
	}
}

function is_admin_page_call(){
	$xpress_root_index = basename(dirname(dirname( __FILE__ ))) . '/wp-admin';
	$php_script_name = $_SERVER['SCRIPT_NAME'];
	if (strstr($php_script_name,$xpress_root_index) !== false) return true; else  return false;
}

function is_media_upload_page_call(){
	$xpress_root_indexs[0] = basename(dirname(dirname( __FILE__ ))) . '/wp-admin/async-upload.php';
	$php_script_name = $_SERVER['SCRIPT_NAME'];
	foreach ($xpress_root_indexs as $xpress_root_index) {
		if (strstr($php_script_name,$xpress_root_index) !== false) return true;
	}
	return false;
}

function is_xmlrpc_call(){

	$xpress_root_index = basename(dirname(dirname( __FILE__ ))) . '/xmlrpc.php';
	$php_script_name = $_SERVER['SCRIPT_NAME'];
	if(strstr($php_script_name,$xpress_root_index) !== false) $ret = true; else  $ret = false;
	$xmlrpc_debug = 0;
	

	if ($xmlrpc_debug) {
		$_debug_file = './wp-content/debug.log';
		$log_data = '';
		$log_data .= 'is_xmlrpc_call()***********************************************************************'. "\n";
		if ($ret) $ret_val = 'true'; else $ret_val = 'false';
		$log_data .= 'return value = ' . $ret_val . "\n";
		
		foreach($_SERVER as $key => $value){
			$log_data .= $key . ' = ' . $value . "\n";
		}

		$_fp = fopen($_debug_file, 'a');
		fwrite($_fp, $log_data);
		fwrite($_fp, "\n\n");
		fclose($_fp);		
	}
	return $ret;
}

function is_wp_cron_call(){
	$xpress_root_index = basename(dirname(dirname( __FILE__ ))) . '/wp-cron.php';
	$php_script_name = $_SERVER['SCRIPT_NAME'];
	if (strstr($php_script_name,$xpress_root_index) !== false) return true; else  return false;
}

?>
