} 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']) { // Learn column placements to strip incident ID, ensure only own reports are exported. $result = pg_query_params($db->getHandle(), 'SELECT column_name FROM information_schema.columns WHERE table_name=$1', array('incidents')); $pos_id = 0; $pos_reporter_id = 0; $i = 0; $field_headings = array(); while ($row = pg_fetch_object($result)) {
/** * 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); }