<?php

/**
 * @package             Joomla Admin Mobile
 * @copyright (C) 2009-2011 by Covert Apps - All rights reserved
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

if(!defined('E_RECOVERABLE_ERROR')) {
        define('E_RECOVERABLE_ERROR', 4096);
}

function JoomlaAdminMobileErrorHandler($errno, $errstr, $errfile, $errline)
{
	print $errno.": ".$errstr." (".$errline.")";
	exit;
}

$params =& JComponentHelper::getParams('com_joomlaadminmobile');
if($params->get("debug"))
{
	//error_reporting(E_ALL);
	ini_set('display_errors', '1');
	// http://us2.php.net/manual/en/errorfunc.constants.php
	set_error_handler("JoomlaAdminMobileErrorHandler", E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR);
}
else
{
	// Try to force display_errors to zero for our users to avoid warnings.
	ini_set('display_errors', '0');
}

if(JRequest::getCmd('testwarning')) {
        trigger_error('This is testing warnings from php', E_USER_WARNING);
}
if(JRequest::getCmd('testerror')) {
        trigger_error('This is testing errors from php', E_USER_ERROR);
}

// Be careful not to include xmlrpc twice or we get - Cannot redeclare xmlrpc_encode_entitites().  I'm not sure how it was happening, but a user reported it with 1.5.23
if(!defined('PHP_XMLRPC_COMPAT_DIR') && !function_exists('xmlrpc_encode_entitites'))
{
	require('phpxmlrpc'.DS.'xmlrpc.php');
}
if(!function_exists('_xmlrpcs_getCapabilities'))
{
	require('phpxmlrpc'.DS.'xmlrpcs.php');
}
require('joomlaadminmobilexmlrpc.php');

// Disable response compression.
$config =& JFactory::getConfig();
$config->setValue('config.gzip', 0);

$xmlrpcServer = new xmlrpc_server(JoomlaAdminMobileXmlRpc::onGetWebServices(), false);
// allow casting to be defined by that actual values passed
$xmlrpcServer->functions_parameters_type = 'phpvals';
// define UTF-8 as the internal encoding for the XML-RPC server
// Disable response compression.
$xmlrpcServer->compress_response = 0;
$encoding = "UTF-8";
$xmlrpcServer->xml_header($encoding);
$xmlrpc_internalencoding = $encoding;
$GLOBALS['xmlrpc_internalencoding'] = $encoding;

// debug level
$xmlrpcServer->setDebug(0);
// start the service
$xmlrpcServer->service();

?>
