Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. function do_search($query, $orderBy = 'rlsnr', $direction = 'desc', $page = 1){
  2.  
  3. $return = array();
  4.  
  5. $whitelist = array('rlsnr', 'rlsname', 'size');
  6. if(!in_array($orderBy, $whitelist)){
  7. $orderBy = 'rlsnr';
  8. }
  9.  
  10. $whitelist = array('desc', 'asc');
  11. if(!in_array($direction, $whitelist)){
  12. $direction = 'asc';
  13. }
  14.  
  15. $page = intval($page);
  16. if($page != 0){
  17. $page = $page;
  18. }
  19. else{
  20. $page = 1;
  21. }
  22.  
  23. $where_clause = '';
  24. $search_query_args = array();
  25.  
  26. $words = array();
  27. $words = explode(" ", $query);
  28. $words = array_map("trim", $words);
  29.  
  30. $search_in = array('rlsnr', 'rlsdir', 'rlsname', 'rlsgroup');
  31. $i = 1;
  32. foreach($words as $word){
  33.  
  34. $where_clause .= '`rlsnr` LIKE ? OR `rlsdir` LIKE ? OR `rlsname` LIKE ? OR `rlsgroup` LIKE ?';
  35. $search_query_args[] = '%'.$word.'%';
  36. $search_query_args[] = '%'.$word.'%';
  37. $search_query_args[] = '%'.$word.'%';
  38. $search_query_args[] = '%'.$word.'%';
  39.  
  40. if($i < count($words)){
  41. $where_clause .= ' OR ';
  42. }
  43.  
  44. $i++;
  45.  
  46. }
  47. #die($where_clause);
  48. $options['offset'] = ($page * ENTRIES_PER_PAGE_AT_LIST - ENTRIES_PER_PAGE_AT_LIST);
  49. $return['number_of_pages'] = ceil(simpleDB::countRows('SELECT `rlsnr`, `rlsdir`, `rlsname`, `rlsgroup` FROM `downloads` WHERE ('.$where_clause.')', $search_query_args) / ENTRIES_PER_PAGE_AT_LIST);
  50.  
  51. $return['entries'] = simpleDB::getRows('SELECT * FROM `downloads` WHERE ('.$where_clause.') ORDER BY '.$orderBy.' '.$direction.' LIMIT '.$options['offset'].', '.ENTRIES_PER_PAGE_AT_LIST, $search_query_args);
  52.  
  53. return $return;
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement