Очистка от неиспользуемого мусора в репозитарии; попытки начать рефакторинг движка на примере 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,48 +10,46 @@ 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;
case 'posts': case 'posts':
case 'post_mod_comment': case 'post_mod_comment':
require(INC_DIR .'bbcode.php'); require(INC_DIR . 'bbcode.php');
require(INC_DIR .'functions_post.php'); require(INC_DIR . 'functions_post.php');
require(INC_DIR .'functions_admin.php'); require(INC_DIR . 'functions_admin.php');
break; break;
case 'view_torrent': case 'view_torrent':
case 'mod_action': case 'mod_action':
case 'change_tor_status': case 'change_tor_status':
case 'gen_passkey'; case 'gen_passkey';
require(BB_ROOT .'attach_mod/attachment_mod.php'); require(BB_ROOT . 'attach_mod/attachment_mod.php');
require(INC_DIR .'functions_torrent.php'); require(INC_DIR . 'functions_torrent.php');
break; break;
case 'change_torrent': case 'change_torrent':
require(BB_ROOT .'attach_mod/attachment_mod.php'); require(BB_ROOT . 'attach_mod/attachment_mod.php');
require(INC_DIR .'functions_torrent.php'); require(INC_DIR . 'functions_torrent.php');
break; break;
case 'user_register': case 'user_register':
require(INC_DIR .'functions_validate.php'); require(INC_DIR . 'functions_validate.php');
break; break;
case 'manage_user': case 'manage_user':
require(INC_DIR .'functions_admin.php'); require(INC_DIR . 'functions_admin.php');
break; break;
case 'group_membership': case 'group_membership':
require(INC_DIR .'functions_group.php'); require(INC_DIR . 'functions_group.php');
break; break;
} }
@ -89,14 +89,14 @@ class ajax_common
'user_register' => array('guest'), 'user_register' => array('guest'),
'posts' => array('guest'), 'posts' => array('guest'),
'index_data' => array('guest'), 'index_data' => array('guest'),
); );
var $action = null; var $action = null;
/** /**
* Constructor * Constructor
*/ */
function ajax_common () function ajax_common()
{ {
ob_start(array(&$this, 'ob_handler')); ob_start(array(&$this, 'ob_handler'));
header('Content-Type: text/plain'); header('Content-Type: text/plain');
@ -105,47 +105,40 @@ class ajax_common
/** /**
* Perform action * Perform action
*/ */
function exec () function exec()
{ {
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();
@ -183,7 +174,7 @@ class ajax_common
/** /**
* Exit on error * Exit on error
*/ */
function ajax_die ($error_msg, $error_code = E_AJAX_GENERAL_ERROR) function ajax_die($error_msg, $error_code = E_AJAX_GENERAL_ERROR)
{ {
$this->response['error_code'] = $error_code; $this->response['error_code'] = $error_code;
$this->response['error_msg'] = $error_msg; $this->response['error_msg'] = $error_msg;
@ -194,7 +185,7 @@ class ajax_common
/** /**
* Initialization * Initialization
*/ */
function init () function init()
{ {
$this->request = $_POST; $this->request = $_POST;
$this->action =& $this->request['action']; $this->action =& $this->request['action'];
@ -203,12 +194,11 @@ class ajax_common
/** /**
* Send data * Send data
*/ */
function send () function send()
{ {
$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();
} }
@ -219,22 +209,18 @@ class ajax_common
/** /**
* OB Handler * OB Handler
*/ */
function ob_handler ($contents) function ob_handler($contents)
{
if (DBG_USER)
{
if ($contents)
{ {
if (DBG_USER) {
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);
} }
@ -246,24 +232,19 @@ class ajax_common
/** /**
* Admin session * Admin session
*/ */
function check_admin_session () function check_admin_session()
{ {
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');
} }
} }
@ -273,7 +254,7 @@ class ajax_common
/** /**
* Prompt for password * Prompt for password
*/ */
function prompt_for_password () function prompt_for_password()
{ {
$this->response['prompt_password'] = 1; $this->response['prompt_password'] = 1;
$this->send(); $this->send();
@ -282,9 +263,9 @@ class ajax_common
/** /**
* Prompt for confirmation * Prompt for confirmation
*/ */
function prompt_for_confirm ($confirm_msg) function prompt_for_confirm($confirm_msg)
{ {
if(empty($confirm_msg)) $this->ajax_die('false'); if (empty($confirm_msg)) $this->ajax_die('false');
$this->response['prompt_confirm'] = 1; $this->response['prompt_confirm'] = 1;
$this->response['confirm_msg'] = $confirm_msg; $this->response['confirm_msg'] = $confirm_msg;
@ -294,100 +275,99 @@ class ajax_common
/** /**
* Verify mod rights * Verify mod rights
*/ */
function verify_mod_rights ($forum_id) function verify_mod_rights($forum_id)
{ {
global $userdata, $lang; global $userdata, $lang;
$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']);
} }
} }
function edit_user_profile () function edit_user_profile()
{ {
require(AJAX_DIR .'edit_user_profile.php'); require(AJAX_DIR . 'edit_user_profile.php');
} }
function change_user_rank () function change_user_rank()
{ {
require(AJAX_DIR .'change_user_rank.php'); require(AJAX_DIR . 'change_user_rank.php');
} }
function change_user_opt () function change_user_opt()
{ {
require(AJAX_DIR .'change_user_opt.php'); require(AJAX_DIR . 'change_user_opt.php');
} }
function gen_passkey () function gen_passkey()
{ {
require(AJAX_DIR .'gen_passkey.php'); require(AJAX_DIR . 'gen_passkey.php');
} }
function group_membership () function group_membership()
{ {
require(AJAX_DIR .'group_membership.php'); require(AJAX_DIR . 'group_membership.php');
} }
function post_mod_comment () function post_mod_comment()
{ {
require(AJAX_DIR .'post_mod_comment.php'); require(AJAX_DIR . 'post_mod_comment.php');
} }
function view_post () function view_post()
{ {
require(AJAX_DIR .'view_post.php'); require(AJAX_DIR . 'view_post.php');
} }
function change_tor_status () function change_tor_status()
{ {
require(AJAX_DIR .'change_tor_status.php'); require(AJAX_DIR . 'change_tor_status.php');
} }
function change_torrent () function change_torrent()
{ {
require(AJAX_DIR .'change_torrent.php'); require(AJAX_DIR . 'change_torrent.php');
} }
function view_torrent () function view_torrent()
{ {
require(AJAX_DIR .'view_torrent.php'); require(AJAX_DIR . 'view_torrent.php');
} }
function user_register () function user_register()
{ {
require(AJAX_DIR .'user_register.php'); require(AJAX_DIR . 'user_register.php');
} }
function mod_action () function mod_action()
{ {
require(AJAX_DIR .'mod_action.php'); require(AJAX_DIR . 'mod_action.php');
} }
function posts () function posts()
{ {
require(AJAX_DIR .'posts.php'); require(AJAX_DIR . 'posts.php');
} }
function manage_user () function manage_user()
{ {
require(AJAX_DIR .'manage_user.php'); require(AJAX_DIR . 'manage_user.php');
} }
function topic_tpl () function topic_tpl()
{ {
require(AJAX_DIR .'topic_tpl.php'); require(AJAX_DIR . 'topic_tpl.php');
} }
function index_data () function index_data()
{ {
require(AJAX_DIR .'index_data.php'); require(AJAX_DIR . 'index_data.php');
} }
function view_profile () function view_profile()
{ {
require(AJAX_DIR .'view_profile.php'); require(AJAX_DIR . 'view_profile.php');
} }
} }

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.