<commit_before>/*jslint node: true, maxlen: 500, maxerr: 50, indent: 2 */
'use strict';

/**
 * phpfreechat's init functions
 */
var phpFreeChat = (function (pfc, $, window, undefined) {

  /**
   * phpFreeChat entry point
   */
  pfc.init = function (plugin) {
    // copy jquery attributes needed by phpfreechat
    pfc.element = plugin.element;
    pfc.options = plugin.options;

    // users and channels data (cache)
    pfc.users    = {}; // users of the chat (uid -> userdata)
    pfc.channels = {}; // channels of the chat (cid -> chandata)

    // session data
    pfc.uid = null; // current connected user
    pfc.cid = null; // current active channel

    // check backlink presence
    if (pfc.options.check_backlink && !pfc.hasBacklink()) {
      return;
    }
    
    // load the interface
    pfc.loadHTML();
    pfc.loadResponsiveBehavior();
    
    // run quick tests
    pfc.checkServerConfig(pfc.startChatLogic);
  }

  /**
   * Run few tests to be sure the server is ready to receive requests
   */
  pfc.checkServerConfig = function (next) {
  
    if (pfc.options.check_server_config) {
      pfc.checkServerConfigPHP(function () {
        pfc.checkServerConfigRewrite(next);
      });
    } else {
      next();
    }
    
  };

  /**
   * Test the server php config file
   */
  pfc.checkServerConfigPHP = function (next) {
    $.ajax({
      type: 'GET',
      url:  pfc.options.serverCheckUrl
    }).done(function (errors) {
      if (errors && errors.length > 0) {
        pfc.showErrorsPopup(errors);
      } else {
        next();
      }
    }).error(function () {
      pfc.showErrorsPopup([ 'Unknown error: check.php cannot be found' ]);
    });
  };
      
  /**
   * Test the rewrite rules are enabled on the server
   */
  pfc.checkServerConfigRewrite = function (next) {
    var err_rewrite_msg = 'mod_rewrite must be enabled server side and correctly configured. "RewriteBase" could be adjusted in server/.htaccess file.';
    $.ajax({
      type: 'GET',
      url:  pfc.options.serverUrl + '/status'
    }).done(function (status) {
      if (!status || !status.running) {
        pfc.showErrorsPopup([ err_rewrite_msg ]);
      } else {
        next();
      }
    }).error(function () {
      pfc.showErrorsPopup([ err_rewrite_msg ]);
    });<commit_msg>display content of check.php if json is not returned<commit_after>/*jslint node: true, maxlen: 500, maxerr: 50, indent: 2 */
'use strict';

/**
 * phpfreechat's init functions
 */
var phpFreeChat = (function (pfc, $, window, undefined) {

  /**
   * phpFreeChat entry point
   */
  pfc.init = function (plugin) {
    // copy jquery attributes needed by phpfreechat
    pfc.element = plugin.element;
    pfc.options = plugin.options;

    // users and channels data (cache)
    pfc.users    = {}; // users of the chat (uid -> userdata)
    pfc.channels = {}; // channels of the chat (cid -> chandata)

    // session data
    pfc.uid = null; // current connected user
    pfc.cid = null; // current active channel

    // check backlink presence
    if (pfc.options.check_backlink && !pfc.hasBacklink()) {
      return;
    }
    
    // load the interface
    pfc.loadHTML();
    pfc.loadResponsiveBehavior();
    
    // run quick tests
    pfc.checkServerConfig(pfc.startChatLogic);
  }

  /**
   * Run few tests to be sure the server is ready to receive requests
   */
  pfc.checkServerConfig = function (next) {
  
    if (pfc.options.check_server_config) {
      pfc.checkServerConfigPHP(function () {
        pfc.checkServerConfigRewrite(next);
      });
    } else {
      next();
    }
    
  };

  /**
   * Test the server php config file
   */
  pfc.checkServerConfigPHP = function (next) {
    $.ajax({
      type: 'GET',
      url:  pfc.options.serverCheckUrl
    }).done(function (errors) {
      // parse json
      try {
        if (errors instanceof String) {
          errors = JSON.parse(errors);
        }
      } catch (err) {
        errors = [ errors ];
      }
      // show errors if one
      if (errors && errors.length > 0) {
        pfc.showErrorsPopup(errors);
      } else {
        next();
      }
    }).error(function () {
      pfc.showErrorsPopup([ 'Unknown error: check.php cannot be found' ]);
    });
  };
      
  /**
   * Test the rewrite rules are enabled on the server
   */
  pfc.checkServerConfigRewrite = function (next) {
    var err_rewrite_msg = 'mod_rewrite must be enabled server side and correctly configured. "RewriteBase" could be adjusted in server/.htaccess file.';
    $.ajax({
      type: 'GET',
      url:  pfc.options.serverUrl + '/status'
    }).done(function (status) {
      if (!status || !status.running) {
        pfc.showErrorsPopup([ err_rewrite_msg ]);
      } else {
        next();
      }
    }).error(function () {
      pfc.showErrorsPopup([ err_rewrite_msg ]);
    });
{'fraction_non_alphanumeric': 0.13231341740748398, 'fraction_numerical': 0.002894356005788712, 'mean_word_length': 2.282225237449118, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5980643', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1508, 'n_words': 395}