forked from Cavemanon/cavepaintings
PSR-2. I'm not a huge fan, but ugly consistency beats no consistency...
This commit is contained in:
@@ -1,284 +1,314 @@
|
||||
<?php
|
||||
class AjaxCall {
|
||||
class AjaxCall
|
||||
{
|
||||
public $reqType;
|
||||
public $updates;
|
||||
|
||||
public $reqType;
|
||||
public $updates;
|
||||
public function AjaxCall($log = null)
|
||||
{
|
||||
header('Content-type: application/json');
|
||||
session_start();
|
||||
|
||||
if (isset($log)) {
|
||||
$_SESSION['yLog'] = $log;
|
||||
}
|
||||
|
||||
$this->reqType = $_POST['reqType'];
|
||||
}
|
||||
|
||||
function AjaxCall($log = null) {
|
||||
header('Content-type: application/json');
|
||||
session_start();
|
||||
|
||||
if (isset($log)) $_SESSION['yLog'] = $log;
|
||||
|
||||
$this->reqType = $_POST['reqType'];
|
||||
}
|
||||
public function process()
|
||||
{
|
||||
switch ($this->reqType) {
|
||||
case 'init':
|
||||
|
||||
function process() {
|
||||
switch($this->reqType) {
|
||||
case 'init':
|
||||
$this->initSession();
|
||||
$this->sendFirstUpdates();
|
||||
break;
|
||||
|
||||
$this->initSession();
|
||||
$this->sendFirstUpdates();
|
||||
break;
|
||||
case 'post':
|
||||
$nickname = $_POST['nickname'];
|
||||
$message = $_POST['message'];
|
||||
cookie('yNickname', $nickname);
|
||||
$ys = ys($_SESSION['yLog']);
|
||||
|
||||
if ($ys->banned(ip())) {
|
||||
$this->sendBanned();
|
||||
break;
|
||||
}
|
||||
if ($post = $ys->post($nickname, $message)) {
|
||||
// To use $post somewheres later
|
||||
$this->sendUpdates();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'post':
|
||||
$nickname = $_POST['nickname'];
|
||||
$message = $_POST['message'];
|
||||
cookie('yNickname', $nickname);
|
||||
$ys = ys($_SESSION['yLog']);
|
||||
|
||||
if ($ys->banned(ip())) { $this->sendBanned(); break; }
|
||||
if ($post = $ys->post($nickname, $message)) {
|
||||
// To use $post somewheres later
|
||||
$this->sendUpdates();
|
||||
}
|
||||
break;
|
||||
case 'refresh':
|
||||
$ys = ys($_SESSION['yLog']);
|
||||
if ($ys->banned(ip())) {
|
||||
$this->sendBanned();
|
||||
break;
|
||||
}
|
||||
|
||||
$this->sendUpdates();
|
||||
break;
|
||||
|
||||
case 'refresh':
|
||||
$ys = ys($_SESSION['yLog']);
|
||||
if ($ys->banned(ip())) { $this->sendBanned(); break; }
|
||||
|
||||
$this->sendUpdates();
|
||||
break;
|
||||
case 'reload':
|
||||
$this->reload();
|
||||
break;
|
||||
|
||||
case 'ban':
|
||||
$this->doBan();
|
||||
break;
|
||||
|
||||
case 'reload':
|
||||
$this->reload();
|
||||
break;
|
||||
|
||||
case 'ban':
|
||||
$this->doBan();
|
||||
break;
|
||||
case 'unban':
|
||||
$this->doUnban();
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$this->doDelete();
|
||||
break;
|
||||
|
||||
case 'unban':
|
||||
$this->doUnban();
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$this->doDelete();
|
||||
break;
|
||||
case 'banself':
|
||||
$this->banSelf();
|
||||
break;
|
||||
|
||||
case 'banself':
|
||||
$this->banSelf();
|
||||
break;
|
||||
case 'unbanself':
|
||||
$this->unbanSelf();
|
||||
break;
|
||||
|
||||
case 'unbanself':
|
||||
$this->unbanSelf();
|
||||
break;
|
||||
case 'clearlog':
|
||||
$this->clearLog();
|
||||
break;
|
||||
|
||||
case 'clearlogs':
|
||||
$this->clearLogs();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
case 'clearlog':
|
||||
$this->clearLog();
|
||||
break;
|
||||
|
||||
case 'clearlogs':
|
||||
$this->clearLogs();
|
||||
break;
|
||||
}
|
||||
}
|
||||
public function doBan()
|
||||
{
|
||||
$ip = $_POST['ip'];
|
||||
$nickname = $_POST['nickname'];
|
||||
$send = [];
|
||||
$ys = ys($_SESSION['yLog']);
|
||||
|
||||
function doBan() {
|
||||
$ip = $_POST['ip'];
|
||||
$nickname = $_POST['nickname'];
|
||||
$send = array();
|
||||
$ys = ys($_SESSION['yLog']);
|
||||
switch (true) {
|
||||
case !loggedIn():
|
||||
$send['error'] = 'admin';
|
||||
break;
|
||||
case $ys->banned($ip):
|
||||
$send['error'] = 'already';
|
||||
break;
|
||||
default:
|
||||
$ys->ban($ip, $nickname);
|
||||
if ($ip == ip()) {
|
||||
$send['bannedSelf'] = true;
|
||||
}
|
||||
$send['error'] = false;
|
||||
}
|
||||
|
||||
switch(true) {
|
||||
case !loggedIn():
|
||||
$send['error'] = 'admin';
|
||||
break;
|
||||
case $ys->banned($ip):
|
||||
$send['error'] = 'already';
|
||||
break;
|
||||
default:
|
||||
$ys->ban($ip, $nickname);
|
||||
if ($ip == ip())
|
||||
$send['bannedSelf'] = true;
|
||||
$send['error'] = false;
|
||||
}
|
||||
echo json_encode($send);
|
||||
}
|
||||
|
||||
echo json_encode($send);
|
||||
}
|
||||
public function doUnban()
|
||||
{
|
||||
$ip = $_POST['ip'];
|
||||
$send = [];
|
||||
$ys = ys($_SESSION['yLog']);
|
||||
|
||||
function doUnban() {
|
||||
$ip = $_POST['ip'];
|
||||
$send = array();
|
||||
$ys = ys($_SESSION['yLog']);
|
||||
switch (true) {
|
||||
case !loggedIn():
|
||||
$send['error'] = 'admin';
|
||||
break;
|
||||
case !$ys->banned($ip):
|
||||
$send['error'] = 'already';
|
||||
break;
|
||||
default:
|
||||
$ys->unban($ip);
|
||||
$send['error'] = false;
|
||||
}
|
||||
|
||||
switch(true) {
|
||||
case !loggedIn():
|
||||
$send['error'] = 'admin';
|
||||
break;
|
||||
case !$ys->banned($ip):
|
||||
$send['error'] = 'already';
|
||||
break;
|
||||
default:
|
||||
$ys->unban($ip);
|
||||
$send['error'] = false;
|
||||
}
|
||||
echo json_encode($send);
|
||||
}
|
||||
|
||||
echo json_encode($send);
|
||||
}
|
||||
public function doDelete()
|
||||
{
|
||||
$uid = $_POST['uid'];
|
||||
$send = [];
|
||||
$ys = ys($_SESSION['yLog']);
|
||||
|
||||
function doDelete() {
|
||||
$uid = $_POST['uid'];
|
||||
$send = array();
|
||||
$ys = ys($_SESSION['yLog']);
|
||||
switch (true) {
|
||||
case !loggedIn():
|
||||
$send['error'] = 'admin';
|
||||
break;
|
||||
default:
|
||||
$ys->delete($uid);
|
||||
$send['error'] = false;
|
||||
}
|
||||
|
||||
switch(true) {
|
||||
case !loggedIn():
|
||||
$send['error'] = 'admin';
|
||||
break;
|
||||
default:
|
||||
$ys->delete($uid);
|
||||
$send['error'] = false;
|
||||
}
|
||||
echo json_encode($send);
|
||||
}
|
||||
|
||||
echo json_encode($send);
|
||||
}
|
||||
public function banSelf()
|
||||
{
|
||||
$ys = ys($_SESSION['yLog']);
|
||||
$nickname = $_POST['nickname'];
|
||||
$ys->ban(ip(), $nickname);
|
||||
|
||||
function banSelf() {
|
||||
$ys = ys($_SESSION['yLog']);
|
||||
$nickname = $_POST['nickname'];
|
||||
$ys->ban(ip(), $nickname);
|
||||
$send = [];
|
||||
$send['error'] = false;
|
||||
|
||||
echo json_encode($send);
|
||||
}
|
||||
|
||||
$send = array();
|
||||
$send['error'] = false;
|
||||
|
||||
echo json_encode($send);
|
||||
}
|
||||
public function unbanSelf()
|
||||
{
|
||||
if (loggedIn()) {
|
||||
$ys = ys($_SESSION['yLog']);
|
||||
$ys->unban(ip());
|
||||
|
||||
$send = [];
|
||||
$send['error'] = false;
|
||||
} else {
|
||||
$send = [];
|
||||
$send['error'] = 'admin';
|
||||
}
|
||||
|
||||
echo json_encode($send);
|
||||
}
|
||||
|
||||
public function reload()
|
||||
{
|
||||
global $prefs;
|
||||
$ys = ys($_SESSION['yLog']);
|
||||
|
||||
function unbanSelf() {
|
||||
if (loggedIn()) {
|
||||
$ys = ys($_SESSION['yLog']);
|
||||
$ys->unban(ip());
|
||||
|
||||
$send = array();
|
||||
$send['error'] = false;
|
||||
} else {
|
||||
$send = array();
|
||||
$send['error'] = 'admin';
|
||||
}
|
||||
|
||||
echo json_encode($send);
|
||||
}
|
||||
|
||||
function reload() {
|
||||
global $prefs;
|
||||
$ys = ys($_SESSION['yLog']);
|
||||
$posts = $ys->latestPosts($prefs['truncate']);
|
||||
$this->setSessTimestamp($posts);
|
||||
$this->updates['posts'] = $posts;
|
||||
echo json_encode($this->updates);
|
||||
}
|
||||
|
||||
$posts = $ys->latestPosts($prefs['truncate']);
|
||||
$this->setSessTimestamp($posts);
|
||||
$this->updates['posts'] = $posts;
|
||||
echo json_encode($this->updates);
|
||||
}
|
||||
public function initSession()
|
||||
{
|
||||
$_SESSION['yLatestTimestamp'] = 0;
|
||||
$_SESSION['yYPath'] = $_POST['yPath'];
|
||||
$_SESSION['yLog'] = $_POST['log'];
|
||||
$loginHash = cookieGet('yLoginHash') ;
|
||||
if (isset($loginHash) && $loginHash != '') {
|
||||
login($loginHash);
|
||||
}
|
||||
}
|
||||
|
||||
function initSession() {
|
||||
$_SESSION['yLatestTimestamp'] = 0;
|
||||
$_SESSION['yYPath'] = $_POST['yPath'];
|
||||
$_SESSION['yLog'] = $_POST['log'];
|
||||
$loginHash = cookieGet('yLoginHash') ;
|
||||
if (isset($loginHash) && $loginHash != '') {
|
||||
login($loginHash);
|
||||
}
|
||||
}
|
||||
public function sendBanned()
|
||||
{
|
||||
$this->updates = [
|
||||
'banned' => true
|
||||
];
|
||||
|
||||
function sendBanned() {
|
||||
$this->updates = array(
|
||||
'banned' => true
|
||||
);
|
||||
echo json_encode($this->updates);
|
||||
}
|
||||
|
||||
public function sendUpdates()
|
||||
{
|
||||
global $prefs;
|
||||
$ys = ys($_SESSION['yLog']);
|
||||
if (!$ys->hasPostsAfter($_SESSION['yLatestTimestamp'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo json_encode($this->updates);
|
||||
}
|
||||
|
||||
function sendUpdates() {
|
||||
global $prefs;
|
||||
$ys = ys($_SESSION['yLog']);
|
||||
if (!$ys->hasPostsAfter($_SESSION['yLatestTimestamp'])) return;
|
||||
$posts = $ys->postsAfter($_SESSION['yLatestTimestamp']);
|
||||
$this->setSessTimestamp($posts);
|
||||
|
||||
$posts = $ys->postsAfter($_SESSION['yLatestTimestamp']);
|
||||
$this->setSessTimestamp($posts);
|
||||
$this->updates['posts'] = $posts;
|
||||
|
||||
$this->updates['posts'] = $posts;
|
||||
echo json_encode($this->updates);
|
||||
}
|
||||
|
||||
echo json_encode($this->updates);
|
||||
}
|
||||
public function setSessTimestamp(&$posts)
|
||||
{
|
||||
if (!$posts) {
|
||||
return;
|
||||
}
|
||||
|
||||
function setSessTimestamp(&$posts) {
|
||||
if (!$posts) return;
|
||||
$latest = array_slice($posts, -1, 1);
|
||||
$_SESSION['yLatestTimestamp'] = $latest[0]['timestamp'];
|
||||
}
|
||||
|
||||
$latest = array_slice( $posts, -1, 1);
|
||||
$_SESSION['yLatestTimestamp'] = $latest[0]['timestamp'];
|
||||
}
|
||||
public function sendFirstUpdates()
|
||||
{
|
||||
global $prefs, $overrideNickname;
|
||||
|
||||
function sendFirstUpdates() {
|
||||
global $prefs, $overrideNickname;
|
||||
$this->updates = [];
|
||||
|
||||
$this->updates = array();
|
||||
$ys = ys($_SESSION['yLog']);
|
||||
|
||||
$ys = ys($_SESSION['yLog']);
|
||||
$posts = $ys->latestPosts($prefs['truncate']);
|
||||
$this->setSessTimestamp($posts);
|
||||
|
||||
$posts = $ys->latestPosts($prefs['truncate']);
|
||||
$this->setSessTimestamp($posts);
|
||||
$this->updates['posts'] = $posts;
|
||||
$this->updates['prefs'] = $this->cleanPrefs($prefs);
|
||||
|
||||
$this->updates['posts'] = $posts;
|
||||
$this->updates['prefs'] = $this->cleanPrefs($prefs);
|
||||
if ($nickname = cookieGet('yNickname')) {
|
||||
$this->updates['nickname'] = $nickname;
|
||||
}
|
||||
|
||||
if ($overrideNickname) {
|
||||
$this->updates['nickname'] = $overrideNickname;
|
||||
}
|
||||
|
||||
if ($ys->banned(ip())) {
|
||||
$this->updates['banned'] = true;
|
||||
}
|
||||
|
||||
if ($nickname = cookieGet('yNickname'))
|
||||
$this->updates['nickname'] = $nickname;
|
||||
|
||||
if ($overrideNickname)
|
||||
$this->updates['nickname'] = $overrideNickname;
|
||||
|
||||
if ($ys->banned(ip()))
|
||||
$this->updates['banned'] = true;
|
||||
echo json_encode($this->updates);
|
||||
}
|
||||
|
||||
public function cleanPrefs($prefs)
|
||||
{
|
||||
unset($prefs['password']);
|
||||
return $prefs;
|
||||
}
|
||||
|
||||
public function clearLog()
|
||||
{
|
||||
//$log = $_POST['log'];
|
||||
$send = [];
|
||||
$ys = ys($_SESSION['yLog']);
|
||||
|
||||
echo json_encode($this->updates);
|
||||
}
|
||||
|
||||
function cleanPrefs($prefs) {
|
||||
unset($prefs['password']);
|
||||
return $prefs;
|
||||
}
|
||||
|
||||
function clearLog() {
|
||||
//$log = $_POST['log'];
|
||||
$send = array();
|
||||
$ys = ys($_SESSION['yLog']);
|
||||
switch (true) {
|
||||
case !loggedIn():
|
||||
$send['error'] = 'admin';
|
||||
break;
|
||||
default:
|
||||
$ys->clear();
|
||||
$send['error'] = false;
|
||||
}
|
||||
|
||||
switch(true) {
|
||||
case !loggedIn():
|
||||
$send['error'] = 'admin';
|
||||
break;
|
||||
default:
|
||||
$ys->clear();
|
||||
$send['error'] = false;
|
||||
}
|
||||
echo json_encode($send);
|
||||
}
|
||||
|
||||
public function clearLogs()
|
||||
{
|
||||
global $prefs;
|
||||
|
||||
//$log = $_POST['log'];
|
||||
$send = [];
|
||||
|
||||
echo json_encode($send);
|
||||
}
|
||||
|
||||
function clearLogs() {
|
||||
global $prefs;
|
||||
|
||||
//$log = $_POST['log'];
|
||||
$send = array();
|
||||
|
||||
//$ys = ys($_SESSION['yLog']);
|
||||
|
||||
switch(true) {
|
||||
case !loggedIn():
|
||||
$send['error'] = 'admin';
|
||||
break;
|
||||
default:
|
||||
for ($i = 1; $i <= $prefs['logs']; $i++) {
|
||||
$ys = ys($i);
|
||||
$ys->clear();
|
||||
}
|
||||
|
||||
$send['error'] = false;
|
||||
}
|
||||
|
||||
echo json_encode($send);
|
||||
}
|
||||
}
|
||||
//$ys = ys($_SESSION['yLog']);
|
||||
|
||||
switch (true) {
|
||||
case !loggedIn():
|
||||
$send['error'] = 'admin';
|
||||
break;
|
||||
default:
|
||||
for ($i = 1; $i <= $prefs['logs']; $i++) {
|
||||
$ys = ys($i);
|
||||
$ys->clear();
|
||||
}
|
||||
|
||||
$send['error'] = false;
|
||||
}
|
||||
|
||||
echo json_encode($send);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user