This commit is contained in:
Shish
2013-06-19 20:59:59 +01:00
parent a3486f9b29
commit 4a2c47459c
43 changed files with 5053 additions and 0 deletions

459
ext/chatbox/cp/ajax.php Normal file
View File

@@ -0,0 +1,459 @@
<?
error_reporting(E_ALL);
$kioskMode = false;
include '../php/filestorage.class.php';
include '../preferences.php';
include '../php/json.class.php';
include '../php/functions.php';
include '../php/yshout.class.php';
include '../php/ajaxcall.class.php';
if (isset($_POST['mode']))
switch($_POST['mode']) {
case 'login':
doLogin();
break;
case 'logout':
doLogout();
break;
case 'unban':
doUnban();
break;
case 'unbanall':
doUnbanAll();
break;
case 'setpreference':
doSetPreference();
break;
case 'resetpreferences':
doResetPreferences();
break;
}
function doLogin() {
global $kioskMode;
if ($kioskMode) {
logout();
$result = array(
'error' => false,
'html' => cp()
);
echo jsonEncode($result);
return;
}
login(md5($_POST['password']));
$result = array();
if (loggedIn()) {
$result['error'] = false;
$result['html'] = cp();
} else
$result['error'] = 'invalid';
echo jsonEncode($result);
}
function doLogout() {
logout();
$result = array(
'error' => false
);
echo jsonEncode($result);
}
function doUnban() {
global $kioskMode;
if ($kioskMode) {
$result = array(
'error' => false
);
echo jsonEncode($result);
return;
}
if (!loggedIn()) return;
$ys = ys();
$result = array();
$ip = $_POST['ip'];
if ($ys->banned($ip)) {
$ys->unban($ip);
$result['error'] = false;
} else
$result['error'] = 'notbanned';
echo jsonEncode($result);
}
function doUnbanAll() {
global $kioskMode;
if ($kioskMode) {
$result = array(
'error' => false
);
echo jsonEncode($result);
return;
}
if (!loggedIn()) return;
$ys = ys();
$ys->unbanAll();
$result = array(
'error' => false
);
echo jsonEncode($result);
}
function doSetPreference() {
global $prefs, $kioskMode;
if ($kioskMode) {
$result = array(
'error' => false
);
echo jsonEncode($result);
return;
}
if (!loggedIn()) return;
$pref = $_POST['preference'];
$value = magic($_POST['value']);
if ($value === 'true') $value = true;
if ($value === 'false') $value = false;
$prefs[$pref] = $value;
savePrefs($prefs);
if ($pref == 'password') login(md5($value));
$result = array(
'error' => false
);
echo jsonEncode($result);
}
function doResetPreferences() {
global $prefs, $kioskMode;
if ($kioskMode) {
$result = array(
'error' => false
);
echo jsonEncode($result);
return;
}
if (!loggedIn()) return;
resetPrefs();
login(md5($prefs['password']));
// $prefs['password'] = 'lol no';
$result = array(
'error' => false,
'prefs' => $prefs
);
echo jsonEncode($result);
}
/* CP Display */
function cp() {
global $kioskMode;
if (!loggedIn() && !$kioskMode) return 'You\'re not logged in!';
return '
<div class="section" id="preferences">
<span style="display: none;" id="cp-loaded">true</span>
<div class="header">
<h1>YShout.Preferences</h1>
<a href="#" class="logout">Logout</a>
</div>
<ul class="subnav">
<li id="sn-administration"><a href="#">Administration</a></li>
<li id="sn-display"><a href="#">Display</a></li>
<li id="sn-resetall"><a href="#">Reset All</a></li>
<span class="sn-loading">Loading...</span>
</ul>
' . preferencesForm() . '
</div>
<div class="section" id="about">
<div class="header">
<h1>YShout.About</h1>
<a href="#" class="logout">Logout</a>
</div>
<ul class="subnav">
<li id="sn-about"><a href="#">About</a></li>
<li id="sn-contact"><a href="#">Contact</a></li>
<span class="sn-loading">Loading...</span>
</ul>
' . about() . '
</div>
<div class="section" id="bans">
<div class="header">
<h1>YShout.Bans</h1>
<a href="#" class="logout">Logout</a>
</div>
<ul class="subnav">
<li id="sn-unbanall"><a href="#">Unban All</a></li>
<span class="sn-loading">Loading...</span>
</ul>
' . bansList() . '
</div>';
}
function bansList() {
global $kioskMode;
$ys = ys();
$bans = $ys->bans();
$html = '<ul id="bans-list">';
$hasBans = false;
foreach($bans as $ban) {
$hasBans = true;
$html .= '
<li>
<span class="nickname">' . $ban['nickname']. '</span>
(<span class="ip">' . ($kioskMode ? '[No IP in Kiosk Mode]' : $ban['ip']) . '</span>)
<a title="Unban" class="unban-link" href="#" rel="' . $ban['timestamp'] . '">Unban</a>
</li>
';
}
if (!$hasBans)
$html = '<p id="no-bans">No one is banned.</p>';
else
$html .= '</ul>';
return $html;
}
function preferencesForm() {
global $prefs, $kioskMode;
return '
<form id="preferences-form">
<div id="cp-pane-administration" class="cp-pane">
<fieldset id="prefs-cat-cp">
<div class="legend">Control Panel</div class="legend">
<ol>
<li>
<label for="pref-password">Password</label>
<input rel="password" type="text" id="pref-password" value="' . ($kioskMode ? 'No password in Kiosk Mode.' : $prefs['password']) . '" />
</li>
</ol>
</fieldset>
<fieldset id="prefs-cat-flood">
<div class="legend">Flood Control</div class="legend">
<ol>
<li>
<label for="pref-flood">Use flood control</label>
<select rel="flood" id="pref-flood">
<option' . ($prefs['flood'] == true ? ' selected' : '') . ' rel="true">Yes</option>
<option' . ($prefs['flood'] == false ? ' selected' : '') . ' rel="false">No</option>
</select>
</li>
<li>
<label for="pref-flood-timeout">Flood timeout</label>
<input rel="floodTimeout" type="text" id="pref-flood-timeout" value="' . $prefs['floodTimeout'] . '" />
</li>
<li>
<label for="pref-flood-messages">Flood messages</label>
<input rel="floodMessages" type="text" id="pref-flood-messages" value="' . $prefs['floodMessages'] . '" />
</li>
<li>
<label for="pref-flood-length">Flood length</label>
<input rel="floodDisable" type="text" id="pref-flood-length" value="' . $prefs['floodDisable'] . '" />
</li>
<li>
<label for="pref-flood-autoban">Automatically ban after</label>
<select rel="autobanFlood" id="pref-flood-autoban">
<option' . ($prefs['autobanFlood'] == 1 ? ' selected' : '') . ' rel="1">One activation</option>
<option' . ($prefs['autobanFlood'] == 2 ? ' selected' : '') . ' rel="2">Two activations</option>
<option' . ($prefs['autobanFlood'] == 3 ? ' selected' : '') . ' rel="3">Three activations</option>
<option' . ($prefs['autobanFlood'] == 4 ? ' selected' : '') . ' rel="4">Four activations</option>
<option' . ($prefs['autobanFlood'] == 5 ? ' selected' : '') . ' rel="5">Five activations</option>
<option' . ($prefs['autobanFlood'] == 0 ? ' selected' : '') . ' rel="false">Never</option>
</select>
</li>
</ol>
</fieldset>
<fieldset id="prefs-cat-history">
<div class="legend">History</div class="legend">
<ol>
<li>
<label for="pref-max-logs">Max. amount of logs</label>
<input rel="logs" type="text" id="pref-max-logs" value="' . $prefs['logs'] . '" />
</li>
<li>
<label for="pref-history-shouts">Shouts to keep in history</label>
<input rel="history" type="text" id="pref-history-shouts" value="' . $prefs['history'] . '" />
</li>
</ol>
</fieldset>
<fieldset id="prefs-cat-misc">
<div class="legend">Miscellaneous</div class="legend">
<ol>
<li>
<label for="pref-refresh-rate">Refresh rate</label>
<input rel="refresh" type="text" id="pref-refresh-rate" value="' . $prefs['refresh'] . '" />
</li>
<li>
<label for="pref-censor-words">Censor words</label>
<input rel="censorWords" type="text" id="pref-censor-words" value="' . $prefs['censorWords'] . '" />
</li>
</ol>
</fieldset>
</div>
<div id="cp-pane-display" class="cp-pane">
<fieldset id="prefs-cat-form">
<div class="legend">Form</div class="legend">
<ol>
<li>
<label for="pref-form-position">Form position</label>
<select rel="inverse" id="pref-form-position">
<option' . ($prefs['inverse'] == true ? ' selected' : '') . ' rel="true">Top</option>
<option' . ($prefs['inverse'] == false ? ' selected' : '') . ' rel="false">Bottom</option>
</select>
</li>
<li>
<label for="pref-nickname-text">Default nickname text</label>
<input rel="defaultNickname" type="text" id="pref-nickname-text" value="' . $prefs['defaultNickname'] . '" />
</li>
<li>
<label for="pref-message-text">Default message text</label>
<input rel="defaultMessage" type="text" id="pref-message-text" value="' . $prefs['defaultMessage'] . '" />
</li>
<li>
<label for="pref-submit-text">Default submit text</label>
<input rel="defaultSubmit" type="text" id="pref-submit-text" value="' . $prefs['defaultSubmit'] . '" />
</li>
<li>
<label for="pref-nickname-length">Max. nickname length</label>
<input rel="nicknameLength" type="text" id="pref-nickname-length" value="' . $prefs['nicknameLength'] . '" />
</li>
<li>
<label for="pref-message-length">Max. message length</label>
<input rel="messageLength" type="text" id="pref-message-length" value="' . $prefs['messageLength'] . '" />
</li>
<li>
<label for="pref-show-submit">Show submit button</label>
<select rel="showSubmit" id="pref-show-submit">
<option' . ($prefs['showSubmit'] == true ? ' selected' : '') . ' rel="true">Yes</option>
<option' . ($prefs['showSubmit'] == false ? ' selected' : '') . ' rel="false">No</option>
</select>
</li>
<li>
<label for="pref-post-form-link">Show link</label>
<select rel="postFormLink" id="pref-post-form-link">
<option' . ($prefs['postFormLink'] == 'none' ? ' selected' : '') . ' rel="none">None</option>
<option' . ($prefs['postFormLink'] == 'history' ? ' selected' : '') . ' rel="history">History</option>
<option' . ($prefs['postFormLink'] == 'cp' ? ' selected' : '') . ' rel="cp">Control Panel</option>
</select>
</li>
</ol>
</fieldset>
<fieldset id="prefs-cat-shouts">
<div class="legend">Shouts</div class="legend">
<ol>
<li>
<label for="pref-timestamp-format">Timestamp format</label>
<select rel="timestamp" id="pref-timestamp-format">
<option' . ($prefs['timestamp'] == 12 ? ' selected' : '') . ' rel="12">12-hour</option>
<option' . ($prefs['timestamp'] == 24 ? ' selected' : '') . ' rel="24">24-hour</option>
<option' . ($prefs['timestamp'] == 0 ? ' selected' : '') . ' rel="false">No timestamps</option>
</select>
</li>
<li>
<label for="pref-truncate">Messages to show</label>
<input rel="truncate" type="text" id="pref-truncate" value="' . $prefs['truncate'] . '" />
</li>
<li>
<label for="pref-do-truncate">Truncate messages</label>
<select rel="doTruncate" id="pref-do-truncate">
<option' . ($prefs['doTruncate'] == true ? ' selected' : '') . ' rel="true">Yes</option>
<option' . ($prefs['doTruncate'] == false ? ' selected' : '') . ' rel="false">No</option>
</select>
</li>
<li>
<label for="pref-nickname-suffix">Nickname suffix</label>
<input rel="nicknameSeparator" type="text" id="pref-nickname-suffix" value="' . $prefs['nicknameSeparator'] . '" />
</li>
<li>
<label for="pref-info-view">Info view</label>
<select rel="info" id="pref-info-view">
<option' . ($prefs['info'] == 'inline' ? ' selected' : '') . ' rel="inline">Inline</option>
<option' . ($prefs['info'] == 'overlay' ? ' selected' : '') . ' rel="overlay">Overlay</option>
</select>
</li>
</ol>
</fieldset>
</div>
</form>
';
}
function about() {
global $prefs;
$html = '
<div id="cp-pane-about" class="cp-pane">
<h2>About YShout</h2>
<p>YShout was created and developed by Yuri Vishnevsky. Version 5 is the first one with an about page, so you\'ll have to excuse the lack of appropriate information &mdash; I\'m not quite sure what it is that goes on "About" pages anyway.</p>
<p>Other than that obviously important tidbit of information, there\'s really nothing else that I can think of putting here... If anyone knows what a good and proper about page should contain, please contact me!
</div>
<div id="cp-pane-contact" class="cp-pane">
<h2>Contact Yuri</h2>
<p>If you have any questions or comments, you can contact me by email at <a href="mailto:yurivish@gmail.com">yurivish@gmail.com</a>, or on AIM at <a href="aim:goim?screnname=yurivish42">yurivish42</a>.</p>
<p>I hope you\'ve enjoyed using YShout!</p>
</div>
';
return $html;
}
?>

View File

@@ -0,0 +1,386 @@
* {
margin: 0;
padding: 0;
}
html, body {height: 100%;}
body {
background: #1a1a1a url(../images/bg.gif) center center no-repeat;
color: #a7a7a7;
font: 11px/1 Tahoma, Arial, sans-serif;
text-shadow: 0 0 0 #273541;
overflow: hidden;
}
a {
outline: none;
color: #fff;
text-decoration: none;
}
a:hover{
color: #fff;
}
input {
font-size: 11px;
background: #e5e5e5;
border: 1px solid #f5f5f5;
padding: 2px;
}
select {
font-size: 11px;
}
#cp {
height: 440px;
width: 620px;
position: absolute;
top: 50%;
left: 50%;
margin-top: -220px;
margin-left: -310px;
}
#nav {
height: 65px;
width: 100%;
background: url(../images/bg-nav.gif) repeat-x;
position: absolute;
bottom: 0;
}
#nav ul {
display: none;
width: 240px;
height: 65px;
margin: 0 auto;
list-style: none;
}
#nav li {
width: 80px;
float: left;
text-align: center;
}
#nav a {
display: block;
height: 65px;
text-indent: -4200px;
outline: none;
}
#nav a:active {
background-position: 0 -65px;
}
#n-prefs a { background: 0 0 url("../images/n-prefs.gif") no-repeat; }
#n-bans a { background: 0 0 url("../images/n-bans.gif") no-repeat; }
#n-about a { background: 0 0 url("../images/n-about.gif") no-repeat; }
.subnav {
height: 25px;
background: url(../images/bg-subnav.gif) repeat-x;
list-style: none;
}
.subnav input {
float: left;
margin-top: 2px;
margin-right: 10px;
}
.subnav li {
width: 85px;
float: left;
text-indent: -4200px;
}
.subnav a {
display: block;
height: 25px;
}
.subnav a:hover {
background-position: bottom left !important;
}
#sn-administration a { background: url(../images/sn-administration.gif) no-repeat; }
#sn-display a { background: url(../images/sn-display.gif) no-repeat; }
#sn-form a { background: url(../images/sn-form.gif) no-repeat; }
#sn-resetall a { background: url(../images/sn-resetall.gif) no-repeat; }
#sn-ban a { background: url(../images/sn-ban.gif) no-repeat; }
#sn-unbanall a { background: url(../images/sn-unbanall.gif) no-repeat; }
#sn-deleteall a { background: url(../images/sn-deleteall.gif) no-repeat; }
#sn-about a { background: url(../images/sn-about.gif) no-repeat; }
#sn-contact a { background: url(../images/sn-contact.gif) no-repeat; }
.sn-loading {
display: block;
height: 25px;
width: 25px;
float: right;
text-indent: -4200px;
background: url(../images/sn-spinny.gif) no-repeat;
_position: absolute;
_right: 20px;
_top: 50px;
}
@media { .sn-loading {
position: absolute;
right: 15px;
top: 41px;
}}
#content {
position: relative;
height: 375px;
overflow: hidden;
}
.header {
height: 33px;
padding-bottom: 2px;
border-bottom: 1px solid #444;
}
#login .header { border-bottom: 1px solid #4c657b; }
h1 {
float: left;
height: 32px;
width: 185px;
text-indent: -4200px;
}
#login h1 { background: url(../images/h-login.gif) no-repeat; }
#preferences h1 { background: url(../images/h-preferences.gif) no-repeat; }
#bans h1 { background: url(../images/h-bans.gif) no-repeat; }
#about h1 { background: url(../images/h-about.gif) no-repeat; }
.logout {
display: block;
height: 32px;
width: 45px;
float: right;
text-indent: -4200px;
background: url(../images/a-logout.gif) no-repeat;
}
.logout:hover {
background-position: bottom left;
}
.section {
clear: both;
width: 590px;
height: 355px;
padding: 15px;
padding-top: 5px;
position: absolute;
}
#login {
left: 0;
background: url(../images/bg-login.gif) repeat-x;
z-index: 5;
}
#login-form {
height: 45px;
width: 300px;
position: absolute;
top: 50%;
left: 50%;
margin-top: -45px;
margin-left: -150px;
background: url(../images/bg-login-form.gif) no-repeat;
}
#login-form label {
display: none;
}
#login-form input {
position: absolute;
left: 127px;
top: 13px;
width: 153px;
z-index: 2;
border: 1px solid #d4e7fa;
background: #e7eef6;
}
#login-loading {
display: block;
position: absolute;
top: 12px;
right: 8px;
height: 25px;
width: 25px;
text-indent: -4200px;
background: url(../images/login-spinny.gif) no-repeat;
z-index: 1;
}
#preferences {
left: 0;
background: url(../images/bg-prefs.gif) repeat-x;
}
#preferences-form { }
#preferences-form fieldset {
margin-top: 10px;
width: 295px;
border: none;
}
#preferences-form fieldset.odd {
float: right;
}
#preferences-form fieldset.even {
float: left;
}
#preferences-form .legend {
display: block;
width: 265px;
color: #fff;
padding-bottom: 3px;
border-bottom: 1px solid #80a147;
}
/* IE7 */
@media {#preferences-form legend {
margin-left: -7px;
}}
#preferences-form ol {
list-style: none;
margin-top: 15px;
}
#preferences-form li {
width: 295px;
padding-bottom: 10px;
}
#preferences-form label {
display: block;
width: 130px;
float: left;
}
#preferences-form input {
width: 129px;
}
#preferences-form select {
width: 135px;
}
.cp-pane {
position: absolute;
width: 590px;
display: none;
}
#cp-pane-administration {
display: block;
}
#bans {
left: 0;
background: url(../images/bg-bans.gif) repeat-x;
line-height: 1.3;
}
#cp #bans-list a {
color: #d9d9d9;
border-bottom: 1px solid transparent;
_border-bottom: none;
}
#cp #bans-list a:hover {
color: #fff;
border-bottom: 1px solid #de4147;
}
#bans-list {
padding-top: 10px;
list-style: none;
height: 280px;
overflow: auto;
}
#bans-list li {
clear: both;
padding: 3px 5px;
}
#bans-list .nickname {
color: #fff;
font-size: 12px;
}
#bans-list .unban-link {
position: absolute;
right: 20px;
}
#no-bans {
margin-top: 100px;
text-align: center;
font-size: 22px;
color: #383838;
}
#about {
left: 0;
background: url(../images/bg-about.gif) repeat-x;
line-height: 1.6;
}
#about h2 {
color: #fff;
font: Arial, sans-serif;
font-size: 14px;
font-weight: normal;
margin-bottom: 5px;
}
#about p {
margin-bottom: 5px;
}
#cp-pane-about {
margin-top: 10px;
display: block;
}
#cp-pane-contact {
margin-top: 10px;
}
#cp-pane-about a,
#cp-pane-contact a {
color: #d9d9d9;
padding-bottom: 2px;
}
#cp-pane-about a:hover,
#cp-pane-contact a:hover {
color: #fff;
border-bottom: 1px solid #f3982d;
}

42
ext/chatbox/cp/index.php Normal file
View File

@@ -0,0 +1,42 @@
<?
include 'ajax.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>YShout: Admin CP</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="js/admincp.js"></script>
</head>
<body>
<div id="cp">
<div id="nav">
<ul>
<li id="n-prefs"><a href="#">Preferences</a></li>
<li id="n-bans"><a href="#">Bans</a></li>
<li id="n-about"><a href="#">About</a></li>
</ul>
</div>
<div id="content">
<div class="section" id="login">
<div class="header">
<h1>YShout.Preferences</h1>
</div>
<form id="login-form" action="index.php" method="post">
<label for="login-password">Password:</label>
<input type="password" id="login-password" name="loginPassword">
<span id="login-loading">Loading...</span>
</form>
</div>
<?
if (loggedIn()) echo cp();
?>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,373 @@
Array.prototype.inArray = function (value) {
for (var i = 0; i < this.length; i++)
if (this[i] === value)
return true;
return false;
};
var AdminCP = function() {
var self = this;
var args = arguments;
$(function(){
self.init.apply(self, args);
});
};
AdminCP.prototype = {
z: 5,
animSpeed: 'normal',
curSection: 'login',
curPrefPane: 'administration',
curAboutPane: 'about',
init: function(options) {
this.initializing = true;
this.loginForm();
this.initEvents();
if (this.loaded()) this.afterLogin();
else {
$('#login-password')[0].focus();
}
this.initializing = false;
},
loginForm: function() {
$('#login-loading').fadeTo(1, 0);
},
initEvents: function() {
var self = this;
$('#login-form').submit(function() { self.login(); return false; });
$('#n-prefs').click(function() { self.show('preferences'); return false; });
$('#n-bans').click(function() { self.show('bans'); return false; });
$('#n-about').click(function() { self.show('about'); return false; });
},
afterLogin: function() {
var self = this;
// Login and logout
$('#login-password')[0].blur();
$('.logout').click(function() { self.logout(); return false; });
// Show the nav
if (this.initializing)
$('#nav ul').css('display', 'block');
else
$('#nav ul').slideDown();
// Some css for betterlookingness
$('#preferences-form fieldset:odd').addClass('odd');
$('#preferences-form fieldset:even').addClass('even');
$('#bans-list li:odd').addClass('odd');
$('#bans-list li:even').addClass('even');
// Hide the loading thingie
$('.sn-loading').fadeTo(1, 0);
// Events after load
this.initEventsAfter();
// If they want to go directly to a section
var anchor = this.getAnchor();
if (anchor.length > 0 && ['preferences', 'bans', 'about'].inArray(anchor))
self.show(anchor);
else
self.show('preferences');
},
initEventsAfter: function() {
var self = this;
// Navigation
$('#sn-administration').click(function() { self.showPrefPane('administration'); return false; });
$('#sn-display').click(function() { self.showPrefPane('display'); return false; });
$('#sn-about').click(function() { self.showAboutPane('about'); return false; });
$('#sn-contact').click(function() { self.showAboutPane('contact'); return false; });
$('#sn-resetall').click(function() { self.resetPrefs(); return false; });
$('#sn-unbanall').click(function() { self.unbanAll(); return false; });
// Bans
$('.unban-link').click(function() {
self.unban($(this).parent().find('.ip').html(), $(this).parent());
return false;
});
// Preferences
$('#preferences-form input').keypress(function(e) {
var key = window.event ? e.keyCode : e.which;
if (key == 13 || key == 3) {
self.changePref.apply(self, [$(this).attr('rel'), this.value]);
return false;
}
}).focus(function() {
this.name = this.value;
}).blur(function() {
if (this.name != this.value)
self.changePref.apply(self, [$(this).attr('rel'), this.value]);
});
$('#preferences-form select').change(function() {
self.changePref.apply(self, [$(this).attr('rel'), $(this).find('option:selected').attr('rel')]);
});
},
changePref: function(pref, value) {
this.loading();
var pars = {
mode: 'setpreference',
preference: pref,
'value': value
};
this.ajax(function(json) {
if (!json.error)
this.done();
else
alert(json.error);
}, pars);
},
resetPrefs: function() {
this.loading();
var pars = {
mode: 'resetpreferences'
}
this.ajax(function(json) {
this.done();
if (json.prefs)
for(pref in json.prefs) {
var value = json.prefs[pref];
var el = $('#preferences-form input[@rel=' + pref + '], select[@rel=' + pref + ']')[0];
if (el.type == 'text')
el.value = value;
else {
if (value == true) value = 'true';
if (value == false) value = 'false';
$('#preferences-form select[@rel=' + pref + ']')
.find('option')
.removeAttr('selected')
.end()
.find('option[@rel=' + value + ']')
.attr('selected', 'yeah');
}
}
}, pars);
},
invalidPassword: function() {
// Shake the login form
$('#login-form')
.animate({ marginLeft: -145 }, 100)
.animate({ marginLeft: -155 }, 100)
.animate({ marginLeft: -145 }, 100)
.animate({ marginLeft: -155 }, 100)
.animate({ marginLeft: -150 }, 50);
$('#login-password').val('').focus();
},
login: function() {
if (this.loaded()) {
alert('Something _really_ weird has happened. Refresh and pretend nothing ever happened.');
return;
}
var self = this;
var pars = {
mode: 'login',
password: $('#login-password').val()
};
this.loginLoading();
this.ajax(function() {
this.ajax(function(json) {
self.loginDone();
if (json.error) {
self.invalidPassword();
return;
}
$('#content').append(json.html);
self.afterLogin.apply(self);
}, pars);
}, pars);
},
logout: function() {
var self = this;
var pars = {
mode: 'logout'
};
this.loading();
this.ajax(function() {
$('#login-password').val('');
$('#nav ul').slideUp();
self.show('login', function() {
$('#login-password')[0].focus();
$('.section').not('#login').remove();
self.done();
});
}, pars);
},
show: function(section, callback) {
// var sections = ['login', 'preferences', 'bans', 'about'];
// if (!sections.inArray(section)) section = 'preferences';
if ($.browser.msie) {
if (section == 'preferences')
$('#preferences select').css('display', 'block');
else
$('#preferences select').css('display', 'none');
}
if (section == this.curSection) return;
this.curSection = section;
$('#' + section)[0].style.zIndex = ++this.z;
if (this.initializing)
$('#' + section).css('display', 'block');
else
$('#' + section).fadeIn(this.animSpeed, callback);
},
showPrefPane: function(pane) {
var self = this;
if (pane == this.curPrefPane) return;
this.curPrefPane = pane;
$('#preferences .cp-pane').css('display', 'none');
$('#cp-pane-' + pane).css('display', 'block').fadeIn(this.animSpeed, function() {
if (self.curPrefPane == pane)
$('#preferences .cp-pane').not('#cp-pane-' + pane).css('display', 'none');
else
$('#cp-pane-' + pane).css('display', 'none');
});
},
showAboutPane: function(pane) {
var self = this;
if (pane == this.curAboutPane) return;
this.curAboutPane = pane;
$('#about .cp-pane').css('display', 'none');
$('#cp-pane-' + pane).css('display', 'block').fadeIn(this.animSpeed, function() {
if (self.curAboutPane == pane)
$('#about .cp-pane').not('#cp-pane-' + pane).css('display', 'none');
else
$('#cp-pane-' + pane).css('display', 'none');
});
},
ajax: function(callback, pars, html) {
var self = this;
$.post('ajax.php', pars, function(parse) {
// alert(parse);
if (parse)
if (html)
callback.apply(self, [parse]);
else
callback.apply(self, [self.json(parse)]);
else
callback.apply(self);
});
},
json: function(parse) {
var json = eval('(' + parse + ')');
return json;
},
loaded: function() {
return ($('#cp-loaded').length == 1);
},
loading: function() {
$('#' + this.curSection + ' .sn-loading').fadeTo(this.animSpeed, 1);
},
done: function() {
$('#' + this.curSection + ' .sn-loading').fadeTo(this.animSpeed, 0);
},
loginLoading: function() {
$('#login-password').animate({
width: 134
});
$('#login-loading').fadeTo(this.animSpeed, 1);
},
loginDone: function() {
$('#login-password').animate({
width: 157
});
$('#login-loading').fadeTo(this.animSpeed, 0);
},
getAnchor: function() {
var href = window.location.href;
if (href.indexOf('#') > -1 )
return href.substr(href.indexOf('#') + 1).toLowerCase();
return '';
},
unban: function(ip, el) {
var self = this;
this.loading();
var pars = {
mode: 'unban',
'ip': ip
};
this.ajax(function(json) {
if (!json.error) {
$(el).fadeOut(function() {
$(this).remove();
$('#bans-list li:odd').removeClass('even').addClass('odd');
$('#bans-list li:even').removeClass('odd').addClass('even');
}, this.animSpeed);
}
self.done();
}, pars);
},
unbanAll: function() {
this.loading();
var pars = {
mode: 'unbanall'
}
this.ajax(function(json) {
this.done();
$('#bans-list').fadeOut(this.animSpeed, function() {
$('#bans-list').children().remove();
$('#bans-list').fadeIn();
});
}, pars);
}
};
var cp = new AdminCP();