PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/php/distance.php

https://gitlab.com/iftikhar.ali/the-testing-project
PHP | 721 lines | 539 code | 92 blank | 90 comment | 113 complexity | a0e167b4dfc35f03c60f0877bbac33a9 MD5 | raw file
  1. <?php
  2. // https://developers.google.com/maps/documentation/javascript/examples/map-projection-simple
  3. add_shortcode('distance_calc_sc','distance_calc');
  4. function distance_calc() {
  5. global $wpdb;
  6. global $user_long_lat;
  7. global $i;
  8. global $map;
  9. global $results;
  10. global $uzip;
  11. global $selected_zip;
  12. global $results_page;
  13. global $user_country;
  14. global $zlookup;
  15. global $search_keyword;
  16. global $test_array;
  17. $search_keyword[0] = NULL;
  18. $current_user = wp_get_current_user();
  19. $current_user->ID;
  20. if(is_user_logged_in()){
  21. $selected_zip = mysql_escape_string($_POST['zip']);
  22. /* User info */
  23. // Get the current user's zip code
  24. $user_zip = $wpdb->get_results("
  25. SELECT *
  26. FROM `wp_bp_xprofile_data`
  27. WHERE user_id = $current_user->ID
  28. AND field_id = 36
  29. LIMIT 1
  30. ");
  31. // Check for a selected zip code
  32. if(!$selected_zip){
  33. $uzip = $user_zip[0]->value;
  34. }
  35. elseif($selected_zip){
  36. $uzip = $selected_zip;
  37. }
  38. $user_country_query = $wpdb->get_results("
  39. SELECT value
  40. FROM `wp_bp_xprofile_data`
  41. WHERE user_id = $current_user->ID
  42. AND field_id = 42
  43. LIMIT 1
  44. ");
  45. $country = $user_country_query[0]->value;
  46. $country_query = $wpdb->last_query;
  47. // Get the longitude and latitude of current user's zip code
  48. if($country == 'United States'){
  49. $user_long_lat = $wpdb->get_results("
  50. SELECT *
  51. FROM `zipcodes`
  52. WHERE postal_code = $uzip
  53. LIMIT 1
  54. ");
  55. }
  56. if($country == 'India'){
  57. $user_long_lat = $wpdb->get_results("
  58. SELECT *
  59. FROM `zipcodes_india`
  60. WHERE postal_code = $uzip
  61. LIMIT 1
  62. ");
  63. }
  64. if($country=='Germany'){
  65. $user_long_lat = $wpdb->get_results("
  66. SELECT *
  67. FROM `zipcodes_germany`
  68. WHERE postal_code = $uzip
  69. LIMIT 1
  70. ");
  71. }
  72. /* Primary Talent */
  73. // Get the current user's primary talent
  74. $user_primary_talent = $wpdb->get_results("
  75. SELECT talent_id
  76. FROM `sat_01_talent`
  77. WHERE user_id = $current_user->ID
  78. LIMIT 1
  79. ");
  80. $ut = $user_primary_talent[0]->talent_id;
  81. // Get the primary talent name for searching
  82. $primary_talent_name = $wpdb->get_results("
  83. SELECT *
  84. FROM `sat_talents`
  85. WHERE id = $ut
  86. LIMIT 1
  87. ");
  88. /* Second Talent */
  89. $user_primary_talent2 = $wpdb->get_results("
  90. SELECT talent_id
  91. FROM `sat_02_talent`
  92. WHERE user_id = $current_user->ID
  93. LIMIT 1
  94. ");
  95. $ut2 = $user_primary_talent2[0]->talent_id;
  96. // Get the second talent name for searching
  97. $second_talent_name = $wpdb->get_results("
  98. SELECT *
  99. FROM `sat_talents`
  100. WHERE id = $ut2
  101. LIMIT 1
  102. ");
  103. /* Third Talent */
  104. $user_primary_talent3 = $wpdb->get_results("
  105. SELECT talent_id
  106. FROM `sat_03_talent`
  107. WHERE user_id = $current_user->ID
  108. LIMIT 1
  109. ");
  110. $ut3 = $user_primary_talent3[0]->talent_id;
  111. // Get the second talent name for searching
  112. $third_talent_name = $wpdb->get_results("
  113. SELECT *
  114. FROM `sat_talents`
  115. WHERE id = $ut3
  116. LIMIT 1
  117. ");
  118. /* Fourth Talent */
  119. $user_primary_talent4 = $wpdb->get_results("
  120. SELECT talent_id
  121. FROM `sat_04_talent`
  122. WHERE user_id = $current_user->ID
  123. LIMIT 1
  124. ");
  125. $ut4 = $user_primary_talent4[0]->talent_id;
  126. // Get the second talent name for searching
  127. $fourth_talent_name = $wpdb->get_results("
  128. SELECT *
  129. FROM `sat_talents`
  130. WHERE id = $ut4
  131. LIMIT 1
  132. ");
  133. /* Fifth Talent */
  134. $user_primary_talent5 = $wpdb->get_results("
  135. SELECT talent_id
  136. FROM `sat_05_talent`
  137. WHERE user_id = $current_user->ID
  138. LIMIT 1
  139. ");
  140. $ut5 = $user_primary_talent5[0]->talent_id;
  141. // Get the second talent name for searching
  142. $fifth_talent_name = $wpdb->get_results("
  143. SELECT *
  144. FROM `sat_talents`
  145. WHERE id = $ut5
  146. LIMIT 1
  147. ");
  148. $sat1 = $primary_talent_name[0]->level_3;
  149. $sat2 = $second_talent_name[0]->level_3;
  150. $sat3 = $third_talent_name[0]->level_3;
  151. $sat4 = $fourth_talent_name[0]->level_3;
  152. $sat5 = $fifth_talent_name[0]->level_3;
  153. $selected_talent = mysql_escape_string($_POST['talent']);
  154. if(!$selected_talent_click){ $search_bar_talent = mysql_escape_string($_GET['search']); }
  155. if(!$search_bar_talent) {
  156. $selected_talent = mysql_escape_string($_POST['talent']);
  157. }
  158. else {$selected_talent = $search_bar_talent; }
  159. if($selected_talent){
  160. $search_term = $selected_talent;
  161. $search_for_the_talent_id = $wpdb->get_results("
  162. SELECT id
  163. FROM `sat_talents`
  164. WHERE `level_3` = '$search_term'
  165. ");
  166. $ut = $search_for_the_talent_id[0]->id;
  167. }
  168. elseif (!$selected_talent) {$search_term = $primary_talent_name[0]->level_3;}
  169. if(!$selected_zip) { // Search groups with the talent in their keywords
  170. $search_the_keyword = $wpdb->get_results("
  171. SELECT user_id
  172. FROM `sat_01_talent`
  173. WHERE talent_id = $ut
  174. ");
  175. /*
  176. $m=0;
  177. foreach ($search_the_keyword as $s) {
  178. $id = $s->id;
  179. $search_keyword_array = $wpdb->get_results("
  180. SELECT group_id as id
  181. FROM `sat_group_localization`
  182. WHERE group_id = $id
  183. LIMIT 1
  184. ");
  185. if(!empty($search_keyword_array)){
  186. $search_keyword[$m] = $search_keyword_array[0];
  187. $m++;
  188. }// end if
  189. }// end foreach
  190. */
  191. $search_keyword = $search_the_keyword;
  192. } //end if
  193. /* SELECTED ZIP */
  194. if($selected_zip) { // Search groups with the talent in their keywords
  195. //look for a selected search term
  196. $selected_talent = mysql_escape_string($_POST['talent']);
  197. if($selected_talent){$search_term = $selected_talent;}
  198. elseif (!$selected_talent) {$search_term = $primary_talent_name[0]->level_3;}
  199. // Look up the search term
  200. $search_the_keyword = $wpdb->get_results("
  201. SELECT user_id
  202. FROM `sat_01_talent`
  203. WHERE talent_id = $ut
  204. ");
  205. /*
  206. // Build an array of the groups that have a search term match
  207. $m=0;
  208. foreach ($search_the_keyword as $s) {
  209. $id = $s->user_id;
  210. $search_keyword_array = $wpdb->get_results("
  211. SELECT group_id as id
  212. FROM `sat_group_localization`
  213. WHERE group_id = $id
  214. AND zip_code = $selected_zip
  215. LIMIT 1
  216. ");
  217. if(!empty($search_keyword_array)){
  218. $search_keyword[$m] = $search_keyword_array[0];
  219. $m++;
  220. }// end if
  221. }// end foreach
  222. */
  223. $search_keyword = $search_the_keyword;
  224. }// end if
  225. $test_array = array();
  226. $map = array();
  227. $results = array();
  228. $i=0;
  229. foreach ($search_keyword as $sk) {
  230. // lookup other group's zip codes
  231. $g_id = $sk->user_id;
  232. $other_zip = $wpdb->get_results("
  233. SELECT *
  234. FROM `wp_bp_xprofile_data`
  235. WHERE user_id = $g_id
  236. and field_id = 36
  237. LIMIT 1
  238. ");
  239. $other_country = $wpdb->get_results("
  240. SELECT *
  241. FROM `wp_bp_xprofile_data`
  242. WHERE user_id = $g_id
  243. and field_id = 42
  244. LIMIT 1
  245. ");
  246. $oz = $other_zip[$i]->value;
  247. $oc = $other_country[$i]->value; // country lookup
  248. // Get long/lat of the group's zip code
  249. if ($oc == 'United States') {
  250. $zlookup = $wpdb->get_results("
  251. SELECT *
  252. FROM `zipcodes`
  253. WHERE postal_code = $oz
  254. ");
  255. }
  256. elseif ($oc == 'India') {
  257. $zlookup = $wpdb->get_results("
  258. SELECT *
  259. FROM `zipcodes_india`
  260. WHERE postal_code = $oz
  261. ");
  262. }
  263. elseif ($oc == 'Germany') {
  264. $zlookup = $wpdb->get_results("
  265. SELECT *
  266. FROM `zipcodes_germany`
  267. WHERE postal_code = $oz
  268. ");
  269. }
  270. // Assign current user and group's long/lat
  271. $point1['lat'] = $user_long_lat[0]->latitude;
  272. $point1['long'] = $user_long_lat[0]->longitude;
  273. $point2['lat'] = $zlookup[0]->latitude;
  274. $point2['long'] = $zlookup[0]->longitude;
  275. $point2['city'] = $zlookup[0]->place_name;
  276. $point2['state'] = $zlookup[0]->place_name2;
  277. // Calculate the distance from current user to group's long/lat
  278. $distance = (3958 * 3.1415926 * sqrt(
  279. ($point1['lat'] - $point2['lat'])
  280. * ($point1['lat'] - $point2['lat'])
  281. + cos($point1['lat'] / 57.29578)
  282. * cos($point2['lat'] / 57.29578)
  283. * ($point1['long'] - $point2['long'])
  284. * ($point1['long'] - $point2['long'])
  285. ) / 180);
  286. // If the distance is under 55 miles, include the group
  287. if ($distance < 55 ) {
  288. $map[$i] = array(
  289. 'o_id' => $g_id,
  290. 'o_long' => $point2['long'],
  291. 'o_lat' => $point2['lat'],
  292. 'o_city' => $point2['city'],
  293. 'o_state' => $point2['state'],
  294. 'o_zip' => $oz
  295. );
  296. // Build arrays for map and results
  297. $map_group[$i] = intval($oz);
  298. $results[$i] = $g_id;
  299. $i++;
  300. }// end if
  301. } // end foreach
  302. //var_dump($map);
  303. //var_dump($results);
  304. if(empty($map)){ ?>
  305. <h2>No results for your talent search. Try another!</h2>
  306. <form action="" method="post">
  307. <p class="groups-header">
  308. <select style="display:inline;" name="talent">
  309. <option value="<?php echo $search_term; ?>" selected="selected"><?php echo $search_term; ?></option>
  310. <option>---------</option>
  311. <?php if($sat1){echo '<option value="' . $sat1 . '">' . $sat1. '</option>';} ?>
  312. <?php if($sat2){echo '<option value="' . $sat2 . '">' . $sat2. '</option>';} ?>
  313. <?php if($sat3){echo '<option value="' . $sat3 . '">' . $sat3. '</option>';} ?>
  314. <?php if($sat4){echo '<option value="' . $sat4 . '">' . $sat4. '</option>';} ?>
  315. <?php if($sat5){echo '<option value="' . $sat5 . '">' . $sat5. '</option>';} ?>
  316. </select>
  317. <input style="display:inline;" type="submit" value="Search"/>
  318. </p>
  319. </form>
  320. <hr />
  321. <?php } // end if
  322. if(!empty($map)) {
  323. $map_group_clean_results = array_unique($map_group);
  324. $map_group_clean = array_filter($map_group_clean_results);
  325. //var_dump($map_group_clean);
  326. ?>
  327. <form action="" method="post">
  328. <p class="groups-header">People in your area with a primary talent of
  329. <select style="display:inline;" name="talent">
  330. <option value="<?php echo $search_term; ?>" selected="selected"><?php echo $search_term; ?></option>
  331. <option>---------</option>
  332. <?php if($sat1){echo '<option value="' . $sat1 . '">' . $sat1. '</option>';} ?>
  333. <?php if($sat2){echo '<option value="' . $sat2 . '">' . $sat2. '</option>';} ?>
  334. <?php if($sat3){echo '<option value="' . $sat3 . '">' . $sat3. '</option>';} ?>
  335. <?php if($sat4){echo '<option value="' . $sat4 . '">' . $sat4. '</option>';} ?>
  336. <?php if($sat5){echo '<option value="' . $sat5 . '">' . $sat5. '</option>';} ?>
  337. </select>
  338. <input style="display:inline;" type="submit" value="Search"/>
  339. </p>
  340. </form>
  341. <hr />
  342. <style type="text/css">
  343. body {
  344. font-family: sans-serif;
  345. }
  346. }
  347. </style>
  348. <script type="text/javascript">
  349. google.maps.event.addDomListener(window, 'load', function() {
  350. var map = new google.maps.Map(document.getElementById('map'), {
  351. zoom: 10,
  352. center: new google.maps.LatLng(<?php echo $point1['lat'] . ', ' . $point1['long'] ?>),
  353. mapTypeId: google.maps.MapTypeId.ROADMAP
  354. });
  355. var infoWindow = new google.maps.InfoWindow;
  356. <?php $i=1;
  357. //var_dump($map_group_clean);
  358. foreach ($map_group_clean as $mgc) {
  359. $selected_talent = mysql_escape_string($_POST['talent']);
  360. if($selected_talent){$if_selected_talent = '<input type="hidden" value="' .$selected_talent . '" name="talent" />';}
  361. $z = $mgc;
  362. if ($country == 'United States'){
  363. $lookup = $wpdb->get_results("
  364. SELECT *
  365. FROM `zipcodes`
  366. WHERE postal_code = $z
  367. ");
  368. }
  369. else if ($country == 'India') {
  370. $lookup = $wpdb->get_results("
  371. SELECT *
  372. FROM `zipcodes_india`
  373. WHERE postal_code = $z
  374. ");
  375. }
  376. else if ($country == 'Germany') {
  377. $lookup = $wpdb->get_results("
  378. SELECT *
  379. FROM `zipcodes_germany`
  380. WHERE postal_code = $z
  381. ");
  382. }
  383. echo '
  384. var onMarker' . $i . 'Click = function() {
  385. var marker = marker' . $i . ';
  386. var latLng = marker.getPosition();
  387. var city = \'' . $lookup[0]->place_name . '\' ;
  388. var st = \'' . $lookup[0]->place_name2 . '\' ;';
  389. if(!$selected_zip) {
  390. echo ' infoWindow.setContent(\'<div style="width:60%; float:left;"><form action="#" method="post"><input type="hidden" value="' . $lookup[0]->postal_code . '" name="zip" /><input type="submit" value="Find Talent in ' . $lookup[0]->place_name . ', ' . $lookup[0]->place_name2 . '!" />' . $if_selected_talent . '</form></div>\');';
  391. echo ' infoWindow.open(map, marker' . $i . ');';
  392. };
  393. echo '};';
  394. echo '';
  395. $i++;
  396. }?>
  397. google.maps.event.addListener(map, 'click', function() {
  398. infoWindow.close();
  399. });
  400. <?php
  401. $i=1;
  402. foreach ($map_group_clean as $mgc) {
  403. $z = $mgc;
  404. if ($user_country == 'United States') {
  405. $lookup = $wpdb->get_results("
  406. SELECT *
  407. FROM `zipcodes`
  408. WHERE postal_code = $z
  409. ");
  410. }
  411. elseif ($user_country == 'India') {
  412. $lookup = $wpdb->get_results("
  413. SELECT *
  414. FROM `zipcodes_india`
  415. WHERE postal_code = $z
  416. ");
  417. }
  418. elseif ($user_country == 'Germany') {
  419. $lookup = $wpdb->get_results("
  420. SELECT *
  421. FROM `zipcodes_germany`
  422. WHERE postal_code = $z
  423. ");
  424. }
  425. echo 'var marker' . $i . ' = new google.maps.Marker({
  426. map: map,
  427. position: new google.maps.LatLng(' . $lookup[0]->latitude . ', ' . $lookup[0]->longitude . ')
  428. });
  429. ';
  430. $i++;
  431. } // end foreach var marker
  432. $i=1;
  433. foreach ($map_group_clean as $mgc) {
  434. $z = $mgc;
  435. $lookup = $wpdb->get_results("
  436. SELECT *
  437. FROM `zipcodes`
  438. WHERE postal_code = $z
  439. LIMIT 1
  440. ");
  441. echo 'google.maps.event.addListener(marker' . $i . ', \'click\', onMarker' . $i . 'Click);';
  442. $i++;
  443. } // end foreach addListener
  444. ?>
  445. });
  446. </script>
  447. <div id="map-container">
  448. <div id="map"></div>
  449. <?php
  450. /*******************************************/
  451. /********* Results container area **********/
  452. /*******************************************/
  453. ?>
  454. <div id="results-container">
  455. <?php
  456. $results_page = intval(mysql_escape_string($_POST['results-page']));
  457. if(empty($results_page)){$results_page_up = 2;}
  458. if(!empty($results_page)){$results_page_up = $results_page+1; $results_page_down = $results_page-1;}
  459. ?>
  460. <?php //var_dump($results); ?>
  461. <?php if(!$selected_zip){ ?>
  462. <h4>Results - <?php if( (count($map)/4) > 1 ){
  463. if(empty($results_page)){
  464. echo ' Page 1/' . ceil(count($map)/4);
  465. }
  466. else {
  467. echo ' Page '. $results_page .'/' . ceil(count($map)/4);
  468. }
  469. ?>
  470. </h4>
  471. <?php
  472. //PREVIOUS button
  473. if($results_page==2){
  474. echo '<a href="http://www.shareatalent.com/find-local-talent" style="border: none; background: none; font-size: 16px; font-weight: bold; color: #e4078c;" >
  475. << Previous </a>';
  476. }
  477. elseif($results_page>=3){
  478. echo '<form style="display:inline;" id="group-page" action="" method="post">
  479. <input type="hidden" name="results-page" value="'. $results_page_down . '" />
  480. <input style="border: none; background: none; font-size: 16px; font-weight: bold; color: #e4078c;" type="submit" value="<< Previous" /></form>';
  481. }
  482. // NEXT button
  483. if(intval($results_page) !== intval(ceil(count($map)/4) ) ){
  484. echo '<form style="display:inline;" id="group-page" action="" method="post">
  485. <input type="hidden" name="results-page" value="'. $results_page_up . '" />
  486. <input style="border: none; background: none; font-size: 16px; font-weight: bold; color: #e4078c;" type="submit" value="Next >>" /></form>';
  487. }//end if
  488. }
  489. } //end if
  490. elseif($selected_zip) { ?>
  491. <h4>Results for <?php echo $lookup[0]->place_name . ', ' . $lookup[0]->place_name2; ?>:
  492. <?php
  493. if(empty($results_page)){ ?>
  494. <br/> Page 1/<?php echo ceil(count($map)/4);
  495. }
  496. elseif(!empty($results_page)) {?><br /> Page <?php echo $results_page .'/' . ceil(count($map)/4);
  497. }
  498. ?>
  499. </h4>
  500. <?php
  501. //PREVIOUS button
  502. if($results_page==2){
  503. echo '<form style="display:inline;" id="group-page" action="" method="post">
  504. <input type="hidden" value="' . $lookup[0]->postal_code . '" name="zip" />
  505. <input style="border: none; background: none; font-size: 16px; font-weight: bold; color: #e4078c;" type="submit" value="<< Previous " /></form>';
  506. // end if';
  507. }
  508. elseif($results_page>=3){
  509. echo '<form style="display:inline;" id="group-page" action="" method="post">
  510. <input type="hidden" name="results-page" value="'. $results_page_up . '" />
  511. <input style="border: none; background: none; font-size: 16px; font-weight: bold; color: #e4078c;" type="submit" value="Next >>" /></form>';
  512. }
  513. // NEXT button
  514. if(intval($results_page) !== intval(ceil(count($map)/4) ) ){
  515. echo '<form style="display:inline;" id="group-page" action="" method="post">
  516. <input type="hidden" value="' . $lookup[0]->postal_code . '" name="zip" />
  517. <input type="hidden" name="results-page" value="'. $results_page_up . '" />
  518. <input style="border: none; background: none; font-size: 16px; font-weight: bold; color: #e4078c;" type="submit" value="Next >>" /></form>';
  519. }//end if
  520. ?>
  521. <?php } //end else ?>
  522. <?php
  523. $rp=1;
  524. if($results_page){
  525. // replace with equation $split = ($results_page * 4) - 4;
  526. if($results_page == 2 ) {$split = 4 ; }
  527. if($results_page == 3 ) {$split = 8 ; }
  528. if($results_page == 4 ) {$split = 12 ; }
  529. if($results_page == 5 ) {$split = 16 ; }
  530. if($results_page == 6 ) {$split = 20 ; }
  531. if($results_page == 7 ) {$split = 24 ; }
  532. if($results_page == 8 ) {$split = 28 ; }
  533. if($results_page == 9 ) {$split = 32 ; }
  534. if($results_page == 10 ) {$split = 36 ; }
  535. if($results_page == 11 ) {$split = 40 ; }
  536. if($results_page == 12 ) {$split = 44 ; }
  537. if($results_page == 13 ) {$split = 48 ; }
  538. if($results_page == 14 ) {$split = 52 ; }
  539. if($results_page == 15 ) {$split = 56 ; }
  540. if($results_page == 16 ) {$split = 60 ; }
  541. if($results_page == 17 ) {$split = 64 ; }
  542. if($results_page == 18 ) {$split = 68 ; }
  543. if($results_page == 19 ) {$split = 72 ; }
  544. if($results_page == 20 ) {$split = 76 ; }
  545. if($results_page == 21 ) {$split = 80 ; }
  546. if($results_page == 22 ) {$split = 84 ; }
  547. if($results_page == 23 ) {$split = 88 ; }
  548. if($results_page == 24 ) {$split = 92 ; }
  549. if($results_page == 25 ) {$split = 96 ; }
  550. $split_plus = $split + 3;
  551. // Break results up into multiple pages for paging of
  552. $r_sliced = array_slice($results,$split,$split_plus,true);
  553. foreach ($r_sliced as $r) {
  554. $ou = new WP_User($r);
  555. $ou_n = $ou->display_name;
  556. $ou_s = $ou->user_nicename;
  557. //$ou_t = strip_tags($ou->description);
  558. $ou_t_array = $wpdb->get_results("
  559. SELECT about_talent
  560. FROM `sat_about_talent`
  561. WHERE user_id = $r
  562. LIMIT 1
  563. ");
  564. //var_dump($ou_t_array);
  565. $ou_t = stripslashes($ou_t_array[0]->about_talent);
  566. $ou_tc = strpos($ou_t,$search_term);
  567. //check if the search term is at the very beginning of the results
  568. if($ou_tc<30){$ou_tr = substr($ou_t, $ou_tc,100);}
  569. else {$ou_tr = substr($ou_t, $ou_tc-30,100);}
  570. $st_html = '<span style="background-color:#e4078c; color:#fff;padding:2px 3px 2px 3px;">' . $search_term . '</span>';
  571. $ou_final = str_ireplace($search_term,$st_html,$ou_tr);
  572. ?>
  573. <hr />
  574. <h4><a href="http://shareatalent.com/groups/<?php echo $ou_s; ?>" target="_blank"><?php echo $ou_n; ?></a></h4>
  575. <p>...<?php echo $ou_final; ?>...</p>
  576. <?php } //end foreach
  577. } // end if ?>
  578. <?php
  579. if(empty($results_page)){
  580. $r_sliced = array_slice($results,0,4,true);
  581. foreach ($r_sliced as $r) {
  582. //echo '<p>No page</p>';
  583. //$map_array = array($m);
  584. //$m_sliced = array_slice($map_array,0,4);
  585. //echo $map_array[0]['o_id'];
  586. $ou = new WP_User($r);
  587. $ou_n = $ou->display_name;
  588. $ou_s = $ou->user_nicename;
  589. //$ou_t = strip_tags($ou->description);
  590. $ou_t_array = $wpdb->get_results("
  591. SELECT about_talent
  592. FROM `sat_about_talent`
  593. WHERE user_id = $r
  594. LIMIT 1
  595. ");
  596. //var_dump($ou_t_array);
  597. $ou_t = stripslashes($ou_t_array[0]->about_talent);
  598. $ou_tc = strpos($ou_t,$search_term);
  599. //var_dump($ou);
  600. //check if the search term is at the very beginning of the results
  601. if($ou_tc<30){$ou_tr = substr($ou_t, $ou_tc,100);}
  602. else {$ou_tr = substr($ou_t, $ou_tc-30,100);}
  603. $st_html = '<span style="background-color:#e4078c; color:#fff;padding:2px 3px 2px 3px;">' . $search_term . '</span>';
  604. $ou_final = str_ireplace($search_term,$st_html,$ou_tr);
  605. ?>
  606. <hr />
  607. <h4><a href="http://www.shareatalent.com/members/<?php echo $ou_s; ?>" target="_blank"><?php echo $ou_n; ?></a></h4>
  608. <p>...<?php echo strip_tags($ou_final); ?>...</p>
  609. <?php
  610. $rp++;
  611. }//end if r
  612. } //end foreach
  613. ?>
  614. <hr />
  615. </div>
  616. </div><!-- end map-container -->
  617. <?php
  618. } // end if (!empty($map)
  619. /***************/
  620. }
  621. else {echo '<h2>You must be <a href="http://shareatalent.com/wp-login.php">Logged In</a> to see this page</h2>'; }
  622. // end if is_user_logged_in
  623. } // end distanc_calc
  624. ?>