Gazelle/sections/ajax/index.php

180 lines
5.1 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
/*
AJAX Switch Center
2013-02-22 08:00:24 +00:00
This page acts as an AJAX "switch" - it's called by scripts, and it includes the required pages.
2011-03-28 14:21:28 +00:00
2013-02-22 08:00:24 +00:00
The required page is determined by $_GET['action'].
2011-03-28 14:21:28 +00:00
*/
enforce_login();
2013-02-04 08:00:13 +00:00
/* AJAX_LIMIT = array(x,y) = 'x' requests every 'y' seconds.
e.g. array(5,10) = 5 requests every 10 seconds */
$AJAX_LIMIT = array(5,10);
2013-07-14 08:00:49 +00:00
$LimitedPages = array('tcomments','user','forum','top10','browse','usersearch','requests','artist','inbox','subscriptions','bookmarks','announcements','notifications','request','better','similar_artists','userhistory','votefavorite','wiki','torrentgroup','news_ajax','user_recents', 'collage', 'raw_bbcode');
2013-06-22 08:01:03 +00:00
2013-06-20 08:01:00 +00:00
// These users aren't rate limited.
2013-06-22 08:01:03 +00:00
// This array should contain user IDs.
2013-06-20 08:01:00 +00:00
$UserExceptions = array(
2013-06-22 08:01:03 +00:00
2013-06-20 08:01:00 +00:00
);
$UserID = $LoggedUser['ID'];
header('Content-Type: application/json; charset=utf-8');
2013-02-04 08:00:13 +00:00
// Enforce rate limiting everywhere except info.php
2013-06-22 08:01:03 +00:00
if (!in_array($UserID, $UserExceptions) && isset($_GET['action']) && in_array($_GET['action'], $LimitedPages)) {
2013-08-14 08:00:46 +00:00
if (!$UserRequests = $Cache->get_value('ajax_requests_'.$UserID)) {
$UserRequests = 0;
2013-06-22 08:01:03 +00:00
$Cache->cache_value('ajax_requests_'.$UserID, '0', $AJAX_LIMIT[1]);
2013-02-04 08:00:13 +00:00
}
2013-08-14 08:00:46 +00:00
if ($UserRequests > $AJAX_LIMIT[0]) {
2013-04-24 08:00:23 +00:00
json_die("failure", "rate limit exceeded");
2013-02-04 08:00:13 +00:00
} else {
$Cache->increment_value('ajax_requests_'.$UserID);
}
}
2012-12-11 08:00:18 +00:00
switch ($_GET['action']) {
2011-08-25 08:00:11 +00:00
// things that (may be) used on the site
2011-03-28 14:21:28 +00:00
case 'upload_section':
// Gets one of the upload forms
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/upload.php');
2011-03-28 14:21:28 +00:00
break;
case 'preview':
require('preview.php');
break;
case 'torrent_info':
require('torrent_info.php');
break;
case 'stats':
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/stats.php');
2011-03-28 14:21:28 +00:00
break;
2013-05-16 16:15:57 +00:00
2012-06-05 08:00:11 +00:00
case 'checkprivate':
include('checkprivate.php');
break;
2011-08-25 08:00:11 +00:00
// things not yet used on the site
2013-04-24 08:00:23 +00:00
case 'torrent':
require('torrent.php');
break;
2011-08-25 08:00:11 +00:00
case 'torrentgroup':
require('torrentgroup.php');
break;
2013-02-04 08:00:13 +00:00
case 'torrentgroupalbumart': // so the album art script can function without breaking the ratelimit
require(SERVER_ROOT . '/sections/ajax/torrentgroupalbumart.php');
break;
2012-06-27 08:00:15 +00:00
case 'tcomments':
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/tcomments.php');
2012-06-27 08:00:15 +00:00
break;
2011-10-31 08:00:12 +00:00
case 'user':
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/user.php');
2011-10-31 08:00:12 +00:00
break;
case 'forum':
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/forum/index.php');
2011-10-31 08:00:12 +00:00
break;
2011-09-16 08:00:13 +00:00
case 'top10':
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/top10/index.php');
2011-09-16 08:00:13 +00:00
break;
2012-01-30 08:00:24 +00:00
case 'browse':
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/browse.php');
2012-02-04 08:00:25 +00:00
break;
2012-01-28 08:00:29 +00:00
case 'usersearch':
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/usersearch.php');
2012-01-28 08:00:29 +00:00
break;
2012-01-27 08:00:19 +00:00
case 'requests':
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/requests.php');
2012-02-04 08:00:25 +00:00
break;
case 'artist':
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/artist.php');
break;
case 'inbox':
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/inbox/index.php');
break;
case 'subscriptions':
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/subscriptions.php');
break;
case 'index':
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/info.php');
break;
2011-10-31 08:00:12 +00:00
case 'bookmarks':
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/bookmarks/index.php');
2011-10-31 08:00:12 +00:00
break;
2012-04-14 08:00:26 +00:00
case 'announcements':
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/announcements.php');
break;
2011-11-26 08:00:20 +00:00
case 'notifications':
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/notifications.php');
2011-11-26 08:00:20 +00:00
break;
2012-01-30 08:00:24 +00:00
case 'request':
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/request.php');
2012-01-30 08:00:24 +00:00
break;
2012-03-01 08:00:25 +00:00
case 'loadavg':
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/loadavg.php');
2012-03-01 08:00:25 +00:00
break;
2012-03-21 08:00:26 +00:00
case 'better':
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/better/index.php');
2012-03-21 08:00:26 +00:00
break;
2012-06-28 08:00:13 +00:00
case 'password_validate':
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/password_validate.php');
break;
2012-06-28 08:00:13 +00:00
case 'similar_artists':
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/similar_artists.php');
break;
2012-07-28 08:00:17 +00:00
case 'userhistory':
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/userhistory/index.php');
break;
2012-10-27 08:00:09 +00:00
case 'votefavorite':
2012-12-11 08:00:18 +00:00
require(SERVER_ROOT . '/sections/ajax/takevote.php');
break;
case 'wiki':
require(SERVER_ROOT . '/sections/ajax/wiki.php');
break;
2013-03-05 08:00:26 +00:00
case 'send_recommendation':
require(SERVER_ROOT . '/sections/ajax/send_recommendation.php');
break;
case 'get_friends':
require(SERVER_ROOT . '/sections/ajax/get_friends.php');
break;
2013-06-14 08:18:16 +00:00
case 'news_ajax':
require(SERVER_ROOT . '/sections/ajax/news_ajax.php');
break;
2013-06-17 08:01:02 +00:00
case 'community_stats':
require(SERVER_ROOT . '/sections/ajax/community_stats.php');
break;
2013-06-24 08:00:28 +00:00
case 'user_recents':
require(SERVER_ROOT . '/sections/ajax/user_recents.php');
break;
2013-07-04 08:00:56 +00:00
case 'collage':
require(SERVER_ROOT . '/sections/ajax/collage.php');
break;
2013-07-14 08:00:49 +00:00
case 'raw_bbcode':
require(SERVER_ROOT . '/sections/ajax/raw_bbcode.php');
break;
2013-08-28 23:08:41 +00:00
case 'get_user_notifications':
require(SERVER_ROOT . '/sections/ajax/get_user_notifications.php');
break;
case 'clear_user_notification':
require(SERVER_ROOT . '/sections/ajax/clear_user_notification.php');
break;
2014-03-31 08:01:19 +00:00
case 'pushbullet_devices':
require(SERVER_ROOT . '/sections/ajax/pushbullet_devices.php');
break;
2011-03-28 14:21:28 +00:00
default:
// If they're screwing around with the query string
2013-04-24 08:00:23 +00:00
json_die("failure");
2011-03-28 14:21:28 +00:00
}
2013-04-19 08:00:55 +00:00
function pullmediainfo($Array) {
2012-03-10 08:00:21 +00:00
$NewArray = array();
foreach ($Array as $Item) {
$NewArray[] = array(
2012-12-11 08:00:18 +00:00
'id' => (int)$Item['id'],
2012-03-10 08:00:21 +00:00
'name' => $Item['name']
);
}
return $NewArray;
}
2011-03-28 14:21:28 +00:00
?>