<commit_before><?php

require 'Slim/Slim.php';
require 'functions/functions.php';
date_default_timezone_set("America/Fortaleza");

\Slim\Slim::registerAutoloader();

$app = new \Slim\Slim();

session_start();

$mongo = "";  
if($_SERVER['SERVER_NAME'] == "hubconsultants.herokuapp.com"){
    $mongo = new Mongo('mongodb://marley:<EMAIL>:10004/consultantsDB');
}else if($_SERVER['SERVER_NAME'] == "localhost"){
    $mongo = new Mongo('mongodb://localhost:27017');
}else{
    echo 'out of the headquarters o.O';
}

$db = $mongo->consultantsDB;

$app->get('/', function () use ($app) {
    $app->render('cdc.html');
});

/*function jsonpWrap($jsonp) {
  $app = Slim::getInstance();

  if (($jsonCallback = $app->request()->get('jsoncallback')) !== null) {
    $jsonp = sprintf("%s(%s);", $jsonCallback, $jsonp);
    $app->response()->header('Content-type', 'application/javascript');
  }
  return $jsonp;
}*/

$authenticate = function ($app) {
    return function () use ($app) {
        if (!isset($_SESSION['user_id'])) {
            $app->flash('error', 'É necessário estar logado para acessar o dashboard!');
            $app->redirect(get_root_url().'admin');
        }
    };
};


$app->get('/(:obj)', $authenticate($app), function ($obj) use ($app,$db) {
      $consultants = $db->consultants;
      $cons['cons'] = $consultants->findOne(array('_id' => new MongoId($obj)));
      if($cons){
          $app->render('cdc.html',$cons);
      }else{
        //$app->render('404.html');
      } 
})->conditions(['obj' => '[0-9a-z]{24}']);


$app->get('/consultants', function () use ($app,$db) {
    $consultants = $db->consultants;
    $cons = $consultants->find();

    $total = $cons->count(true);
    echo ($total) ." registros encontrados.<p>";
    //$mongo->close();
    foreach ($cons as $key => $obj) {
        if(is_array($obj)){
            echo $key.'</br>';
            printer($obj);
        }else{
            echo $key.'   '.$obj.'</br>';
        }
    }
    $mongo->close();
});

/*$app->get('/consultants/(:id)', $authenticate($app), function($id) use ($app){ 
      if($app->request->isAjax()){
        //echo $app->request->isAjax();<commit_msg>array no conditions da rota com regex<commit_after><?php

require 'Slim/Slim.php';
require 'functions/functions.php';
date_default_timezone_set("America/Fortaleza");

\Slim\Slim::registerAutoloader();

$app = new \Slim\Slim();

session_start();

$mongo = "";  
if($_SERVER['SERVER_NAME'] == "hubconsultants.herokuapp.com"){
    $mongo = new Mongo('mongodb://marley:<EMAIL>:10004/consultantsDB');
}else if($_SERVER['SERVER_NAME'] == "localhost"){
    $mongo = new Mongo('mongodb://localhost:27017');
}else{
    echo 'out of the headquarters o.O';
}

$db = $mongo->consultantsDB;

$app->get('/', function () use ($app) {
    $app->render('cdc.html');
});

/*function jsonpWrap($jsonp) {
  $app = Slim::getInstance();

  if (($jsonCallback = $app->request()->get('jsoncallback')) !== null) {
    $jsonp = sprintf("%s(%s);", $jsonCallback, $jsonp);
    $app->response()->header('Content-type', 'application/javascript');
  }
  return $jsonp;
}*/

$authenticate = function ($app) {
    return function () use ($app) {
        if (!isset($_SESSION['user_id'])) {
            $app->flash('error', 'É necessário estar logado para acessar o dashboard!');
            $app->redirect(get_root_url().'admin');
        }
    };
};


$app->get('/(:obj)', $authenticate($app), function ($obj) use ($app,$db) {
      $consultants = $db->consultants;
      $cons['cons'] = $consultants->findOne(array('_id' => new MongoId($obj)));
      if($cons){
          $app->render('cdc.html',$cons);
      }else{
        //$app->render('404.html');
      } 
})->conditions(array('obj' => '[0-9a-z]{24}'));


$app->get('/consultants', function () use ($app,$db) {
    $consultants = $db->consultants;
    $cons = $consultants->find();

    $total = $cons->count(true);
    echo ($total) ." registros encontrados.<p>";
    //$mongo->close();
    foreach ($cons as $key => $obj) {
        if(is_array($obj)){
            echo $key.'</br>';
            printer($obj);
        }else{
            echo $key.'   '.$obj.'</br>';
        }
    }
    $mongo->close();
});

/*$app->get('/consultants/(:id)', $authenticate($app), function($id) use ($app){ 
      if($app->request->isAjax()){
        //echo $app->request->isAjax();
{'fraction_non_alphanumeric': 0.2365097588978186, 'fraction_numerical': 0.007807118254879449, 'mean_word_length': 3.325719960278054, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 69, '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': '3155342', 'n_tokens_mistral': 1558, 'n_tokens_neox': 1511, 'n_words': 259}