location.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /* GNU FM -- a free network service for sharing your music listening habits
  3. Copyright (C) 2009 Free Software Foundation, Inc
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Affero General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. require_once('database.php');
  16. require_once('templating.php');
  17. require_once('data/sanitize.php');
  18. require_once('data/Server.php');
  19. require_once('data/User.php');
  20. if (strtolower(substr($connect_string, 0, 5)) == 'mysql') {
  21. $random = 'RAND';
  22. } else if (strtolower(substr($connect_string, 0, 5)) == 'mssql') {
  23. $random = 'NEWID'; // I don't think we try to support MSSQL, but here's how it's done theoretically anyway
  24. } else {
  25. $random = 'RANDOM'; // postgresql, sqlite, possibly others
  26. }
  27. if ($_REQUEST['country']) {
  28. $q = sprintf('SELECT u.* FROM Users u INNER JOIN Places p ON u.location_uri=p.location_uri AND p.country=%s ORDER BY %s() LIMIT 100',
  29. $adodb->qstr(strtoupper($_REQUEST['country'])),
  30. $random);
  31. $adodb->SetFetchMode(ADODB_FETCH_ASSOC);
  32. $res = $adodb->GetAll($q);
  33. foreach ($res as &$row) {
  34. try {
  35. $userlist[] = new User($row['username'], $row);
  36. } catch (Exception $e) {}
  37. }
  38. $smarty->assign('country', strtoupper($_REQUEST['country']));
  39. $row = $adodb->GetRow(sprintf('SELECT * FROM Countries WHERE country=%s LIMIT 1',
  40. $adodb->qstr(strtoupper($_REQUEST['country']))));
  41. if ($row) {
  42. $smarty->assign('country_info', $row);
  43. }
  44. $smarty->assign('userlist', $userlist);
  45. $smarty->assign('extra_head_links', array(
  46. array(
  47. 'rel' => 'meta',
  48. 'type' => 'application/rdf+xml',
  49. 'title' => 'FOAF',
  50. 'href' => $base_url . '/rdf.php?fmt=xml&page=' . rawurlencode(str_replace($base_url, '', $_SERVER['REQUEST_URI']))
  51. )
  52. ));
  53. $smarty->display('location-country.tpl');
  54. } else {
  55. displayError("Location not found", "Location not found, shall I call in a missing locations report?");
  56. }