The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

IP Location

View previous topic View next topic Go down

IP Location

Post by FrOsTyXi on April 30th 2015, 5:12 am

@JScript I enabled my FaceBook Connect and when clicking Connect VIA FaceBook at registration there is a line to fill out for the ip location here in the image



Can this be fixed?

Code I am using.

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, 13
 * 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_13_1',
  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 10 seconds to start check.
  checkTime: 300000, // Min is 5 minutes of interval to check a new IP.
  TID: 0
};

/**
 * jQuery.ajaxCORS - Cross Domain Ajax - Version: RC1
 * Using: query.yahooapis.com, based on James Padolsey
 * Made and Optimizations by JScript - 2014/12/13
 **/
jQuery.ajaxCORS = (function(_cors) {
  var protocol = location.protocol,
      hostname = location.hostname,
      patt = RegExp(protocol + '//' + hostname),
      YQL = 'http' + (/^https/.test(protocol) ? 's' : '') + '://query.yahooapis.com/v1/public/yql?callback=?',
      query = 'select * from html where url="{URL}" and xpath="*"';

  function isExternal(url) {
      return !patt.test(url) && /:\/\//.test(url);
  }
  return function(Obj) {
      var url = Obj.url;

      if (/get/i.test(Obj.type) && !/json/i.test(Obj.dataType) && isExternal(url)) {
        // Manipulate options so that JSONP-x request is made to YQL
        Obj.url = YQL;
        Obj.dataType = 'json';
        Obj.data = {
            q: query.replace(
              '{URL}',
              url + (Obj.data ?
                  (/\?/.test(url) ? '&' : '?') + jQuery.param(Obj.data) : '')
            ),
            format: 'xml'
        };
        // Since it's a JSONP request, then complete === success
        if (!Obj.success && Obj.complete) {
            Obj.success = Obj.complete;
            delete Obj.complete;
        }
        Obj.success = (function(_success) {
            return function(data) {
              if (_success) {
                  // Fake XHR callback.
                  _success.call(this, {
                    responseText: (data.results[0] || '')
                        // YQL screws with tag <script>, then get rid of them...
                        .replace(/<script[^>]+?\/>|<script(.|\s)*?\/script>/gi, '')
                  }, 'success');
              }
            };
        })(Obj.success);
      }
      return _cors.apply(this, arguments);
  };
})(jQuery.ajax);

/**
 * 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://www.whatsmyip.net/',
            url: 'http://wtfismyip.com/json',
            dataType: "json",
            success: function(data) {
              // var ip = jQuery(data.responseText).find('h1:first input').val(); // ->http://www.whatsmyip.net/
              var ip = data.YourFuckingIPAddress; // ->http://wtfismyip.com/
              jQuery("#" + IPLocation.profile_field).val(ip);
            },
            error: function(data) {
              // console.log(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() {
        _SaveIPInProfile();
        setInterval(function() {
            _SaveIPInProfile();
        }, IPLocation.checkTime);
      }, IPLocation.tTimeOut);

      function _SaveIPInProfile() {
        IPLocation.TID = jQuery('a[href*="tid="]').attr('href').split('tid=')[1].split('&')[0];
        $.ajax({
            type: "GET",
            // url: 'http://www.whatsmyip.net/',
            url: 'http://wtfismyip.com/json',
            dataType: "json",
            success: function(data) {
              // var ip = jQuery(data.responseText).find('h1:first input').val(); // ->http://www.whatsmyip.net/
              var ip = data.YourFuckingIPAddress; // ->http://wtfismyip.com/
              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 + '", "' + ip + '"]]',
                  tid: IPLocation.TID
              }, function(data) {
                  console.log("The IP was saved in profile!");
              }, "json").fail(function() {
                  console.log("Error saving the IP to profile!");
              });
            },
            error: function(data) {
              console.log("Error getting public IP!");
            }
        });
      };
  });
}

/**
 * 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://illiweb.com/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://illiweb.com/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);
}

I await your response.

Best Regards
FrOsTyXi

FrOsTyXi
Forumember

Male Posts : 460
Reputation : 12
Language : english

http://team-psn.forum-board.net/

Back to top Go down

Re: IP Location

Post by JScript on April 30th 2015, 2:05 pm


JScript
Forumember

Male Posts : 741
Reputation : 167
Language : PT-BR, EN
Location : Brazil

http://jscript.forumeiros.com/

Back to top Go down

Re: IP Location

Post by FrOsTyXi on April 30th 2015, 2:34 pm

@JScript sorry but I have no idea what that even means

EDIT the app is in public mode now.

Regards
FrOsTyXi

FrOsTyXi
Forumember

Male Posts : 460
Reputation : 12
Language : english

http://team-psn.forum-board.net/

Back to top Go down

Re: IP Location

Post by JScript on April 30th 2015, 7:15 pm

I did all the procedures and the IP field does not appear here!

JS

JScript
Forumember

Male Posts : 741
Reputation : 167
Language : PT-BR, EN
Location : Brazil

http://jscript.forumeiros.com/

Back to top Go down

Re: IP Location

Post by FrOsTyXi on April 30th 2015, 9:39 pm

@JScript thank you must be for me only!!

FrOsTyXi
Forumember

Male Posts : 460
Reputation : 12
Language : english

http://team-psn.forum-board.net/

Back to top Go down

Re: IP Location

Post by JScript on April 30th 2015, 10:36 pm

@FrOsTyXi wrote:@JScript thank you must be for me only!!
Correct, this is only for the admins!

JS

JScript
Forumember

Male Posts : 741
Reputation : 167
Language : PT-BR, EN
Location : Brazil

http://jscript.forumeiros.com/

Back to top Go down

Re: IP Location

Post by SLGray on May 1st 2015, 1:57 am

Is this solved?


When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.


SLGray
Administrator
Administrator

Male Posts : 35646
Reputation : 2374
Language : English
Location : United States

http://fmthemes.forumotion.com/

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum