mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-21 22:03:49 -07:00
r564
Очистка от неиспользуемого мусора в репозитарии; попытки начать рефакторинг движка на примере ajax.php git-svn-id: https://torrentpier2.googlecode.com/svn/trunk@564 a8ac35ab-4ca4-ca47-4c2d-a49a94f06293
This commit is contained in:
parent
58fea37572
commit
438ef8fb1f
8 changed files with 118 additions and 138 deletions
252
upload/ajax.php
252
upload/ajax.php
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
|
||||
define('BB_SCRIPT', 'ajax');
|
||||
define('IN_AJAX', true);
|
||||
|
||||
$ajax = new ajax_common();
|
||||
|
||||
require('./common.php');
|
||||
|
@ -8,53 +10,51 @@ require('./common.php');
|
|||
$ajax->init();
|
||||
|
||||
// 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']);
|
||||
}
|
||||
|
||||
// Load actions required modules
|
||||
switch ($ajax->action)
|
||||
{
|
||||
switch ($ajax->action) {
|
||||
case 'view_post':
|
||||
require(INC_DIR .'bbcode.php');
|
||||
break;
|
||||
require(INC_DIR . 'bbcode.php');
|
||||
break;
|
||||
|
||||
case 'posts':
|
||||
case 'post_mod_comment':
|
||||
require(INC_DIR .'bbcode.php');
|
||||
require(INC_DIR .'functions_post.php');
|
||||
require(INC_DIR .'functions_admin.php');
|
||||
break;
|
||||
require(INC_DIR . 'bbcode.php');
|
||||
require(INC_DIR . 'functions_post.php');
|
||||
require(INC_DIR . 'functions_admin.php');
|
||||
break;
|
||||
|
||||
case 'view_torrent':
|
||||
case 'mod_action':
|
||||
case 'change_tor_status':
|
||||
case 'gen_passkey';
|
||||
require(BB_ROOT .'attach_mod/attachment_mod.php');
|
||||
require(INC_DIR .'functions_torrent.php');
|
||||
break;
|
||||
require(BB_ROOT . 'attach_mod/attachment_mod.php');
|
||||
require(INC_DIR . 'functions_torrent.php');
|
||||
break;
|
||||
|
||||
case 'change_torrent':
|
||||
require(BB_ROOT .'attach_mod/attachment_mod.php');
|
||||
require(INC_DIR .'functions_torrent.php');
|
||||
break;
|
||||
require(BB_ROOT . 'attach_mod/attachment_mod.php');
|
||||
require(INC_DIR . 'functions_torrent.php');
|
||||
break;
|
||||
|
||||
case 'user_register':
|
||||
require(INC_DIR .'functions_validate.php');
|
||||
break;
|
||||
require(INC_DIR . 'functions_validate.php');
|
||||
break;
|
||||
|
||||
case 'manage_user':
|
||||
require(INC_DIR .'functions_admin.php');
|
||||
break;
|
||||
require(INC_DIR . 'functions_admin.php');
|
||||
break;
|
||||
|
||||
case 'group_membership':
|
||||
require(INC_DIR .'functions_group.php');
|
||||
break;
|
||||
require(INC_DIR . 'functions_group.php');
|
||||
break;
|
||||
}
|
||||
|
||||
// position in $ajax->valid_actions['xxx']
|
||||
define('AJAX_AUTH', 0); // 'guest', 'user', 'mod', 'admin', 'super_admin'
|
||||
define('AJAX_AUTH', 0); // 'guest', 'user', 'mod', 'admin', 'super_admin'
|
||||
|
||||
$user->session_start();
|
||||
$ajax->exec();
|
||||
|
@ -64,11 +64,11 @@ $ajax->exec();
|
|||
//
|
||||
class ajax_common
|
||||
{
|
||||
var $request = array();
|
||||
var $request = array();
|
||||
var $response = array();
|
||||
|
||||
var $valid_actions = array(
|
||||
// ACTION NAME AJAX_AUTH
|
||||
// ACTION NAME AJAX_AUTH
|
||||
'edit_user_profile' => array('admin'),
|
||||
'change_user_rank' => array('admin'),
|
||||
'change_user_opt' => array('admin'),
|
||||
|
@ -89,85 +89,76 @@ class ajax_common
|
|||
'user_register' => array('guest'),
|
||||
'posts' => array('guest'),
|
||||
'index_data' => array('guest'),
|
||||
);
|
||||
);
|
||||
|
||||
var $action = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
function ajax_common ()
|
||||
* Constructor
|
||||
*/
|
||||
function ajax_common()
|
||||
{
|
||||
ob_start(array(&$this, 'ob_handler'));
|
||||
header('Content-Type: text/plain');
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform action
|
||||
*/
|
||||
function exec ()
|
||||
* Perform action
|
||||
*/
|
||||
function exec()
|
||||
{
|
||||
global $lang;
|
||||
|
||||
// Exit if we already have errors
|
||||
if (!empty($this->response['error_code']))
|
||||
{
|
||||
if (!empty($this->response['error_code'])) {
|
||||
$this->send();
|
||||
}
|
||||
|
||||
// Check that requested action is valid
|
||||
$action = $this->action;
|
||||
|
||||
if (!$action || !is_string($action))
|
||||
{
|
||||
if (!$action || !is_string($action)) {
|
||||
$this->ajax_die('no action specified');
|
||||
}
|
||||
elseif (!$action_params =& $this->valid_actions[$action])
|
||||
{
|
||||
$this->ajax_die('invalid action: '. $action);
|
||||
} elseif (!$action_params =& $this->valid_actions[$action]) {
|
||||
$this->ajax_die('invalid action: ' . $action);
|
||||
}
|
||||
|
||||
// Auth check
|
||||
switch ($action_params[AJAX_AUTH])
|
||||
{
|
||||
switch ($action_params[AJAX_AUTH]) {
|
||||
// GUEST
|
||||
case 'guest':
|
||||
break;
|
||||
break;
|
||||
|
||||
// USER
|
||||
case 'user':
|
||||
if (IS_GUEST)
|
||||
{
|
||||
if (IS_GUEST) {
|
||||
$this->ajax_die($lang['NEED_TO_LOGIN_FIRST']);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
// MOD
|
||||
case 'mod':
|
||||
if (!IS_AM)
|
||||
{
|
||||
if (!IS_AM) {
|
||||
$this->ajax_die($lang['ONLY_FOR_MOD']);
|
||||
}
|
||||
$this->check_admin_session();
|
||||
break;
|
||||
break;
|
||||
|
||||
// ADMIN
|
||||
case 'admin':
|
||||
if (!IS_ADMIN)
|
||||
{
|
||||
if (!IS_ADMIN) {
|
||||
$this->ajax_die($lang['ONLY_FOR_ADMIN']);
|
||||
}
|
||||
$this->check_admin_session();
|
||||
break;
|
||||
break;
|
||||
|
||||
// SUPER_ADMIN
|
||||
case 'super_admin':
|
||||
if (!IS_SUPER_ADMIN)
|
||||
{
|
||||
if (!IS_SUPER_ADMIN) {
|
||||
$this->ajax_die($lang['ONLY_FOR_SUPER_ADMIN']);
|
||||
}
|
||||
$this->check_admin_session();
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
trigger_error("invalid auth type for $action", E_USER_ERROR);
|
||||
|
@ -181,9 +172,9 @@ class ajax_common
|
|||
}
|
||||
|
||||
/**
|
||||
* Exit on error
|
||||
*/
|
||||
function ajax_die ($error_msg, $error_code = E_AJAX_GENERAL_ERROR)
|
||||
* Exit on error
|
||||
*/
|
||||
function ajax_die($error_msg, $error_code = E_AJAX_GENERAL_ERROR)
|
||||
{
|
||||
$this->response['error_code'] = $error_code;
|
||||
$this->response['error_msg'] = $error_msg;
|
||||
|
@ -192,23 +183,22 @@ class ajax_common
|
|||
}
|
||||
|
||||
/**
|
||||
* Initialization
|
||||
*/
|
||||
function init ()
|
||||
* Initialization
|
||||
*/
|
||||
function init()
|
||||
{
|
||||
$this->request = $_POST;
|
||||
$this->action =& $this->request['action'];
|
||||
$this->action =& $this->request['action'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Send data
|
||||
*/
|
||||
function send ()
|
||||
* Send data
|
||||
*/
|
||||
function send()
|
||||
{
|
||||
$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();
|
||||
}
|
||||
|
||||
|
@ -217,24 +207,20 @@ class ajax_common
|
|||
}
|
||||
|
||||
/**
|
||||
* OB Handler
|
||||
*/
|
||||
function ob_handler ($contents)
|
||||
* OB Handler
|
||||
*/
|
||||
function ob_handler($contents)
|
||||
{
|
||||
if (DBG_USER)
|
||||
{
|
||||
if ($contents)
|
||||
{
|
||||
if (DBG_USER) {
|
||||
if ($contents) {
|
||||
$this->response['raw_output'] = $contents;
|
||||
}
|
||||
}
|
||||
|
||||
$response_js = bb_json_encode($this->response);
|
||||
|
||||
if (GZIP_OUTPUT_ALLOWED && !defined('NO_GZIP'))
|
||||
{
|
||||
if (UA_GZIP_SUPPORTED && strlen($response_js) > 2000)
|
||||
{
|
||||
if (GZIP_OUTPUT_ALLOWED && !defined('NO_GZIP')) {
|
||||
if (UA_GZIP_SUPPORTED && strlen($response_js) > 2000) {
|
||||
header('Content-Encoding: gzip');
|
||||
$response_js = gzencode($response_js, 1);
|
||||
}
|
||||
|
@ -244,26 +230,21 @@ class ajax_common
|
|||
}
|
||||
|
||||
/**
|
||||
* Admin session
|
||||
*/
|
||||
function check_admin_session ()
|
||||
* Admin session
|
||||
*/
|
||||
function check_admin_session()
|
||||
{
|
||||
global $user;
|
||||
|
||||
if (!$user->data['session_admin'])
|
||||
{
|
||||
if (empty($this->request['user_password']))
|
||||
{
|
||||
if (!$user->data['session_admin']) {
|
||||
if (empty($this->request['user_password'])) {
|
||||
$this->prompt_for_password();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$login_args = array(
|
||||
'login_username' => $user->data['username'],
|
||||
'login_password' => $_POST['user_password'],
|
||||
);
|
||||
if (!$user->login($login_args, true))
|
||||
{
|
||||
if (!$user->login($login_args, true)) {
|
||||
$this->ajax_die('Wrong password');
|
||||
}
|
||||
}
|
||||
|
@ -271,20 +252,20 @@ class ajax_common
|
|||
}
|
||||
|
||||
/**
|
||||
* Prompt for password
|
||||
*/
|
||||
function prompt_for_password ()
|
||||
* Prompt for password
|
||||
*/
|
||||
function prompt_for_password()
|
||||
{
|
||||
$this->response['prompt_password'] = 1;
|
||||
$this->send();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompt for confirmation
|
||||
*/
|
||||
function prompt_for_confirm ($confirm_msg)
|
||||
* Prompt for confirmation
|
||||
*/
|
||||
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['confirm_msg'] = $confirm_msg;
|
||||
|
@ -292,102 +273,101 @@ class ajax_common
|
|||
}
|
||||
|
||||
/**
|
||||
* Verify mod rights
|
||||
*/
|
||||
function verify_mod_rights ($forum_id)
|
||||
* Verify mod rights
|
||||
*/
|
||||
function verify_mod_rights($forum_id)
|
||||
{
|
||||
global $userdata, $lang;
|
||||
|
||||
$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']);
|
||||
}
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
|
@ -55,8 +55,8 @@ $domain_name = (!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : $do
|
|||
|
||||
// Increase number of revision after update
|
||||
$bb_cfg['tp_version'] = '2.5 (unstable)';
|
||||
$bb_cfg['tp_release_date'] = '19-01-2014';
|
||||
$bb_cfg['tp_release_state'] = 'R563';
|
||||
$bb_cfg['tp_release_date'] = '21-01-2014';
|
||||
$bb_cfg['tp_release_state'] = 'R564';
|
||||
|
||||
// Database
|
||||
$charset = 'utf8';
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue