Gazelle/sections/userhistory/thread_subscribe.php

51 lines
1.4 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
// perform the back end of subscribing to topics
authorize();
2013-04-13 08:00:19 +00:00
if (!empty($LoggedUser['DisableForums'])) {
2011-03-28 14:21:28 +00:00
error(403);
}
2013-04-13 08:00:19 +00:00
if (!is_number($_GET['topicid'])) {
2011-03-28 14:21:28 +00:00
error(0);
}
2011-10-12 08:00:15 +00:00
require(SERVER_ROOT.'/sections/forums/index.php');
2013-07-04 08:00:56 +00:00
$DB->query('
SELECT ID
FROM forums
WHERE forums.ID =
(
SELECT ForumID
FROM forums_topics
WHERE ID = '.db_string($_GET['topicid']).'
)');
2011-10-12 08:00:15 +00:00
list($ForumID) = $DB->next_record();
2013-04-13 08:00:19 +00:00
if (!check_forumperm($ForumID)) {
2011-03-28 14:21:28 +00:00
die();
}
2013-04-13 08:00:19 +00:00
if (!$UserSubscriptions = $Cache->get_value('subscriptions_user_'.$LoggedUser['ID'])) {
2013-07-04 08:00:56 +00:00
$DB->query('
SELECT TopicID
FROM users_subscriptions
WHERE UserID = '.db_string($LoggedUser['ID']));
2011-03-28 14:21:28 +00:00
$UserSubscriptions = $DB->collect(0);
2013-07-04 08:00:56 +00:00
$Cache->cache_value('subscriptions_user_'.$LoggedUser['ID'], $UserSubscriptions, 0);
2011-03-28 14:21:28 +00:00
}
2013-07-04 08:00:56 +00:00
if (($Key = array_search($_GET['topicid'], $UserSubscriptions)) !== false) {
$DB->query('
DELETE FROM users_subscriptions
WHERE UserID = '.db_string($LoggedUser['ID']).'
AND TopicID = '.db_string($_GET['topicid']));
2011-03-28 14:21:28 +00:00
unset($UserSubscriptions[$Key]);
} else {
2013-07-04 08:00:56 +00:00
$DB->query("
INSERT IGNORE INTO users_subscriptions (UserID, TopicID)
VALUES ($LoggedUser[ID], ".db_string($_GET['topicid']).")");
2011-03-28 14:21:28 +00:00
array_push($UserSubscriptions, $_GET['topicid']);
}
$Cache->replace_value('subscriptions_user_'.$LoggedUser['ID'], $UserSubscriptions, 0);
$Cache->delete_value('subscriptions_user_new_'.$LoggedUser['ID']);