<?php $reports_found = array(); if (is_numeric($_GET['id'])) { $report = new PATIncident(array('id' => $_GET['id'])); $report->setReader($me); if ($report->isVisible()) { if ($report->reportee_id) { // Get information about the reportee. $url = "/{$report->reportee_id}?fields=name,picture.type(square),link"; $reportee = getFacebookUserInfoFromApi($FB, $url); if ($reportee['picture']['data']['url']) { $reportee['picture'] = $reportee['picture']['data']['url']; } // Automatically search for any other reports against this user ID. $result = pg_query_params($db->getHandle(), 'SELECT * FROM incidents WHERE reportee_id=$1 AND id <> $2 ORDER BY report_date DESC;', array($report->reportee_id, $report->id)); while ($row = pg_fetch_assoc($result)) { $r = new PATIncident($row); $r->setReader($me); if ($r->isVisible()) { $reports_found[] = $r; } } } } } else { if (isset($_GET['mine'])) { $result = pg_query_params($db->getHandle(), 'SELECT * FROM incidents WHERE reporter_id=$1 ORDER BY report_date DESC', array($user_id)); if (pg_num_rows($result)) { while ($row = pg_fetch_assoc($result)) { $r = new PATIncident($row);
} // We're in the middle of paging, and just asked for another page. $p = parse_url($_REQUEST['next_page']); $url = "{$p['path']}?{$p['query']}"; $x = processFacebookSearchResults($FB->api(urldecode($url))); $search_results = $x['search_results']; $next_search_results_url = $x['next_page']; } if (is_numeric($reportee_id)) { $reportee_data = getFacebookUserInfoFromApi($FB, $reportee_id); } else { if (empty($reportee_id) && !empty($_REQUEST['reportee_name']) && empty($_REQUEST['submit_clarification'])) { // If the "name" is numeric or doesn't have spaces, assume it's an ID or an // unique username, so do that search first. if (is_numeric($_REQUEST['reportee_name']) || false === strpos($_REQUEST['reportee_name'], ' ')) { $search_results[] = getFacebookUserInfoFromApi($FB, $_REQUEST['reportee_name']); } // But then always do a Graph Search, too. $x = processFacebookSearchResults($FB->api('/search?type=user&q=' . urlencode($_REQUEST['reportee_name']) . '&fields=id,name,picture.type(square),gender,bio,birthday,link')); $search_results = array_merge($search_results, $x['search_results']); $next_search_results_url = $x['next_page']; if (empty($search_results) && false !== strpos($_REQUEST['reportee_name'], ' ')) { $x = guessFacebookUsername($_REQUEST['reportee_name']); if ($x) { $search_results[] = $x; } } } } // Offer a tab separated values download of the user's own reports. if ('export' === $_GET['action']) {
/** * Given a string, mutates it in various ways to guess whether or not it's also * a Facebook username. For instance, given "Joe Cassidy Smith", this will try * * 1. "JoeCassidySmith" * 2. "JCassidySmith" * 3. "JCSmith" * 4. "JCS" * * @param string $str The string to start guessing with. * @return mixed A Facebook response if a match is eventually found, false otherwise. */ function guessFacebookUsername($str, $attempts = 0) { global $FB; $name_parts = explode(' ', $str); if ($attempts > count($name_parts)) { return false; // Give up trying to guess. } $guess = ''; for ($i = 0; $i < $attempts; $i++) { $guess .= substr(array_shift($name_parts), 0, 1); } foreach ($name_parts as $part) { $guess .= $part; } $guessX = getFacebookUserInfoFromApi($FB, "/{$guess}"); return $guessX ? $guessX : guessFacebookUsername($str, ++$attempts); }