BioTorrents.de’s version of Gazelle
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.

paranoia.class.php 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. // Note: at the time this file is loaded, check_perms is not defined.
  3. // Don't call check_paranoia in /classes/script_start.php without ensuring check_perms has been defined
  4. // The following are used throughout the site:
  5. // uploaded, ratio, downloaded: stats
  6. // lastseen: approximate time the user last used the site
  7. // uploads: the full list of the user's uploads
  8. // uploads+: just how many torrents the user has uploaded
  9. // snatched, seeding, leeching: the list of the user's snatched torrents, seeding torrents, and leeching torrents respectively
  10. // snatched+, seeding+, leeching+: the length of those lists respectively
  11. // uniquegroups, perfectflacs: the list of the user's uploads satisfying a particular criterion
  12. // uniquegroups+, perfectflacs+: the length of those lists
  13. // If "uploads+" is disallowed, so is "uploads". So if "uploads" is in the array, the user is a little paranoid, "uploads+", very paranoid.
  14. // The following are almost only used in /sections/user/user.php:
  15. // requiredratio
  16. // requestsfilled_count: the number of requests the user has filled
  17. // requestsfilled_bounty: the bounty thus earned
  18. // requestsfilled_list: the actual list of requests the user has filled
  19. // requestsvoted_...: similar
  20. // artistsadded: the number of artists the user has added
  21. // torrentcomments: the list of comments the user has added to torrents
  22. // +
  23. // collages: the list of collages the user has created
  24. // +
  25. // collagecontribs: the list of collages the user has contributed to
  26. // +
  27. // invitedcount: the number of users this user has directly invited
  28. /**
  29. * Return whether currently logged in user can see $Property on a user with $Paranoia, $UserClass and (optionally) $UserID
  30. * If $Property is an array of properties, returns whether currently logged in user can see *all* $Property ...
  31. *
  32. * @param $Property The property to check, or an array of properties.
  33. * @param $Paranoia The paranoia level to check against.
  34. * @param $UserClass The user class to check against (Staff can see through paranoia of lower classed staff)
  35. * @param $UserID Optional. The user ID of the person being viewed
  36. * @return mixed 1 representing the user has normal access
  37. * 2 representing that the paranoia was overridden,
  38. * false representing access denied.
  39. */
  40. define("PARANOIA_ALLOWED", 1);
  41. define("PARANOIA_OVERRIDDEN", 2);
  42. function check_paranoia($Property, $Paranoia = false, $UserClass = false, $UserID = false)
  43. {
  44. global $Classes;
  45. if ($Property == false) {
  46. return false;
  47. }
  48. if (!is_array($Paranoia)) {
  49. $Paranoia = json_decode($Paranoia, true);
  50. }
  51. if (!is_array($Paranoia)) {
  52. $Paranoia = [];
  53. }
  54. if (is_array($Property)) {
  55. $all = true;
  56. foreach ($Property as $P) {
  57. $all = $all && check_paranoia($P, $Paranoia, $UserClass, $UserID);
  58. }
  59. return $all;
  60. } else {
  61. if (($UserID !== false) && (G::$LoggedUser['ID'] == $UserID)) {
  62. return PARANOIA_ALLOWED;
  63. }
  64. $May = !in_array($Property, $Paranoia) && !in_array($Property . '+', $Paranoia);
  65. if ($May) {
  66. return PARANOIA_ALLOWED;
  67. }
  68. if (check_perms('users_override_paranoia', $UserClass)) {
  69. return PARANOIA_OVERRIDDEN;
  70. }
  71. $Override=false;
  72. switch ($Property) {
  73. case 'downloaded':
  74. case 'ratio':
  75. case 'uploaded':
  76. case 'lastseen':
  77. if (check_perms('users_mod', $UserClass)) {
  78. return PARANOIA_OVERRIDDEN;
  79. }
  80. break;
  81. case 'snatched': case 'snatched+':
  82. if (check_perms('users_view_torrents_snatchlist', $UserClass)) {
  83. return PARANOIA_OVERRIDDEN;
  84. }
  85. break;
  86. case 'uploads': case 'uploads+':
  87. case 'seeding': case 'seeding+':
  88. case 'leeching': case 'leeching+':
  89. if (check_perms('users_view_seedleech', $UserClass)) {
  90. return PARANOIA_OVERRIDDEN;
  91. }
  92. break;
  93. case 'invitedcount':
  94. if (check_perms('users_view_invites', $UserClass)) {
  95. return PARANOIA_OVERRIDDEN;
  96. }
  97. break;
  98. }
  99. return false;
  100. }
  101. }