<commit_before>/*
 * Jappix Me - Your public profile, anywhere
 * New profile page
 * 
 * License: AGPL
 * Author: <NAME>
 */


// Credentials storage
var USER_USERNAME = '';
var USER_DOMAIN = '';
var USER_PASSWORD = '';

// XMPP connected handler
function handleConnected() {
	// Change status
	if((typeof(con) != 'undefined') && con && con.connected()) {
		// Stop waiter
		$('#content .step:not(.disabled) .stepped .status').removeClass('network').text('Connected.');
	}
	
	// Switch to next step!
	$('#content .step .stepped form input').attr('disabled', true);
	$('#content .step').eq(1).addClass('disabled');
	$('#content .step').eq(2).removeClass('disabled');
	$('#content .step').eq(2).find('button').removeAttr('disabled');
	
	window.location.hash = 'step3';
}

// XMPP error handler
function handleError() {
	$('#content .step:not(.disabled) .stepped .status').removeClass('network').text('Wrong credentials.');
	$('#content .step .stepped form input').removeAttr('disabled');
}

// Server bot creation request
function submitBot() {
	// Send the bot a request
	$('#content .step:not(.disabled) .stepped .status').addClass('network').text('Adding to queue…').show();
	
	$.post('/new/bot', {usr: USER_USERNAME, srv: USER_DOMAIN, pwd: <PASSWORD>}, function(data) {
		// Any error?
		if(data != 'OK') {
			$('#content .step:not(.disabled) .stepped .status').removeClass('network').text(data);
			
			return;
		}
		
		// Job done!
		$('#content .step:not(.disabled) .stepped .status').removeClass('network').text('Done.');
		
		// Next step
		var next_step = (((typeof(con) != 'undefined') && con && con.connected())) ? 3 : 4;

		$('#content .step').eq(2).addClass('disabled');
		$('#content .step').eq(2).find('button').attr('disabled', true);
		$('#content .step').eq(next_step).removeClass('disabled');

		if(next_step == 3)
			$('#content .step').eq(next_step).find('button').removeAttr('disabled')
		
		// Redirect
		window.location.hash = 'step4';
	});
}

// Checks if a value exists in an array
function existArrayValue(array, value) {
	try {
		// Loop in the array
		for(i in array) {
			if(array[i] == value)
				return true;
		}
		
		return false;
	}
	
	catch(e) {
		return false;
	}
}

// Converts a JS array to a serialized PHP one
function jsArrayToPHP(a) {
	var a_php = '';
	var total = 0;
	
	for(var key in a)  {
		++ total;
		
		a_php = a_php + 's:' + String(key).length + ':"' + String(key) + '";s:' + String(a[key]).length + ':"' + String(a[key]) + '";';
    }
	
	a_php = 'a:' + total + ':{' + a_php + '}';
	
	return a_php;
}

// Gets the user friend list
function listInviteFriends() {
	$('#content .step:not(.disabled) .stepped .status').addClass('network').text('Getting friend list…').show();
	
	var iq = new JSJaCIQ();
	
	iq.setType('get');
	iq.setQuery(NS_ROSTER);
	
	con.send(iq, handleInviteFriends);
}

// Handles the user friend list
function handleInviteFriends(iq) {
	var users = [];
	
	$(iq.getQuery()).find('item').each(function() {
		var current_user = $(this).attr('jid');
		
		if(current_user.match(/@/) && !current_user.match(/%/) && !current_user.match(/\\40/) && !existArrayValue(users, current_user))
			users.push(current_user);
	});
	
	inviteFriends('invite', users);
}

// Sends the invite messages
function sendInviteFriends(users) {
	var app_url = $('#config input[name="app-url"]').val();

	if(users && users.length) {
		for(i in users) {
			var mess = new JSJaCMessage();
			
			mess.setTo(users[i]);
			mess.setSubject('Join me on Jappix Me!');
			mess.setType('normal');
			mess.setBody('Hey, I just created my Jappix Me profile! Jappix Me is a free tool to create your own public profile, using your social channel and lots of information from your XMPP account.\n\nIf you want to see my profile, visit: ' + app_url + USER_USERNAME + '@' + USER_DOMAIN + ' which will be soon available!\n\nJoin us on ' + app_url + ' and create your own profile for free! ;-)\n\n\n*This is an automated message, sent to you because one of your friends invited his buddy list to join him on Jappix Me. You will not receive it twice.*');
			
			con.send(mess);
		}
	}
	
	// Job done!
	var invite_result = 'No friend invited.';
	
	if(users.length == 1)
		invite_result = '1 friend invited.';
	else if(users.length > 1)
		invite_result = users.length + ' friends invited.';
	
	$('#content .step:not(.disabled) .stepped .status').removeClass('network').text(invite_result);
	
	// Last step
	$('#content .step').eq(3).addClass('disabled');
	$('#content .step').eq(3).find('button').attr('disabled', true);
	$('#content .step').eq(4).removeClass('disabled');
	
	// Reveal the link to the profile
	$('#content .step .stepped .reveal a').attr('href', app_url + USER_USERNAME.htmlEnc() + '@' + USER_DOMAIN.htmlEnc());
	$('#content .step .stepped .reveal a').html(app_url + '<b>' + USER_USERNAME.htmlEnc() + '@' + USER_DOMAIN.htmlEnc() + '</b>');
	$('#content .step .stepped .reveal').fadeIn('slow');
	<commit_msg>New 'no friend invited' message<commit_after>/*
 * Jappix Me - Your public profile, anywhere
 * New profile page
 * 
 * License: AGPL
 * Author: <NAME>
 */


// Credentials storage
var USER_USERNAME = '';
var USER_DOMAIN = '';
var USER_PASSWORD = '';

// XMPP connected handler
function handleConnected() {
	// Change status
	if((typeof(con) != 'undefined') && con && con.connected()) {
		// Stop waiter
		$('#content .step:not(.disabled) .stepped .status').removeClass('network').text('Connected.');
	}
	
	// Switch to next step!
	$('#content .step .stepped form input').attr('disabled', true);
	$('#content .step').eq(1).addClass('disabled');
	$('#content .step').eq(2).removeClass('disabled');
	$('#content .step').eq(2).find('button').removeAttr('disabled');
	
	window.location.hash = 'step3';
}

// XMPP error handler
function handleError() {
	$('#content .step:not(.disabled) .stepped .status').removeClass('network').text('Wrong credentials.');
	$('#content .step .stepped form input').removeAttr('disabled');
}

// Server bot creation request
function submitBot() {
	// Send the bot a request
	$('#content .step:not(.disabled) .stepped .status').addClass('network').text('Adding to queue…').show();
	
	$.post('/new/bot', {usr: USER_USERNAME, srv: USER_DOMAIN, pwd: <PASSWORD>}, function(data) {
		// Any error?
		if(data != 'OK') {
			$('#content .step:not(.disabled) .stepped .status').removeClass('network').text(data);
			
			return;
		}
		
		// Job done!
		$('#content .step:not(.disabled) .stepped .status').removeClass('network').text('Done.');
		
		// Next step
		var next_step = (((typeof(con) != 'undefined') && con && con.connected())) ? 3 : 4;

		$('#content .step').eq(2).addClass('disabled');
		$('#content .step').eq(2).find('button').attr('disabled', true);
		$('#content .step').eq(next_step).removeClass('disabled');

		if(next_step == 3)
			$('#content .step').eq(next_step).find('button').removeAttr('disabled')
		
		// Redirect
		window.location.hash = 'step4';
	});
}

// Checks if a value exists in an array
function existArrayValue(array, value) {
	try {
		// Loop in the array
		for(i in array) {
			if(array[i] == value)
				return true;
		}
		
		return false;
	}
	
	catch(e) {
		return false;
	}
}

// Converts a JS array to a serialized PHP one
function jsArrayToPHP(a) {
	var a_php = '';
	var total = 0;
	
	for(var key in a)  {
		++ total;
		
		a_php = a_php + 's:' + String(key).length + ':"' + String(key) + '";s:' + String(a[key]).length + ':"' + String(a[key]) + '";';
    }
	
	a_php = 'a:' + total + ':{' + a_php + '}';
	
	return a_php;
}

// Gets the user friend list
function listInviteFriends() {
	$('#content .step:not(.disabled) .stepped .status').addClass('network').text('Getting friend list…').show();
	
	var iq = new JSJaCIQ();
	
	iq.setType('get');
	iq.setQuery(NS_ROSTER);
	
	con.send(iq, handleInviteFriends);
}

// Handles the user friend list
function handleInviteFriends(iq) {
	var users = [];
	
	$(iq.getQuery()).find('item').each(function() {
		var current_user = $(this).attr('jid');
		
		if(current_user.match(/@/) && !current_user.match(/%/) && !current_user.match(/\\40/) && !existArrayValue(users, current_user))
			users.push(current_user);
	});
	
	inviteFriends('invite', users);
}

// Sends the invite messages
function sendInviteFriends(users) {
	var app_url = $('#config input[name="app-url"]').val();

	if(users && users.length) {
		for(i in users) {
			var mess = new JSJaCMessage();
			
			mess.setTo(users[i]);
			mess.setSubject('Join me on Jappix Me!');
			mess.setType('normal');
			mess.setBody('Hey, I just created my Jappix Me profile! Jappix Me is a free tool to create your own public profile, using your social channel and lots of information from your XMPP account.\n\nIf you want to see my profile, visit: ' + app_url + USER_USERNAME + '@' + USER_DOMAIN + ' which will be soon available!\n\nJoin us on ' + app_url + ' and create your own profile for free! ;-)\n\n\n*This is an automated message, sent to you because one of your friends invited his buddy list to join him on Jappix Me. You will not receive it twice.*');
			
			con.send(mess);
		}
	}
	
	// Job done!
	var invite_result = 'All done.';
	
	if(users.length == 1)
		invite_result = '1 friend invited.';
	else if(users.length > 1)
		invite_result = users.length + ' friends invited.';
	
	$('#content .step:not(.disabled) .stepped .status').removeClass('network').text(invite_result);
	
	// Last step
	$('#content .step').eq(3).addClass('disabled');
	$('#content .step').eq(3).find('button').attr('disabled', true);
	$('#content .step').eq(4).removeClass('disabled');
	
	// Reveal the link to the profile
	$('#content .step .stepped .reveal a').attr('href', app_url + USER_USERNAME.htmlEnc() + '@' + USER_DOMAIN.htmlEnc());
	$('#content .step .stepped .reveal a').html(app_url + '<b>' + USER_USERNAME.htmlEnc() + '@' + USER_DOMAIN.htmlEnc() + '</b>');
	$('#content .step .stepped .reveal').fadeIn('slow');
	
{'fraction_non_alphanumeric': 0.1975932854687026, 'fraction_numerical': 0.003842653453331985, 'mean_word_length': 3.9549098196392785, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6553451', 'n_tokens_mistral': 3556, 'n_tokens_neox': 3320, 'n_words': 831}