Gazelle/sections/userhistory/collage_subscribe.php

39 lines
1.2 KiB
PHP
Raw Normal View History

<?
// perform the back end of subscribing to collages
authorize();
2013-04-13 08:00:19 +00:00
if (!is_number($_GET['collageid'])) {
error(0);
}
2013-10-30 08:01:19 +00:00
$CollageID = (int)$_GET['collageid'];
2013-05-25 08:01:03 +00:00
2013-04-13 08:00:19 +00:00
if (!$UserSubscriptions = $Cache->get_value('collage_subs_user_'.$LoggedUser['ID'])) {
2013-07-04 08:00:56 +00:00
$DB->query('
SELECT CollageID
FROM users_collage_subs
WHERE UserID = '.db_string($LoggedUser['ID']));
$UserSubscriptions = $DB->collect(0);
2013-07-04 08:00:56 +00:00
$Cache->cache_value('collage_subs_user_'.$LoggedUser['ID'], $UserSubscriptions, 0);
}
2013-05-25 08:01:03 +00:00
if (($Key = array_search($CollageID, $UserSubscriptions)) !== false) {
2013-07-04 08:00:56 +00:00
$DB->query('
DELETE FROM users_collage_subs
WHERE UserID = '.db_string($LoggedUser['ID'])."
AND CollageID = $CollageID");
unset($UserSubscriptions[$Key]);
2013-05-25 08:01:03 +00:00
Collages::decrease_subscriptions($CollageID);
} else {
2013-07-04 08:00:56 +00:00
$DB->query("
INSERT IGNORE INTO users_collage_subs
(UserID, CollageID, LastVisit)
VALUES
($LoggedUser[ID], $CollageID, NOW())");
2013-05-25 08:01:03 +00:00
array_push($UserSubscriptions, $CollageID);
Collages::increase_subscriptions($CollageID);
}
$Cache->replace_value('collage_subs_user_'.$LoggedUser['ID'], $UserSubscriptions, 0);
$Cache->delete_value('collage_subs_user_new_'.$LoggedUser['ID']);
2013-07-04 08:00:56 +00:00
$Cache->delete_value("collage_$CollageID");