Last active
December 15, 2015 20:19
-
-
Save miniplay/5317335 to your computer and use it in GitHub Desktop.
API loading for external games. Miniplay Connect DEMO.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* NOTICE: For miniplay connect to work, your domain must be allowed by us, contact us to request access */ | |
/* 1. Parameters decoding ============================================================================================ */ | |
/* Only if your system configuration or language doesn't automatically decodes it */ | |
foreach ($_GET as $key => $value) $_GET[$key] = urldecode($value); | |
/* 2. Parameters validation (mp_*) =================================================================================== */ | |
/* External games doesn't receive neither parameters or signature, no validation needed */ | |
/* 3. Known received parameters from Miniplay Connect ================================================================ */ | |
$api_user_id = !empty($_GET['mp_api_user_id']) ? $_GET['mp_api_user_id'] : null; | |
$api_user_token = !empty($_GET['mp_api_user_token']) ? $_GET['mp_api_user_token'] : null; | |
$api_js_url = "http://api.minijuegos.com/lechuck/static/js/latest.js"; | |
$api_id = "## YOUR API ID ##"; /* Numeric, public ID of your API. DO NOT PUT YOUR PRIVATE API KEY HERE! */ | |
?> | |
<html> | |
<head> | |
<!-- ## YOUR OWN HEAD ## --> | |
<?php if ($api_js_url && $api_id):?> | |
<!-- Load MINIPLAY JS API! --> | |
<script id='LeChuckAPIjs' src="<?php echo $api_js_url;?>"></script> | |
<script type='text/javascript'> | |
lechuck = new LeChuckAPI({ | |
id: "<?php echo $api_id;?>", | |
user_id: "<?php echo $api_user_id?>", | |
user_token: "<?php echo $api_user_token?>", | |
locale: "es_ES" /* Locale to use for Miniplay connect, check API docs for supported locales */ | |
}); | |
</script> | |
<?php endif;?> | |
</head> | |
<body> | |
<h1>Miniplay JS API external operation: A very basic demo showing the initialization & the guest user handling</h1> | |
<hr/> | |
<div id='status-msg'></div> | |
<div id='game' style='display:none'> | |
<p> | |
## Your game content for registered users (or it can be a dynamically attached iframe!) ## | |
</p> | |
<p> | |
Logged-in user: <span id='game-user'></span> | |
</p> | |
</div> | |
<div id='game-guest' style='display:none'> | |
<p> | |
Sorry, only for registered users!. <a href='' onclick='lechuck.user.login();return false;'>Login or register!</a> | |
</p> | |
</div> | |
<!-- GUEST USER HANDLER --> | |
<script type='text/javascript'> | |
var status_msg = document.getElementById('status-msg'); | |
var game = document.getElementById('game'); | |
var game_guest = document.getElementById('game-guest'); | |
// Check if the API instance exists | |
if (lechuck instanceof Object) { | |
// Attach an onReady event listener to be dispatched once the api is ready! | |
// if the api is ready it will be automatically dispatched | |
lechuck.events.onApiReady(function() { | |
if(lechuck.user.isGuest()) { | |
game_guest.style.display="block"; // Show guest message | |
} else { | |
game.style.display="block"; // Show game! (or load it) | |
document.getElementById('game-user').innerHTML = "#" + lechuck.user.getId() + " " + | |
lechuck.user.getUid() + " <img src='"+lechuck.user.getAvatarMini()+"'>"; | |
} | |
status_msg.style.display="none"; // Hide status message | |
}); | |
// Initializing api... | |
status_msg.innerHTML = "Loading..."; | |
} else { | |
status_msg.innerHTML = "API not loaded :("; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment