<?php
/**
 * Boot code for TeamBuddy
 */

// General error handling
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
    throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler("exception_error_handler");

// Include Francis FW
$dependencies = dirname( __FILE__ ) . '/../../../../../dependencies';
require_once $dependencies . '/Francis/config/boot_francis.php';
Francis_Utils_Config::set( 'path.dependencies', $dependencies );

// Construct paths
Francis_Utils_Config::set( 'path.root', realpath( dirname( __FILE__ ) . '/../../..' ) );

// Set autoloader
Francis_Core_Autoloader::attachLocator( new Francis_Core_Locator( 'TB', Francis_Utils_Config::get( 'path.root' ) . '/src' ) );

// Action controller path
Francis_Utils_Config::set( 'path.server.controller', Francis_Utils_Config::get( 'path.root' ) . '/src/server/control' );

// Setting application version
$version = '0.0';
$versionArr = json_decode( file_get_contents( Francis_Utils_Config::get( 'path.root' ) . '/version.json' ), true );
if ( is_array( $versionArr ) && isset( $versionArr[ 'version' ] ) ) {
    $version = $versionArr[ 'version' ];
}
Francis_Utils_Config::set( 'version', $version );

// Google Push Notifications
Francis_Utils_Config::set( 'push.gcm.apikey', 'AIzaSyCx2rDPdJPjWEOZqanaBsUZddj3n0j27Sw' );

require_once( $dependencies. '/braintree_php-master/lib/Braintree.php' );

// Global shortcut function
// @todo Replace later
function _lc( $txt, array $params = NULL ) {
    return vsprintf( $txt, $params );
}

/**
 * Strip tags, optionally strip or encode special characters.
 * Useful to avoid XSS attacks
 *
 * @param string $txt
 * @return mixed
 *
 */
function _xss( $txt ) {
    return ( is_string( $txt ) ) ? filter_var( $txt, FILTER_SANITIZE_STRING ) : $txt;
}