mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2026-04-01 09:35:28 +00:00
implement comments, init magnet page
This commit is contained in:
parent
fc5617846d
commit
123b08823d
9 changed files with 839 additions and 8 deletions
|
|
@ -29,6 +29,246 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false)
|
|||
{
|
||||
case 'comment':
|
||||
|
||||
switch (isset($_GET['toggle']) ? $_GET['toggle'] : false)
|
||||
{
|
||||
case 'approved':
|
||||
|
||||
// Yggdrasil connections only
|
||||
if (!preg_match(YGGDRASIL_URL_REGEX, $_SERVER['REMOTE_ADDR']))
|
||||
{
|
||||
$response->success = false;
|
||||
$response->message = _('Yggdrasil connection required for this action');
|
||||
}
|
||||
|
||||
// Init session
|
||||
else if (!$userId = $db->initUserId($_SERVER['REMOTE_ADDR'], USER_DEFAULT_APPROVED, time()))
|
||||
{
|
||||
$response->success = false;
|
||||
$response->message = _('Could not init user session');
|
||||
}
|
||||
|
||||
// Get user
|
||||
else if (!$user = $db->getUser($userId))
|
||||
{
|
||||
$response->success = false;
|
||||
$response->message = _('Could not init user info');
|
||||
}
|
||||
|
||||
// Magnet comment exists
|
||||
else if (!$magnetComment = $db->getMagnetComment(isset($_GET['magnetCommentId']) && $_GET['magnetCommentId'] > 0 ? (int) $_GET['magnetCommentId'] : 0))
|
||||
{
|
||||
$response->success = false;
|
||||
$response->message = _('Requested magnet comment not found');
|
||||
}
|
||||
|
||||
// Access allowed
|
||||
else if (!in_array($user->address, MODERATOR_IP_LIST)) {
|
||||
|
||||
$response->success = false;
|
||||
$response->message = _('Access denied');
|
||||
}
|
||||
|
||||
// Validate callback
|
||||
else if (empty($_GET['callback']))
|
||||
{
|
||||
$response->success = false;
|
||||
$response->message = _('Callback required');
|
||||
}
|
||||
|
||||
// Validate base64
|
||||
else if (!$callback = (string) @base64_decode($_GET['callback']))
|
||||
{
|
||||
$response->success = false;
|
||||
$response->message = _('Invalid callback encoding');
|
||||
}
|
||||
|
||||
// Request valid
|
||||
else
|
||||
{
|
||||
if ($magnetComment->approved)
|
||||
{
|
||||
$db->updateMagnetCommentApproved($magnetComment->magnetCommentId, false);
|
||||
|
||||
if (USER_AUTO_APPROVE_ON_COMMENT_APPROVE)
|
||||
{
|
||||
$db->updateUserApproved($magnetComment->userId, false, time());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->updateMagnetCommentApproved($magnetComment->magnetCommentId, true);
|
||||
|
||||
if (USER_AUTO_APPROVE_ON_COMMENT_APPROVE)
|
||||
{
|
||||
$db->updateUserApproved($magnetComment->userId, true, time());
|
||||
}
|
||||
}
|
||||
|
||||
// Redirect to edit page
|
||||
header(
|
||||
sprintf('Location: %s', $callback)
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'public':
|
||||
|
||||
// Yggdrasil connections only
|
||||
if (!preg_match(YGGDRASIL_URL_REGEX, $_SERVER['REMOTE_ADDR']))
|
||||
{
|
||||
$response->success = false;
|
||||
$response->message = _('Yggdrasil connection required for this action');
|
||||
}
|
||||
|
||||
// Init session
|
||||
else if (!$userId = $db->initUserId($_SERVER['REMOTE_ADDR'], USER_DEFAULT_APPROVED, time()))
|
||||
{
|
||||
$response->success = false;
|
||||
$response->message = _('Could not init user session');
|
||||
}
|
||||
|
||||
// Get user
|
||||
else if (!$user = $db->getUser($userId))
|
||||
{
|
||||
$response->success = false;
|
||||
$response->message = _('Could not init user info');
|
||||
}
|
||||
|
||||
// Magnet comment exists
|
||||
else if (!$magnetComment = $db->getMagnetComment(isset($_GET['magnetCommentId']) && $_GET['magnetCommentId'] > 0 ? (int) $_GET['magnetCommentId'] : 0))
|
||||
{
|
||||
$response->success = false;
|
||||
$response->message = _('Requested magnet comment not found');
|
||||
}
|
||||
|
||||
// Access allowed
|
||||
else if (!($user->address == $db->getUser($magnetComment->userId)->address || in_array($user->address, MODERATOR_IP_LIST))) {
|
||||
|
||||
$response->success = false;
|
||||
$response->message = _('Access denied');
|
||||
}
|
||||
|
||||
// Validate callback
|
||||
else if (empty($_GET['callback']))
|
||||
{
|
||||
$response->success = false;
|
||||
$response->message = _('Callback required');
|
||||
}
|
||||
|
||||
// Validate base64
|
||||
else if (!$callback = (string) @base64_decode($_GET['callback']))
|
||||
{
|
||||
$response->success = false;
|
||||
$response->message = _('Invalid callback encoding');
|
||||
}
|
||||
|
||||
// Request valid
|
||||
else
|
||||
{
|
||||
if ($magnetComment->public)
|
||||
{
|
||||
$db->updateMagnetCommentPublic($magnetComment->magnetCommentId, false);
|
||||
}
|
||||
else{
|
||||
$db->updateMagnetCommentPublic($magnetComment->magnetCommentId, true);
|
||||
}
|
||||
|
||||
// Redirect to edit page
|
||||
header(
|
||||
sprintf('Location: %s', $callback)
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'new':
|
||||
|
||||
// Yggdrasil connections only
|
||||
if (!preg_match(YGGDRASIL_URL_REGEX, $_SERVER['REMOTE_ADDR']))
|
||||
{
|
||||
$response->success = false;
|
||||
$response->message = _('Yggdrasil connection required for this action');
|
||||
}
|
||||
|
||||
// Init session
|
||||
else if (!$userId = $db->initUserId($_SERVER['REMOTE_ADDR'], USER_DEFAULT_APPROVED, time()))
|
||||
{
|
||||
$response->success = false;
|
||||
$response->message = _('Could not init user session');
|
||||
}
|
||||
|
||||
// Get user
|
||||
else if (!$user = $db->getUser($userId))
|
||||
{
|
||||
$response->success = false;
|
||||
$response->message = _('Could not init user info');
|
||||
}
|
||||
|
||||
// Magnet exists
|
||||
else if (!$magnet = $db->getMagnet(isset($_GET['magnetId']) && $_GET['magnetId'] > 0 ? (int) $_GET['magnetId'] : 0))
|
||||
{
|
||||
$response->success = false;
|
||||
$response->message = _('Requested magnet not found');
|
||||
}
|
||||
|
||||
// Access allowed
|
||||
else if (!($user->address == $db->getUser($magnet->userId)->address || in_array($user->address, MODERATOR_IP_LIST) || ($magnet->public && $magnet->approved))) {
|
||||
|
||||
$response->success = false;
|
||||
$response->message = _('Magnet not available for this action');
|
||||
}
|
||||
|
||||
// Validate callback
|
||||
else if (empty($_GET['callback']))
|
||||
{
|
||||
$response->success = false;
|
||||
$response->message = _('Callback required');
|
||||
}
|
||||
|
||||
// Validate base64
|
||||
else if (!$callback = (string) @base64_decode($_GET['callback']))
|
||||
{
|
||||
$response->success = false;
|
||||
$response->message = _('Invalid callback encoding');
|
||||
}
|
||||
|
||||
// Validate comment value
|
||||
else if (empty($_POST['comment']) ||
|
||||
mb_strlen($_POST['comment']) < COMMENT_MIN_LENGTH ||
|
||||
mb_strlen($_POST['comment']) > COMMENT_MAX_LENGTH)
|
||||
{
|
||||
$response->success = false;
|
||||
$response->message = sprintf(_('Valid comment value required, %s-%s chars allowed'), COMMENT_MIN_LENGTH, COMMENT_MAX_LENGTH);
|
||||
}
|
||||
|
||||
// Request valid
|
||||
else
|
||||
{
|
||||
if ($magnetCommentId = $db->addMagnetComment($magnet->magnetId,
|
||||
$user->userId,
|
||||
null, // @TODO implement threads
|
||||
trim($_POST['comment']),
|
||||
$user->approved || in_array($user->address, MODERATOR_IP_LIST) ? true : COMMENT_DEFAULT_APPROVED,
|
||||
COMMENT_DEFAULT_PUBLIC,
|
||||
time()))
|
||||
{
|
||||
// Redirect to referrer page
|
||||
header(
|
||||
sprintf('Location: %s#comment-%s', $callback, $magnetCommentId)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
header(
|
||||
sprintf('Location: %s', WEBSITE_URL)
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'star':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue