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.

bookmarks.class.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. class Bookmarks
  3. {
  4. /**
  5. * Check if can bookmark
  6. *
  7. * @param string $Type
  8. * @return boolean
  9. */
  10. public static function can_bookmark($Type)
  11. {
  12. return in_array($Type, array(
  13. 'torrent',
  14. 'artist',
  15. 'collage',
  16. 'request'
  17. ));
  18. }
  19. /**
  20. * Get the bookmark schema.
  21. * Recommended usage:
  22. * list($Table, $Col) = bookmark_schema('torrent');
  23. *
  24. * @param string $Type the type to get the schema for
  25. */
  26. public static function bookmark_schema($Type)
  27. {
  28. switch ($Type) {
  29. case 'torrent':
  30. return array(
  31. 'bookmarks_torrents',
  32. 'GroupID'
  33. );
  34. break;
  35. case 'artist':
  36. return array(
  37. 'bookmarks_artists',
  38. 'ArtistID'
  39. );
  40. break;
  41. case 'collage':
  42. return array(
  43. 'bookmarks_collages',
  44. 'CollageID'
  45. );
  46. break;
  47. case 'request':
  48. return array(
  49. 'bookmarks_requests',
  50. 'RequestID'
  51. );
  52. break;
  53. default:
  54. error('h4x');
  55. }
  56. }
  57. /**
  58. * Check if something is bookmarked
  59. *
  60. * @param string $Type
  61. * type of bookmarks to check
  62. * @param int $ID
  63. * bookmark's id
  64. * @return boolean
  65. */
  66. public static function has_bookmarked($Type, $ID)
  67. {
  68. return in_array($ID, self::all_bookmarks($Type));
  69. }
  70. /**
  71. * Fetch all bookmarks of a certain type for a user.
  72. * If UserID is false than defaults to G::$LoggedUser['ID']
  73. *
  74. * @param string $Type
  75. * type of bookmarks to fetch
  76. * @param int $UserID
  77. * userid whose bookmarks to get
  78. * @return array the bookmarks
  79. */
  80. public static function all_bookmarks($Type, $UserID = false)
  81. {
  82. if ($UserID === false) {
  83. $UserID = G::$LoggedUser['ID'];
  84. }
  85. $CacheKey = "bookmarks_$Type".'_'.$UserID;
  86. if (($Bookmarks = G::$Cache->get_value($CacheKey)) === false) {
  87. list($Table, $Col) = self::bookmark_schema($Type);
  88. $QueryID = G::$DB->get_query_id();
  89. G::$DB->query("
  90. SELECT `$Col`
  91. FROM `$Table`
  92. WHERE UserID = '$UserID'");
  93. $Bookmarks = G::$DB->collect($Col);
  94. G::$DB->set_query_id($QueryID);
  95. G::$Cache->cache_value($CacheKey, $Bookmarks, 0);
  96. }
  97. return $Bookmarks;
  98. }
  99. }