Gazelle/sections/tools/managers/recommend_add.php

39 lines
1.2 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
//******************************************************************************//
//--------------- Add a recommendation -----------------------------------------//
authorize();
2013-05-02 08:00:23 +00:00
if (!check_perms('site_recommend_own') && !check_perms('site_manage_recommendations')) {
2011-03-28 14:21:28 +00:00
error(403);
}
$URL = trim($_POST['url']);
// Make sure the URL they entered is on our site, and is a link to a torrent
$URLRegex = '/^https?:\/\/(www\.|ssl\.)?'.NONSSL_SITE_URL.'\/torrents\.php\?id=([0-9]+)$/i';
$Val->SetFields('url',
'1','regex','The URL must be a link to a torrent on the site.',array('regex'=>$URLRegex));
$Err = $Val->ValidateForm($_POST); // Validate the form
2013-05-02 08:00:23 +00:00
if ($Err) { // if something didn't validate
2011-03-28 14:21:28 +00:00
error($Err);
header('Location: '.$_SERVER['HTTP_REFERER']);
exit;
}
// Get torrent ID
$URLRegex = '/torrents\.php\?id=([0-9]+)$/i';
preg_match($URLRegex, $URL, $Matches);
2013-05-02 08:00:23 +00:00
$GroupID = $Matches[1];
2013-05-02 08:00:23 +00:00
if (empty($GroupID) || !is_number($GroupID)) {
2013-02-22 08:00:24 +00:00
error(404);
}
2011-03-28 14:21:28 +00:00
$DB->query("INSERT INTO torrents_recommended (GroupID, UserID, Time) VALUES ('".db_string($GroupID)."', $LoggedUser[ID], '".sqltime()."')");
2012-10-11 08:00:15 +00:00
Torrents::freeleech_groups($GroupID, 2, 3);
2011-03-28 14:21:28 +00:00
$Cache->delete_value('recommend');
header('Location: '.$_SERVER['HTTP_REFERER']);
?>