Очистка от неиспользуемого мусора в репозитарии; попытки начать рефакторинг движка на примере ajax.php git-svn-id: https://torrentpier2.googlecode.com/svn/trunk@564 a8ac35ab-4ca4-ca47-4c2d-a49a94f06293
This commit is contained in:
glix08@gmail.com 2014-01-20 21:03:46 +00:00
commit 438ef8fb1f
8 changed files with 118 additions and 138 deletions

View file

@ -1,6 +1,8 @@
<?php <?php
define('BB_SCRIPT', 'ajax');
define('IN_AJAX', true); define('IN_AJAX', true);
$ajax = new ajax_common(); $ajax = new ajax_common();
require('./common.php'); require('./common.php');
@ -8,14 +10,12 @@ require('./common.php');
$ajax->init(); $ajax->init();
// Handle "board disabled via ON/OFF trigger" // Handle "board disabled via ON/OFF trigger"
if (file_exists(BB_DISABLED)) if (file_exists(BB_DISABLED)) {
{
$ajax->ajax_die($bb_cfg['board_disabled_msg']); $ajax->ajax_die($bb_cfg['board_disabled_msg']);
} }
// Load actions required modules // Load actions required modules
switch ($ajax->action) switch ($ajax->action) {
{
case 'view_post': case 'view_post':
require(INC_DIR . 'bbcode.php'); require(INC_DIR . 'bbcode.php');
break; break;
@ -110,42 +110,35 @@ class ajax_common
global $lang; global $lang;
// Exit if we already have errors // Exit if we already have errors
if (!empty($this->response['error_code'])) if (!empty($this->response['error_code'])) {
{
$this->send(); $this->send();
} }
// Check that requested action is valid // Check that requested action is valid
$action = $this->action; $action = $this->action;
if (!$action || !is_string($action)) if (!$action || !is_string($action)) {
{
$this->ajax_die('no action specified'); $this->ajax_die('no action specified');
} } elseif (!$action_params =& $this->valid_actions[$action]) {
elseif (!$action_params =& $this->valid_actions[$action])
{
$this->ajax_die('invalid action: ' . $action); $this->ajax_die('invalid action: ' . $action);
} }
// Auth check // Auth check
switch ($action_params[AJAX_AUTH]) switch ($action_params[AJAX_AUTH]) {
{
// GUEST // GUEST
case 'guest': case 'guest':
break; break;
// USER // USER
case 'user': case 'user':
if (IS_GUEST) if (IS_GUEST) {
{
$this->ajax_die($lang['NEED_TO_LOGIN_FIRST']); $this->ajax_die($lang['NEED_TO_LOGIN_FIRST']);
} }
break; break;
// MOD // MOD
case 'mod': case 'mod':
if (!IS_AM) if (!IS_AM) {
{
$this->ajax_die($lang['ONLY_FOR_MOD']); $this->ajax_die($lang['ONLY_FOR_MOD']);
} }
$this->check_admin_session(); $this->check_admin_session();
@ -153,8 +146,7 @@ class ajax_common
// ADMIN // ADMIN
case 'admin': case 'admin':
if (!IS_ADMIN) if (!IS_ADMIN) {
{
$this->ajax_die($lang['ONLY_FOR_ADMIN']); $this->ajax_die($lang['ONLY_FOR_ADMIN']);
} }
$this->check_admin_session(); $this->check_admin_session();
@ -162,8 +154,7 @@ class ajax_common
// SUPER_ADMIN // SUPER_ADMIN
case 'super_admin': case 'super_admin':
if (!IS_SUPER_ADMIN) if (!IS_SUPER_ADMIN) {
{
$this->ajax_die($lang['ONLY_FOR_SUPER_ADMIN']); $this->ajax_die($lang['ONLY_FOR_SUPER_ADMIN']);
} }
$this->check_admin_session(); $this->check_admin_session();
@ -207,8 +198,7 @@ class ajax_common
{ {
$this->response['action'] = $this->action; $this->response['action'] = $this->action;
if (DBG_USER && SQL_DEBUG && !empty($_COOKIE['sql_log'])) if (DBG_USER && SQL_DEBUG && !empty($_COOKIE['sql_log'])) {
{
$this->response['sql_log'] = get_sql_log(); $this->response['sql_log'] = get_sql_log();
} }
@ -221,20 +211,16 @@ class ajax_common
*/ */
function ob_handler($contents) function ob_handler($contents)
{ {
if (DBG_USER) if (DBG_USER) {
{ if ($contents) {
if ($contents)
{
$this->response['raw_output'] = $contents; $this->response['raw_output'] = $contents;
} }
} }
$response_js = bb_json_encode($this->response); $response_js = bb_json_encode($this->response);
if (GZIP_OUTPUT_ALLOWED && !defined('NO_GZIP')) if (GZIP_OUTPUT_ALLOWED && !defined('NO_GZIP')) {
{ if (UA_GZIP_SUPPORTED && strlen($response_js) > 2000) {
if (UA_GZIP_SUPPORTED && strlen($response_js) > 2000)
{
header('Content-Encoding: gzip'); header('Content-Encoding: gzip');
$response_js = gzencode($response_js, 1); $response_js = gzencode($response_js, 1);
} }
@ -250,20 +236,15 @@ class ajax_common
{ {
global $user; global $user;
if (!$user->data['session_admin']) if (!$user->data['session_admin']) {
{ if (empty($this->request['user_password'])) {
if (empty($this->request['user_password']))
{
$this->prompt_for_password(); $this->prompt_for_password();
} } else {
else
{
$login_args = array( $login_args = array(
'login_username' => $user->data['username'], 'login_username' => $user->data['username'],
'login_password' => $_POST['user_password'], 'login_password' => $_POST['user_password'],
); );
if (!$user->login($login_args, true)) if (!$user->login($login_args, true)) {
{
$this->ajax_die('Wrong password'); $this->ajax_die('Wrong password');
} }
} }
@ -300,8 +281,7 @@ class ajax_common
$is_auth = auth(AUTH_MOD, $forum_id, $userdata); $is_auth = auth(AUTH_MOD, $forum_id, $userdata);
if (!$is_auth['auth_mod']) if (!$is_auth['auth_mod']) {
{
$this->ajax_die($lang['ONLY_FOR_MOD']); $this->ajax_die($lang['ONLY_FOR_MOD']);
} }
} }

View file

@ -55,8 +55,8 @@ $domain_name = (!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : $do
// Increase number of revision after update // Increase number of revision after update
$bb_cfg['tp_version'] = '2.5 (unstable)'; $bb_cfg['tp_version'] = '2.5 (unstable)';
$bb_cfg['tp_release_date'] = '19-01-2014'; $bb_cfg['tp_release_date'] = '21-01-2014';
$bb_cfg['tp_release_state'] = 'R563'; $bb_cfg['tp_release_state'] = 'R564';
// Database // Database
$charset = 'utf8'; $charset = 'utf8';

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.