diff --git a/classes/bookmarks.class.php b/classes/bookmarks.class.php
new file mode 100644
index 00000000..e30565b1
--- /dev/null
+++ b/classes/bookmarks.class.php
@@ -0,0 +1,95 @@
+
+class Bookmarks {
+
+ /**
+ * Check if can bookmark
+ *
+ * @param string $Type
+ * @return boolean
+ */
+ public static function can_bookmark($Type) {
+ return in_array($Type, array(
+ 'torrent',
+ 'artist',
+ 'collage',
+ 'request'
+ ));
+ }
+
+ /**
+ * Get the bookmark schema.
+ * Recommended usage:
+ * list($Table, $Col) = bookmark_schema('torrent');
+ *
+ * @param string $Type the type to get the schema for
+ */
+ public static function bookmark_schema($Type) {
+ switch ($Type) {
+ case 'torrent':
+ return array(
+ 'bookmarks_torrents',
+ 'GroupID'
+ );
+ break;
+ case 'artist':
+ return array(
+ 'bookmarks_artists',
+ 'ArtistID'
+ );
+ break;
+ case 'collage':
+ return array(
+ 'bookmarks_collages',
+ 'CollageID'
+ );
+ break;
+ case 'request':
+ return array(
+ 'bookmarks_requests',
+ 'RequestID'
+ );
+ break;
+ default:
+ die('HAX');
+ }
+ }
+
+ /**
+ * Check if something is bookmarked
+ *
+ * @param string $Type
+ * type of bookmarks to check
+ * @param int $ID
+ * bookmark's id
+ * @return boolean
+ */
+ public static function has_bookmarked($Type, $ID) {
+ return in_array($ID, self::all_bookmarks($Type));
+ }
+
+ /**
+ * Fetch all bookmarks of a certain type for a user.
+ * If UserID is false than defaults to $LoggedUser['ID']
+ *
+ * @param string $Type
+ * type of bookmarks to fetch
+ * @param int $UserID
+ * userid whose bookmarks to get
+ * @return array the bookmarks
+ */
+ public static function all_bookmarks($Type, $UserID = false) {
+ global $DB, $Cache, $LoggedUser;
+ if ($UserID === false) {
+ $UserID = $LoggedUser['ID'];
+ }
+ $CacheKey = 'bookmarks_' . $Type . '_' . $UserID;
+ if (($Bookmarks = $Cache->get_value($CacheKey)) === FALSE) {
+ list ($Table, $Col) = self::bookmark_schema($Type);
+ $DB->query("SELECT $Col FROM $Table WHERE UserID = '$UserID'");
+ $Bookmarks = $DB->collect($Col);
+ $Cache->cache_value($CacheKey, $Bookmarks, 0);
+ }
+ return $Bookmarks;
+ }
+}
+?>
diff --git a/classes/script_start.php b/classes/script_start.php
index 1149177f..da6f05f5 100644
--- a/classes/script_start.php
+++ b/classes/script_start.php
@@ -96,6 +96,9 @@
case 'BencodeTorrent':
$FileName = 'class_bencodetorrent';
break;
+ case 'Bookmarks':
+ $FileName = 'bookmarks.class';
+ break;
case 'Format':
$FileName = 'class_format';
break;
diff --git a/sections/ajax/artist.php b/sections/ajax/artist.php
index f6bb39af..1d89b4be 100644
--- a/sections/ajax/artist.php
+++ b/sections/ajax/artist.php
@@ -4,7 +4,7 @@ function compare($X, $Y){
return($Y['count'] - $X['count']);
}
-include(SERVER_ROOT.'/sections/bookmarks/functions.php'); // has_bookmarked()
+ // Bookmarks::has_bookmarked()
include(SERVER_ROOT.'/sections/requests/functions.php');
include(SERVER_ROOT.'/classes/class_text.php'); // Text formatting class
@@ -225,7 +225,7 @@ function compare($X, $Y){
'releaseType' => (int) $ReleaseType,
'wikiImage' => $WikiImage,
'groupVanityHouse' => $GroupVanityHouse == 1,
- 'hasBookmarked' => $hasBookmarked = has_bookmarked('torrent', $GroupID),
+ 'hasBookmarked' => $hasBookmarked = Bookmarks::has_bookmarked('torrent', $GroupID),
'torrent' => $InnerTorrents
);
}
@@ -295,7 +295,7 @@ function compare($X, $Y){
'id' => (int) $ArtistID,
'name' => $Name,
'notificationsEnabled' => $notificationsEnabled,
- 'hasBookmarked' => has_bookmarked('artist', $ArtistID),
+ 'hasBookmarked' => Bookmarks::has_bookmarked('artist', $ArtistID),
'image' => $Image,
'body' => $Text->full_format($Body),
'vanityHouse' => $VanityHouseArtist == 1,
diff --git a/sections/ajax/bookmarks/artists.php b/sections/ajax/bookmarks/artists.php
index 13287b95..b7045e84 100644
--- a/sections/ajax/bookmarks/artists.php
+++ b/sections/ajax/bookmarks/artists.php
@@ -29,7 +29,7 @@
$Sneaky = ($UserID != $LoggedUser['ID']);
-//$ArtistList = all_bookmarks('artist', $UserID);
+//$ArtistList = Bookmarks::all_bookmarks('artist', $UserID);
$DB->query('SELECT ag.ArtistID, ag.Name
FROM bookmarks_artists AS ba
diff --git a/sections/ajax/bookmarks/index.php b/sections/ajax/bookmarks/index.php
index 735428b1..ae3a1b6d 100644
--- a/sections/ajax/bookmarks/index.php
+++ b/sections/ajax/bookmarks/index.php
@@ -1,5 +1,5 @@
-include(SERVER_ROOT.'/sections/bookmarks/functions.php');
+
// Number of users per page
define('BOOKMARKS_PER_PAGE', '20');
diff --git a/sections/ajax/browse.php b/sections/ajax/browse.php
index 18a24c61..c66c0e92 100644
--- a/sections/ajax/browse.php
+++ b/sections/ajax/browse.php
@@ -1,7 +1,7 @@
-include(SERVER_ROOT.'/sections/bookmarks/functions.php');
+
include(SERVER_ROOT.'/sections/torrents/functions.php');
// The "order by x" links on columns headers
@@ -525,7 +525,7 @@ function header_link($SortKey,$DefaultWay="desc") {
die();
}
-$Bookmarks = all_bookmarks('torrent');
+$Bookmarks = Bookmarks::all_bookmarks('torrent');
$JsonGroups = array();
foreach ($Results as $Result) {
diff --git a/sections/ajax/request.php b/sections/ajax/request.php
index 3c5c39a9..a6916d6d 100644
--- a/sections/ajax/request.php
+++ b/sections/ajax/request.php
@@ -13,7 +13,7 @@
include(SERVER_ROOT.'/sections/requests/functions.php');
-include(SERVER_ROOT.'/sections/bookmarks/functions.php'); // has_bookmarked()
+ // Bookmarks::has_bookmarked()
include(SERVER_ROOT.'/classes/class_text.php');
$Text = new TEXT;
diff --git a/sections/ajax/torrentgroup.php b/sections/ajax/torrentgroup.php
index f90dd0b1..95be7ccd 100644
--- a/sections/ajax/torrentgroup.php
+++ b/sections/ajax/torrentgroup.php
@@ -2,7 +2,7 @@
require(SERVER_ROOT.'/sections/torrents/functions.php');
-include(SERVER_ROOT.'/sections/bookmarks/functions.php');
+
include(SERVER_ROOT.'/classes/class_text.php'); // Text formatting class
$Text = new TEXT;
@@ -51,7 +51,7 @@
'categoryName' => $CategoryName,
'time' => $TorrentDetails['Time'],
'vanityHouse' => $TorrentDetails['VanityHouse'] == 1,
- 'isBookmarked' => has_bookmarked('torrent', $GroupID),
+ 'isBookmarked' => Bookmarks::has_bookmarked('torrent', $GroupID),
'musicInfo' => $JsonMusicInfo
);
diff --git a/sections/artist/artist.php b/sections/artist/artist.php
index 4d4de07e..63421e60 100644
--- a/sections/artist/artist.php
+++ b/sections/artist/artist.php
@@ -6,7 +6,7 @@ function compare($X, $Y){
return($Y['count'] - $X['count']);
}
-include(SERVER_ROOT.'/sections/bookmarks/functions.php'); // has_bookmarked()
+ // Bookmarks::has_bookmarked()
include(SERVER_ROOT.'/classes/class_text.php'); // Text formatting class
$Text = new TEXT;
@@ -383,7 +383,13 @@ function compare($X, $Y){
endif; ?>
-
=$DisplayName?>
+
=$DisplayName?>
+ if (Bookmarks::has_bookmarked('torrent', $GroupID)) {
+ echo "
Unbookmark";
+ } else {
+ echo "
Bookmark";
+ } ?>
+
=$TorrentTags->format()?>
@@ -475,7 +481,7 @@ function compare($X, $Y){
}
}
-if (has_bookmarked('artist', $ArtistID)) {
+if (Bookmarks::has_bookmarked('artist', $ArtistID)) {
?>
Remove bookmark
diff --git a/sections/bookmarks/add.php b/sections/bookmarks/add.php
index 82993de8..bf9e4dd6 100644
--- a/sections/bookmarks/add.php
+++ b/sections/bookmarks/add.php
@@ -4,13 +4,13 @@
authorize();
-if (!can_bookmark($_GET['type'])) { error(404); }
+if (!Bookmarks::can_bookmark($_GET['type'])) { error(404); }
$Feed = new FEED;
$Text = new TEXT;
$Type = $_GET['type'];
-list($Table, $Col) = bookmark_schema($Type);
+list($Table, $Col) = Bookmarks::bookmark_schema($Type);
if(!is_number($_GET['id'])) {
error(0);
diff --git a/sections/bookmarks/artists.php b/sections/bookmarks/artists.php
index 7e9bef96..b8fbc620 100644
--- a/sections/bookmarks/artists.php
+++ b/sections/bookmarks/artists.php
@@ -15,7 +15,7 @@
$Sneaky = ($UserID != $LoggedUser['ID']);
-//$ArtistList = all_bookmarks('artist', $UserID);
+//$ArtistList = Bookmarks::all_bookmarks('artist', $UserID);
$DB->query('SELECT ag.ArtistID, ag.Name
FROM bookmarks_artists AS ba
diff --git a/sections/bookmarks/functions.php b/sections/bookmarks/functions.php
deleted file mode 100644
index 33d033e5..00000000
--- a/sections/bookmarks/functions.php
+++ /dev/null
@@ -1,44 +0,0 @@
-
-
-function can_bookmark($Type) {
- return in_array($Type, array('torrent', 'artist', 'collage', 'request'));
-}
-
-// Recommended usage:
-// list($Table, $Col) = bookmark_schema('torrent');
-function bookmark_schema($Type) {
- switch ($Type) {
- case 'torrent':
- return array('bookmarks_torrents', 'GroupID');
- break;
- case 'artist':
- return array('bookmarks_artists', 'ArtistID');
- break;
- case 'collage':
- return array('bookmarks_collages', 'CollageID');
- break;
- case 'request':
- return array('bookmarks_requests', 'RequestID');
- break;
- default:
- die('HAX');
- }
-}
-
-function has_bookmarked($Type, $ID) {
- return in_array($ID, all_bookmarks($Type));
-}
-
-function all_bookmarks($Type, $UserID = false) {
- global $DB, $Cache, $LoggedUser;
- if ($UserID === false) { $UserID = $LoggedUser['ID']; }
- $CacheKey = 'bookmarks_'.$Type.'_'.$UserID;
- if(($Bookmarks = $Cache->get_value($CacheKey)) === FALSE) {
- list($Table, $Col) = bookmark_schema($Type);
- $DB->query("SELECT $Col FROM $Table WHERE UserID = '$UserID'");
- $Bookmarks = $DB->collect($Col);
- $Cache->cache_value($CacheKey, $Bookmarks, 0);
- }
- return $Bookmarks;
-}
-?>
diff --git a/sections/bookmarks/index.php b/sections/bookmarks/index.php
index f1ca59f3..aaf02c2b 100644
--- a/sections/bookmarks/index.php
+++ b/sections/bookmarks/index.php
@@ -1,6 +1,6 @@
enforce_login();
-include(SERVER_ROOT.'/sections/bookmarks/functions.php');
+
// Number of users per page
define('BOOKMARKS_PER_PAGE', '20');
diff --git a/sections/bookmarks/mass_edit.php b/sections/bookmarks/mass_edit.php
index a9653abc..2c150760 100644
--- a/sections/bookmarks/mass_edit.php
+++ b/sections/bookmarks/mass_edit.php
@@ -2,7 +2,7 @@
authorize();
-if ($UserID != $LoggedUser['ID'] || !can_bookmark('torrent')) error(403);
+if ($UserID != $LoggedUser['ID'] || !Bookmarks::can_bookmark('torrent')) error(403);
if ($_POST['type'] === 'torrents') {
// require_once SERVER_ROOT.'/classes/class_mass_user_bookmarks_editor.php'; //Bookmark Updater Class
diff --git a/sections/bookmarks/remove.php b/sections/bookmarks/remove.php
index 313afaa0..934110eb 100644
--- a/sections/bookmarks/remove.php
+++ b/sections/bookmarks/remove.php
@@ -1,11 +1,11 @@
authorize();
-if (!can_bookmark($_GET['type'])) { error(404); }
+if (!Bookmarks::can_bookmark($_GET['type'])) { error(404); }
$Type = $_GET['type'];
-list($Table, $Col) = bookmark_schema($Type);
+list($Table, $Col) = Bookmarks::bookmark_schema($Type);
if(!is_number($_GET['id'])) {
error(0);
diff --git a/sections/collages/collage.php b/sections/collages/collage.php
index 0565a556..5a01361e 100644
--- a/sections/collages/collage.php
+++ b/sections/collages/collage.php
@@ -7,7 +7,7 @@ function compare($X, $Y){
return($Y['count'] - $X['count']);
}
-include(SERVER_ROOT.'/sections/bookmarks/functions.php'); // has_bookmarked()
+ // Bookmarks::has_bookmarked()
include(SERVER_ROOT.'/classes/class_text.php'); // Text formatting class
$Text = new TEXT;
@@ -340,7 +340,7 @@ function compare($X, $Y){
} else { ?>
Locked
}
- if(has_bookmarked('collage', $CollageID)) {
+ if(Bookmarks::has_bookmarked('collage', $CollageID)) {
?>
Remove bookmark
} else { ?>
diff --git a/sections/requests/request.php b/sections/requests/request.php
index 2ee6471f..9a4d07d0 100644
--- a/sections/requests/request.php
+++ b/sections/requests/request.php
@@ -4,7 +4,7 @@
* This is the page that displays the request to the end user after being created.
*/
-include(SERVER_ROOT.'/sections/bookmarks/functions.php'); // has_bookmarked()
+ // Bookmarks::has_bookmarked()
include(SERVER_ROOT.'/classes/class_text.php');
$Text = new TEXT;
@@ -93,7 +93,7 @@
if($UserCanEdit || check_perms('users_mod')) { //check_perms('site_moderate_requests')) { ?>
Delete
} ?>
- if(has_bookmarked('request', $RequestID)) { ?>
+ if(Bookmarks::has_bookmarked('request', $RequestID)) { ?>
Remove bookmark
} else { ?>
Bookmark
diff --git a/sections/top10/torrents.php b/sections/top10/torrents.php
index 6d910807..dea437c3 100644
--- a/sections/top10/torrents.php
+++ b/sections/top10/torrents.php
@@ -1,5 +1,5 @@
-include(SERVER_ROOT.'/sections/bookmarks/functions.php'); // has_bookmarked()
+ // Bookmarks::has_bookmarked()
$Where = array();
@@ -420,7 +420,7 @@ function generate_torrent_table($Caption, $Tag, $Details, $Limit) {
$Format,$Encoding,$Media,$Scene,$HasLog,$HasCue,$LogScore,$Year,$GroupYear,
$RemasterTitle,$Snatched,$Seeders,$Leechers,$Data,$ReleaseType,$Size) = $Detail;
- $IsBookmarked = has_bookmarked('torrent', $GroupID);
+ $IsBookmarked = Bookmarks::has_bookmarked('torrent', $GroupID);
$IsSnatched = Torrents::has_snatched($TorrentID);
// highlight every other row
diff --git a/sections/top10/votes.php b/sections/top10/votes.php
index ed24e5a6..e38a5bcc 100644
--- a/sections/top10/votes.php
+++ b/sections/top10/votes.php
@@ -1,7 +1,7 @@
// We need these to do our rankification
include(SERVER_ROOT.'/sections/torrents/ranking_funcs.php');
-include(SERVER_ROOT.'/sections/bookmarks/functions.php');
+
$UserVotes = Votes::get_user_votes($LoggedUser['ID']);
@@ -125,7 +125,7 @@
}
-$Bookmarks = all_bookmarks('torrent');
+$Bookmarks = Bookmarks::all_bookmarks('torrent');
?>
Top =$Limit.' '.$Caption?>
diff --git a/sections/torrents/browse2.php b/sections/torrents/browse2.php
index 596312a0..79bb4f07 100644
--- a/sections/torrents/browse2.php
+++ b/sections/torrents/browse2.php
@@ -20,7 +20,7 @@
*
*************************************************************************/
-include(SERVER_ROOT.'/sections/bookmarks/functions.php');
+
include(SERVER_ROOT.'/sections/torrents/functions.php');
@@ -871,7 +871,7 @@ function header_link($SortKey,$DefaultWay="desc") {
// List of pages
$Pages = Format::get_pages($Page, $TorrentCount, TORRENTS_PER_PAGE);
-$Bookmarks = all_bookmarks('torrent');
+$Bookmarks = Bookmarks::all_bookmarks('torrent');
?>
=$Pages?>
diff --git a/sections/torrents/details.php b/sections/torrents/details.php
index 30c7d94f..6c69f823 100644
--- a/sections/torrents/details.php
+++ b/sections/torrents/details.php
@@ -7,7 +7,7 @@ function compare($X, $Y){
define('MAX_PERS_COLLAGES', 3); // How many personal collages should be shown by default
define('MAX_COLLAGES', 5); // How many normal collages should be shown by default
-include(SERVER_ROOT.'/sections/bookmarks/functions.php'); // has_bookmarked()
+ // Bookmarks::has_bookmarked()
include(SERVER_ROOT.'/classes/class_text.php');
$Text = NEW TEXT;
@@ -93,7 +93,7 @@ function compare($X, $Y){
if($RevisionID && check_perms('site_edit_wiki')) { ?>
Revert to this revision
}
- if(has_bookmarked('torrent', $GroupID)) {
+ if(Bookmarks::has_bookmarked('torrent', $GroupID)) {
?>
Unbookmark
} else { ?>