by JScript December 12th 2014, 3:42 am
Here is the code that writes the the public IP of a member in the register and then when it is logged in on the forum the IP will be updated!
Note: This code works only when the Advanced profile is activated!
If they wish to work in the normal profile, let me know ok?
Create a new field in the profile as follows:
Then go on editing your profile and with the help of the browser console, locate the new field identifier that was created as illustrated below:
Use this code with placement in all pages:
- Code:
/*******************************************************************************************************
* Application: Location IP.
* Description: Shows the user's IP in the profile.
* Version: RC2 - Beta tester only!
* Made and Optimizations by JScript - 2014/12/10, 11
* Copyright (c) 2014 JScript <jscriptbrasil at live dot com>
* This work is free. You can redistribute it and/or modify it
* under the terms of the WTFPL, Version 2
********************************************************************************************************
-
Variables that can be changed by the user:
1- profile_field (change the value profile_field_XX_XX by your profile field!)
2- error_msg
3- tTimeOut
4- checkTime
Note: For those variables "tTimeout" and "checkTime" ->
- to avoid the "Request Limit" the lowest value should be 5 seconds and 10 seconds respectively!
*/
var IPLocation = {
profile_field: 'profile_field_XX_XX',
error_msg: "Warning!\n\nAn error occurred while requesting registration, wait 10 seconds and refresh the page to re-register!",
setLoop: 0,
lInterval: 10,
tTimeOut: 10000, // Min is 5 seconds to start check.
checkTime: 60000, // Min is 30 seconds of interval to check a new IP.
TID: 0
};
/**
* jQuery AJAX Cross Origin v1.3 (http://www.ajax-cross-origin.com)
* jQuery plugin to bypass Same-origin_policy using Google Apps Script.
* (c) 2014, Writen by Erez Ninio. site: www.dealhotelbook.com
**/
AJAX_CrossOrigin();
/**
* Waits for a user registers to record the initial IP!
**/
if (location.search == "?agreed=true\x26step=2") {
IPLocation.setLoop = setInterval(function() {
if (document.getElementById(IPLocation.profile_field) !== null) {
jQuery("#" + IPLocation.profile_field).closest("dl").hide();
clearInterval(IPLocation.setLoop);
$.ajax({
type: "GET",
url: "http://api.ipify.org",
crossOrigin: true,
dataType: "text",
success: function(data) {
jQuery("#" + IPLocation.profile_field).val(data);
},
error: function(data) {
jQuery("#" + IPLocation.profile_field).val('127.0.0.0');
// alert("Warning!\n\nAn error occurred while requesting registration, wait 10 seconds and refresh the page to re-register!");
}
});
};
}, IPLocation.lInterval);
} else {
jQuery(function() {
if (!_userdata.session_logged_in) {
return false;
}
/**
* If you are logged in, writes the current IP in the profile field...
**/
setTimeout(function() {
IPLocation.TID = jQuery('a[href*="tid="]').attr('href').split('tid=')[1].split('&')[0];
setInterval(function() {
$.ajax({
type: "GET",
url: "http://api.ipify.org",
crossOrigin: true,
dataType: "text",
success: function(data) {
jQuery.post("/ajax_profile.forum?jsoncallback=?", {
id: IPLocation.profile_field.substring(17, IPLocation.profile_field.length),
user: _userdata.user_id,
active: "1",
content: '[["' + IPLocation.profile_field + '", "' + data + '"]]',
tid: IPLocation.TID
}, function(data) {
console.log("The IP " + data + " was saved in profile!");
}, "json").fail(function() {
console.log("Error saving the IP to profile!");
});
},
error: function(data) {
console.log("Error getting public IP!");
}
});
}, IPLocation.checkTime);
}, IPLocation.tTimeOut);
});
}
/**
* If the member go on editing your profile and it is not a staff member, the IP field is removed!
**/
if (location.pathname.indexOf('/profile') == 0) {
IPLocation.setLoop = setInterval(function() {
if (document.getElementById(IPLocation.profile_field) !== null) {
if (_userdata.user_level == 0) {
jQuery("#" + IPLocation.profile_field).closest("dl").remove();
}
clearInterval(IPLocation.setLoop);
};
}, IPLocation.lInterval);
}
/**
* If the member is viewing your profile and ->
**/
if (location.pathname.indexOf('/u') == 0) {
IPLocation.setLoop = setInterval(function() {
if (document.getElementById('profile-advanced-right') !== null) {
if (!_userdata.session_logged_in) {
return false;
}
var forbid = jQuery('#field_id' + IPLocation.profile_field.substring(17, IPLocation.profile_field.length));
if (forbid.length) {
forbid.attr('id', 'forbid');
/**
* <- it is not a staff member, the IP field will be removed!
**/
if (_userdata.user_level == 0) {
forbid.remove();
}
}
/**
* Since we do not have access to the template of the advanced profile,
* then we have to modify the identifiers so we can intercept them in order
* to avoid that members can modify the IP field!
**/
var oTarget = jQuery('[id^=field_id]'),
iLen = oTarget.length,
index = 0;
for (; index < iLen; index++) {
var oThis = jQuery(oTarget[index]);
oThis.attr('id', 'JS_' + oThis.attr('id'));
IPLocation.profile_field
};
clearInterval(IPLocation.setLoop);
$('[id^=JS_field_id]').each(function() {
if ($(this).find('.field_editable').is('span, div')) {
$(this).hover(function() {
if ($(this).find('.field_editable.invisible').is('span, div')) {
$(this).find('.field_editable').prev().addClass('ajax-profil_hover').parent().addClass('ajax-profil_parent').append('<div class="ajax-profil_edit"><img src="http://2img.net/i/fa/invision/../edit.png" /></div>');
$(this).find('.ajax-profil_edit').attr({
alt: "{L_FIELD_EDIT_VALUE}",
title: "{L_FIELD_EDIT_VALUE}"
}).click(function() {
$(this).prev().prev().removeClass('ajax-profil_hover').addClass('invisible').next().removeClass('invisible').append('<img src="http://2img.net/i/fa/invision/../valid.png" class="ajax-profil_valid" />').find('input,select');
$(this).prev().find('.ajax-profil_valid').attr({
alt: "{L_VALIDATE}",
title: "{L_VALIDATE}"
}).click(function() {
var content = new Array();
$(this).parent().find('[name]').each(function() {
var type_special = $(this).is('input[type=radio],input[type=checkbox]');
if ((type_special && $(this).is(':checked')) || !type_special) {
content.push(new Array($(this).attr('name'), $(this).attr('value')));
}
});
var id_name = $(this).parents('[id^=JS_field_id]').attr('id');
var id = id_name.substring(11, id_name.length);
// console.log('id_name: ' + id_name + '\n' + 'id: ' + id);
$.post(
"/ajax_profile.forum?jsoncallback=?", {
id: id,
user: _userdata.user_id,
active: "1",
content: $.toJSON(content),
tid: jQuery('a[href*="tid="]').attr('href').split('tid=')[1].split('&')[0];
},
function(data) {
$.each(data, function(i, item) {
$('[id=JS_field_id' + i + ']').find('.field_uneditable').html(item).end().find('.ajax-profil_valid').remove().end().find('.field_editable').addClass('invisible').end().find('.field_uneditable').removeClass('invisible');
});
},
"json"
);
});
$(this).remove();
});
}
}, function() {
if ($(this).find('.field_editable.invisible').is('span, div')) {
$(this).find('.field_editable').prev().removeClass('ajax-profil_hover');
$(this).find('.ajax-profil_edit').remove();
}
});
}
});
};
}, 50);
}
/*
jQuery AJAX Cross Origin v1.3 (http://www.ajax-cross-origin.com)
jQuery plugin to bypass Same-origin_policy using Google Apps Script.
references:
http://en.wikipedia.org/wiki/Same-origin_policy
http://www.google.com/script/start/
(c) 2014, Writen by Erez Ninio. site: www.dealhotelbook.com
Licensed under the Creative Commons Attribution 3.0 Unported License.
For details, see http://creativecommons.org/licenses/by/3.0/.
*/
function AJAX_CrossOrigin() {
if (typeof proxyJsonp === 'undefined') {
var proxyJsonp = "https://script.google.com/macros/s/AKfycbwmqG55tt2d2FcT_WQ3WjCSKmtyFpkOcdprSITn45-4UgVJnzp9/exec";
jQuery.ajaxOrig = jQuery.ajax;
jQuery.ajax = function(a, b) {
function d(a) {
a = encodeURI(a).replace(/&/g, "%26");
return proxyJsonp + "?url=" + a + "&callback=?"
}
var c = "object" === typeof a ? a : b || {};
c.url = c.url || ("string" === typeof a ? a : "");
var c = jQuery.ajaxSetup({}, c),
e = function(a, c) {
var b = document.createElement("a");
b.href = a;
return c.crossOrigin && "http" == a.substr(0, 4).toLowerCase() && "localhost" != b.hostname && "127.0.0.1" != b.hostname && b.hostname != window.location.hostname
}(c.url, c);
c.proxy && 0 < c.proxy.length && (proxyJsonp = c.proxy, "object" === typeof a ?
a.crossDomain = !0 : "object" === typeof b && (b.crossDomain = !0));
e && ("object" === typeof a ? a.url && (a.url = d(a.url), a.charset && (a.url += "&charset=" + a.charset), a.dataType = "json") : "string" === typeof a && "object" === typeof b && (a = d(a), b.charset && (a += "&charset=" + b.charset), b.dataType = "json"));
return jQuery.ajaxOrig.apply(this, arguments)
};
jQuery.ajax.prototype = new jQuery.ajaxOrig;
jQuery.ajax.prototype.constructor = jQuery.ajax;
}
}
Note: Change this value
profile_field_XX_XX ] by the identifier that you found in step above!
Result:The code now includes:jQuery AJAX Cross Origin v1.3 (http://www.ajax-cross-origin.com)
jQuery plugin to bypass Same-origin_policy using Google Apps Script.
(c) 2014, Writen by Erez Ninio. site: www.dealhotelbook.comJS
Last edited by JScript on December 12th 2014, 3:51 am; edited 1 time in total