Instantly share code, notes, and snippets.
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save itsbalamurali/10105516 to your computer and use it in GitHub Desktop.
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
<!--my footer.php--> | |
<link rel="shortcut icon" href="candy/res/img/favicon.png" type="image/gif" /> | |
<link rel="stylesheet" type="text/css" href="candy/res/candy.css" /> | |
<script type="text/javascript" src="candy/libs/libs.min.js"></script> | |
<script type="text/javascript" src="candy/candy.min.js"></script> | |
<meta charset="utf-8"> | |
<?php | |
require_once( "models/config.php"); | |
if (!securePage($_SERVER[ 'PHP_SELF'])){die();} | |
require_once( "models/header.php"); | |
if(isUserLoggedIn()) { "()"; } | |
else { header( "Location: login.php"); die(); } | |
?> | |
footer> | |
<br> | |
<button id='vanish'>cHaT bOX!</button> | |
<br> | |
<div id="footer2" style=display:none height:30 > | |
<!-- EVERYTHING IN HERE GETS HIDDEN ON CLICK --> | |
<div id="candy"> | |
this is the div for candy-chat- Calling the javascript below populates this area on successfull connections. | |
</div> | |
</div> | |
<!-- END OF HIDE FOOTER --> | |
</footer> | |
<?php include_once ("candy.php");?> //first call the candy.php | |
<script type="text/javascript"> //then call the show/hide script | |
var button = document.getElementById('vanish'); | |
button.onclick = function () { | |
var div = document.getElementById('footer2'); | |
if (div.style.display !== "none") { | |
div.style.display = "none"; | |
div.style.height = 30;} | |
else { | |
div.style.display = "block"; | |
div.style.height = 300;}}; | |
</script> | |
my Candy.php | |
///////////////////////////////////////////////////////////////////////////////////////////////////////// | |
<link rel="stylesheet" type="text/css" href="models/site-templates/uitabs.css"> | |
<?php | |
require_once("models/config.php"); | |
if (!securePage($_SERVER['PHP_SELF'])){die();} | |
require_once("models/header.php"); | |
if(isUserLoggedIn()) { "()"; } | |
else { header("Location: login.php"); die(); } | |
$usernm = $loggedInUser->username; | |
$user = $loggedInUser->user_id; | |
//the table uc_stats contains the data ill use to find out a Chatroom Name to log in to | |
$uc_info = Get_id_table($user,'uc_stats'); | |
$cu_Empire = $uc_info["Empire"]; | |
// here we set up the variables required to auto-login users to Openfire | |
$username = $usernm."@localhost"; | |
$room1 = $cu_Empire."@conference.localhost"; | |
$room2 = "[email protected]"; | |
// You need to set up a way to create a password here. I tried $loggedInUser->hash_pw but that was to big. | |
$password = 'create your own password schema'; | |
echo " | |
<!doctype html> | |
<html> | |
<head> | |
<script type='text/javascript' src='candy/libs/libs.min.js'></script> | |
<script type='text/javascript' src='candy/candy.min.js'></script> | |
<script src='http://code.jquery.com/jquery-1.8.2.js'></script> | |
<script src='http://code.jquery.com/ui/1.9.1/jquery-ui.js'></script> | |
</head> | |
<body> | |
</body> | |
</html>"; | |
echo " | |
<script type='text/javascript'> | |
$(document).ready(function () { | |
Candy.init('http-bind/', { | |
core: { | |
debug: false, | |
autojoin: ['"; echo $room1 ; echo "', '"; echo $room2;echo"'] }, | |
view: { language: 'en' } }); | |
Candy.Core.connect('"; echo $username;echo "', '"; echo $password; echo"'); }); | |
</script>"; | |
?> | |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
my AddChatAccount.php | |
<?php | |
require_once("models/config.php"); | |
if (!securePage($_SERVER['PHP_SELF'])){die();} | |
require_once("models/header.php"); | |
if(isUserLoggedIn()) { "()"; } | |
else { header("Location: login.php"); die(); } | |
$name = $loggedInUser->username; | |
$user = $loggedInUser->user_id; | |
$password = 'create your own password schema'; //This should match the shcema you are using in Candy.php | |
//I load this page every time a user visits the main page so i check if some things are already set. | |
//This could be done in the create account function/page but i have not gotten that far yet. | |
//With this code i know if i have already ran this code by checking database values. | |
//If any values are there i skip running this as everything is alreayd set up. | |
if (Check_uc_Stats_Status($user)!="empty") //calls a function to check the db for values. returns empty if not setup | |
{ | |
echo""; | |
} | |
else | |
{ | |
echo(" the user has not set any uc_stats"); | |
/////// Populate Database Tables uc_stats | |
$sql="INSERT INTO uc_stats (id, Health, Energy, MaxEnergy,Shield,Race,Empire,RC,TC,SC,Current_Ship) | |
VALUES ($loggedInUser->user_id,100, 100, 100,100,'Human','Noob_Empire',0,0,0,'The Leo')"; | |
db_exe($sql); //my nfunction for executing database strings. | |
/////// Set up chat account - Username and Password is username and something you create. | |
// again all 3 pages need to have the same password schema. You could hardcode | |
// a single password for everyone as the users prob will never know it exists | |
// but i find a unique password makes me feel safer about mischevious users | |
// posing as other users. | |
$uc_info = Get_id_table($user,'uc_stats'); //grabbing the array of logged in user | |
$cu_Empire = $uc_info["Empire"]; //getting the chatroom name | |
// here we create the string we need to pass as a url to Openfire to create a user. | |
$url = 'http://127.0.0.1:9090/plugins/userService/userservice?type=add&secret=123abcD&username=' | |
.$name.'&password='.$password.'&name='.$user.'&groups=World,'.$cu_Empire; | |
$fopen = fopen($url, 'r'); | |
$data = fread($fopen, 1024); | |
fclose($fopen); | |
return $data;} // u can return data here about errors but my setup doesnt require i do anything with this info | |
// it returns "OK" if everything went ok or it returns a few diff errors depending on instance | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment