<commit_before><?php

$errorMessage = "";

require LIBDIR . "/LdapWrapper.php";

$failed_search = FALSE;

if (isset($_REQUEST['username']) && $username = $_REQUEST['username']) {
  $ldapWrapper = new LdapWrapper();
  $person = $ldapWrapper->lookupUser($username);
  if ($person) {
    require "$page->branch/detail.html";
  } else {
    $errorMessage = $ldapWrapper->getError();
    require "$page->branch/detail.html";
  }

} elseif (isset($_REQUEST['filter'])
    && $searchTerms = trim($_REQUEST['filter'])) {

  $ldapWrapper = new LdapWrapper();
  if ($ldapWrapper->buildQuery($searchTerms)
      && $people = $ldapWrapper->doQuery()) {

    $total = count($people);
    switch ($total) {
      case 0:
        $failed_search = TRUE;
        require "$page->branch/index.html";
        break;
      case 1:
        $person = $people[0];
        require "$page->branch/detail.html";
        break;
      default:
        $content = new ResultsContent("items", "people", $page);
        require "$page->branch/results.html";
        break;
    }

  } else {
    $errorMessage = $ldapWrapper->getError();
    require "$page->branch/index.html";
  }

} else {

  $page->cache();
  require "$page->branch/index.html";
}

$page->output();

function detail_url($person)
{
    return $_SERVER['SCRIPT_NAME'] . '?username=' . urlencode($person->getId()) . '&filter=' . urlencode($_REQUEST['filter']);
}

function phoneHREF($number)
{
    // check if number already starts with "+1"
    if(strpos($number, "+1") != 0) {
        $number = "+1" . $number;
    }
    return 'tel:' . str_replace('-', '', $number);
}

function mailHREF($email)
{
    return "mailto:$email";
}

function has_phone($person)
{
  return ($person->getField('homephone')
    || $person->getField('facsimiletelephonenumber')
    || $person->getField('telephonenumber'));
}

function officeURL($address) {
    // Only send the next-to-last line of the address to the map search.
    $addressLines = explode("$", $address);
    $lineCount = count($addressLines);
    if ($lineCount > 1) {
	$linkAddress = $addressLines[$lineCount - 2];
    } else {
        $linkAddress = $address;
    }

    return mapURL($linkAddress);
}

?>
<commit_msg>Strip slashes added by PHP on the search term parameter. Check doQuery() against FALSE with !== because empty arrays evaluate to FALSE.<commit_after><?php

$errorMessage = "";

require LIBDIR . "/LdapWrapper.php";

$failed_search = FALSE;

if (isset($_REQUEST['username']) && $username = $_REQUEST['username']) {
  $ldapWrapper = new LdapWrapper();
  $person = $ldapWrapper->lookupUser($username);
  if ($person) {
    require "$page->branch/detail.html";
  } else {
    $errorMessage = $ldapWrapper->getError();
    require "$page->branch/detail.html";
  }

} elseif (isset($_REQUEST['filter'])
    && $searchTerms = stripslashes(trim($_REQUEST['filter']))) {

  $ldapWrapper = new LdapWrapper();
  if ($ldapWrapper->buildQuery($searchTerms)
      && ($people = $ldapWrapper->doQuery()) !== FALSE) {

    $total = count($people);
    switch ($total) {
      case 0:
        $failed_search = TRUE;
        require "$page->branch/index.html";
        break;
      case 1:
        $person = $people[0];
        require "$page->branch/detail.html";
        break;
      default:
        $content = new ResultsContent("items", "people", $page);
        require "$page->branch/results.html";
        break;
    }

  } else {
    $errorMessage = $ldapWrapper->getError();
    require "$page->branch/index.html";
  }

} else {

  $page->cache();
  require "$page->branch/index.html";
}

$page->output();

function detail_url($person)
{
    return $_SERVER['SCRIPT_NAME'] . '?username=' . urlencode($person->getId()) . '&filter=' . urlencode($_REQUEST['filter']);
}

function phoneHREF($number)
{
    // check if number already starts with "+1"
    if(strpos($number, "+1") != 0) {
        $number = "+1" . $number;
    }
    return 'tel:' . str_replace('-', '', $number);
}

function mailHREF($email)
{
    return "mailto:$email";
}

function has_phone($person)
{
  return ($person->getField('homephone')
    || $person->getField('facsimiletelephonenumber')
    || $person->getField('telephonenumber'));
}

function officeURL($address) {
    // Only send the next-to-last line of the address to the map search.
    $addressLines = explode("$", $address);
    $lineCount = count($addressLines);
    if ($lineCount > 1) {
	$linkAddress = $addressLines[$lineCount - 2];
    } else {
        $linkAddress = $address;
    }

    return mapURL($linkAddress);
}

?>

{'fraction_non_alphanumeric': 0.18305531167690958, 'fraction_numerical': 0.003950834064969272, 'mean_word_length': 3.34, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '1972021', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1448, 'n_words': 301}