user-stats.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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('user-menu.php');
  18. require_once('data/User.php');
  19. require_once('data/RemoteUser.php');
  20. require_once('data/TagCloud.php');
  21. require_once('data/Statistic.php');
  22. require_once('data/GraphTypes.php');
  23. if (!isset($_GET['user']) && $logged_in == false) {
  24. displayError("Error", "User not set. You shouldn't be here.");
  25. }
  26. try {
  27. if(strstr($_GET['user'], '@')) {
  28. $user = new RemoteUser($_GET['user']);
  29. } else {
  30. $user = new User($_GET['user']);
  31. }
  32. } catch (Exception $e) {
  33. if ($e->getCode() == 22) {
  34. $error = "We had some trouble locating that user. Are you sure you spelled it correctly?";
  35. } else {
  36. $error = $e->getMessage();
  37. }
  38. $user = null;
  39. }
  40. $toptracks = intval($_GET['toptracks']);
  41. if (!($toptracks >= 10 && $toptracks <= 500)) {
  42. $toptracks = 20;
  43. }
  44. $topartists = intval($_GET['topartists']);
  45. if (!($topartists >= 10 && $topartists <= 500)) {
  46. $topartists = 20;
  47. }
  48. if (isset($user->name)) {
  49. $begin = null;
  50. $total_tracks_limit = 15000;
  51. $total_tracks = $user->getTotalTracks();
  52. if(!$total_tracks) {
  53. displayError("No stats for user",
  54. "User {$user->name} doesn't seem to have scrobbled anything yet.");
  55. }
  56. // Limit stats to timeperiod if track count is higher than limit
  57. if($total_tracks > $total_tracks_limit) {
  58. $begin = strtotime('-6 months');
  59. $smarty->assign('timeperiod', '(last 6 months)');
  60. }
  61. $smarty->assign('stat_barwidth', 320);
  62. $smarty->assign('topartistspx', 25 * $topartists);
  63. try {
  64. $smarty->assign('graphtopartists', new GraphTopArtists($user, $topartists, $begin));
  65. } catch (exception $e) {}
  66. try {
  67. $smarty->assign('graphplaysbydays', new GraphPlaysByDays($user, 20));
  68. } catch (exception $e) {}
  69. $smarty->assign('toptrackspx', 25 * $toptracks);
  70. try {
  71. $smarty->assign('graphtoptracks', new GraphTopTracks($user, $toptracks, $begin));
  72. } catch (exception $e) {}
  73. $smarty->assign('totaltracks', $total_tracks);
  74. $smarty->assign('me', $user);
  75. $smarty->assign('geo', Server::getLocationDetails($user->location_uri));
  76. $smarty->assign('isme', ($this_user->name == $user->name));
  77. $smarty->assign('pagetitle', $user->name . '\'s stats');
  78. $smarty->assign('extra_head_links', array(
  79. array(
  80. 'rel' => 'meta',
  81. 'type' => 'application/rdf+xml' ,
  82. 'title' => 'FOAF',
  83. 'href' => $base_url . '/rdf.php?fmt=xml&page=' . rawurlencode(str_replace($base_url, '', $user->getURL()))
  84. ),
  85. array(
  86. 'rel' => 'stylesheet',
  87. 'type' => 'text/css',
  88. 'title' => 'jqPlot CSS',
  89. 'href' => $base_url . '/themes/' . $default_theme . '/css/jquery.jqplot.css'
  90. )
  91. ));
  92. $submenu = user_menu($user, 'Stats');
  93. $smarty->assign('submenu', $submenu);
  94. $smarty->assign('stats', true);
  95. $smarty->display('user-stats.tpl');
  96. } else {
  97. displayError("User not found", "User not found, shall I call in a missing persons report?");
  98. }