Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.3 KiB

10 years ago
  1. <?php
  2. function msearch_post(App $a) {
  3. $perpage = (($_POST['n']) ? $_POST['n'] : 80);
  4. $page = (($_POST['p']) ? intval($_POST['p'] - 1) : 0);
  5. $startrec = (($page+1) * $perpage) - $perpage;
  6. $search = $_POST['s'];
  7. if(! strlen($search))
  8. killme();
  9. $r = q("SELECT COUNT(*) AS `total` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 AND `user`.`hidewall` = 0 AND MATCH `pub_keywords` AGAINST ('%s') ",
  10. dbesc($search)
  11. );
  12. if (dbm::is_result($r))
  13. $total = $r[0]['total'];
  14. $results = array();
  15. $r = q("SELECT `pub_keywords`, `username`, `nickname`, `user`.`uid` FROM `user` LEFT JOIN `profile` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 AND `user`.`hidewall` = 0 AND MATCH `pub_keywords` AGAINST ('%s') LIMIT %d , %d ",
  16. dbesc($search),
  17. intval($startrec),
  18. intval($perpage)
  19. );
  20. if (dbm::is_result($r)) {
  21. foreach($r as $rr)
  22. $results[] = array(
  23. 'name' => $rr['name'],
  24. 'url' => App::get_baseurl() . '/profile/' . $rr['nickname'],
  25. 'photo' => App::get_baseurl() . '/photo/avatar/' . $rr['uid'] . '.jpg',
  26. 'tags' => str_replace(array(',',' '),array(' ',' '),$rr['pub_keywords'])
  27. );
  28. }
  29. $output = array('total' => $total, 'items_page' => $perpage, 'page' => $page + 1, 'results' => $results);
  30. echo json_encode($output);
  31. killme();
  32. }