public function getFriendListAction() { global $TNB_GLOBALS, $db; $data = $_POST; $keyword = isset($data['keyword']) ? $data['keyword'] : null; $token = isset($data['TOKEN']) ? trim($data['TOKEN']) : null; $sort = "pop"; $page = isset($data['page']) ? $data['page'] : null; if (!$token) { return ['STATUS_CODE' => STATUS_CODE_BAD_REQUEST, 'DATA' => buckys_api_get_error_result('Api token should not be blank')]; } if (!($userID = BuckysUsersToken::checkTokenValidity($token, "api"))) { return ['STATUS_CODE' => STATUS_CODE_UNAUTHORIZED, 'DATA' => buckys_api_get_error_result('Api token is not valid.')]; } //Search Results $searchIns = new BuckysSearch(); $pageIns = new BuckysPage(); $pageFollowerIns = new BuckysPageFollower(); $db_results = $searchIns->search($keyword, BuckysSearch::SEARCH_TYPE_USER_AND_PAGE, $sort, $page); $results = []; foreach ($db_results as $item) { if ($item['type'] == "user") { //Getting Detail Information $query = $db->prepare("SELECT \n u.firstName, \n u.lastName, \n u.userID, \n u.thumbnail, \n u.current_city, \n u.current_city_visibility,\n f.friendID \n FROM \n " . TABLE_USERS . " AS u\n LEFT JOIN " . TABLE_FRIENDS . " AS f ON f.userID=%d AND f.userFriendID=u.userID AND f.status='1'\n WHERE u.userID=%d", $userID, $item['userID']); $data = $db->getRow($query); if ($data['friendID']) { $row = []; $row['id'] = $item['userID']; $row['name'] = $data['firstName'] . " " . $data['lastName']; $row['description'] = $data['current_city_visibility'] ? $data['current_city'] : ""; $row['friendType'] = "user"; $row['thumbnail'] = THENEWBOSTON_SITE_URL . BuckysUser::getProfileIcon($data); $results[] = $row; } } } return ['STATUS_CODE' => STATUS_CODE_OK, 'DATA' => ["STATUS" => "SUCCESS", "RESULT" => $results]]; }
<?php require dirname(__FILE__) . '/includes/bootstrap.php'; buckys_enqueue_stylesheet('search.css'); buckys_enqueue_javascript('search.js'); $searchIns = new BuckysSearch(); $TNB_GLOBALS['content'] = 'search'; $TNB_GLOBALS['headerType'] = ''; $paramQueryStr = buckys_escape_query_string($_REQUEST['q']); $paramType = buckys_escape_query_string($_REQUEST['type']); $paramSort = buckys_escape_query_string($_REQUEST['sort']); $view = []; //Create Base URL for pagination of search page $view['page_base_url'] = buckys_pp_search_url($paramQueryStr, $paramType, $paramSort, true); $page = isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1; $totalCount = $searchIns->getNumberOfSearchResult($paramQueryStr, $paramType); $pagination = new Pagination($totalCount, BuckysSearch::SEARCH_RESULT_PER_PAGE, $page); $page = $pagination->getCurrentPage(); //Get Friends $view['search_result'] = $searchIns->search($paramQueryStr, $paramType, $paramSort, $page); //Display $TNB_GLOBALS['searchParamPP']['q'] = $paramQueryStr; $TNB_GLOBALS['searchParamPP']['type'] = $paramType; $TNB_GLOBALS['searchParamPP']['sort'] = $paramSort; if ($paramQueryStr != '') { $TNB_GLOBALS['title'] = $paramQueryStr . ' - ' . TNB_SITE_NAME . ' Search'; } else { $TNB_GLOBALS['title'] = TNB_SITE_NAME . ' Search'; } require DIR_FS_TEMPLATE . $TNB_GLOBALS['template'] . "/" . $TNB_GLOBALS['layout'] . ".php";