diff --git a/ajax.php b/ajax.php index 8bf17a936..e17753c90 100644 --- a/ajax.php +++ b/ajax.php @@ -26,7 +26,7 @@ define('BB_SCRIPT', 'ajax'); define('IN_AJAX', true); -$ajax = new ajax_common(); +$ajax = new TorrentPier\Legacy\Ajax(); require __DIR__ . '/common.php'; @@ -83,10 +83,6 @@ switch ($ajax->action) { case 'manage_group': require INC_DIR . '/functions_group.php'; break; - - case 'sitemap': - require CLASS_DIR . '/sitemap.php'; - break; } // Position in $ajax->valid_actions['xxx'] @@ -94,335 +90,8 @@ define('AJAX_AUTH', 0); // 'guest', 'user', 'mod', 'admin', 'super_admin' $ajax->exec(); -// -// Ajax -// -class ajax_common -{ - public $request = array(); - public $response = array(); - - public $valid_actions = array( - // ACTION NAME AJAX_AUTH - 'edit_user_profile' => array('admin'), - 'change_user_rank' => array('admin'), - 'change_user_opt' => array('admin'), - 'manage_user' => array('admin'), - 'manage_admin' => array('admin'), - 'sitemap' => array('admin'), - - 'mod_action' => array('mod'), - 'topic_tpl' => array('mod'), - 'group_membership' => array('mod'), - 'post_mod_comment' => array('mod'), - - 'avatar' => array('user'), - 'gen_passkey' => array('user'), - 'change_torrent' => array('user'), - 'change_tor_status' => array('user'), - 'manage_group' => array('user'), - - 'view_post' => array('guest'), - 'view_torrent' => array('guest'), - 'user_register' => array('guest'), - 'posts' => array('guest'), - 'index_data' => array('guest'), - ); - - public $action; - - /** - * Constructor - */ - public function __construct() - { - ob_start(array(&$this, 'ob_handler')); - header('Content-Type: text/plain'); - } - - /** - * Perform action - */ - public function exec() - { - global $lang; - - // Exit if we already have errors - if (!empty($this->response['error_code'])) { - $this->send(); - } - - // Check that requested action is valid - $action = $this->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); - } - - // Auth check - switch ($action_params[AJAX_AUTH]) { - // GUEST - case 'guest': - break; - - // USER - case 'user': - if (IS_GUEST) { - $this->ajax_die($lang['NEED_TO_LOGIN_FIRST']); - } - break; - - // MOD - case 'mod': - if (!IS_AM) { - $this->ajax_die($lang['ONLY_FOR_MOD']); - } - $this->check_admin_session(); - break; - - // ADMIN - case 'admin': - if (!IS_ADMIN) { - $this->ajax_die($lang['ONLY_FOR_ADMIN']); - } - $this->check_admin_session(); - break; - - // SUPER_ADMIN - case 'super_admin': - if (!IS_SUPER_ADMIN) { - $this->ajax_die($lang['ONLY_FOR_SUPER_ADMIN']); - } - $this->check_admin_session(); - break; - - default: - trigger_error("invalid auth type for $action", E_USER_ERROR); - } - - // Run action - $this->$action(); - - // Send output - $this->send(); - } - - /** - * Exit on error - */ - public function ajax_die($error_msg, $error_code = E_AJAX_GENERAL_ERROR) - { - $this->response['error_code'] = $error_code; - $this->response['error_msg'] = $error_msg; - - $this->send(); - } - - /** - * Initialization - */ - public function init() - { - $this->request = $_POST; - $this->action =& $this->request['action']; - } - - /** - * Send data - */ - public function send() - { - $this->response['action'] = $this->action; - - if (DBG_USER && SQL_DEBUG && !empty($_COOKIE['sql_log'])) { - $this->response['sql_log'] = get_sql_log(); - } - - // sending output will be handled by $this->ob_handler() - exit(); - } - - /** - * OB Handler - */ - public function ob_handler($contents) - { - if (DBG_USER) { - if ($contents) { - $this->response['raw_output'] = $contents; - } - } - - $response_js = json_encode($this->response); - - 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); - } - } - - return $response_js; - } - - /** - * Admin session - */ - public function check_admin_session() - { - global $user; - - if (!$user->data['session_admin']) { - if (empty($this->request['user_password'])) { - $this->prompt_for_password(); - } else { - $login_args = array( - 'login_username' => $user->data['username'], - 'login_password' => $_POST['user_password'], - ); - if (!$user->login($login_args, true)) { - $this->ajax_die('Wrong password'); - } - } - } - } - - /** - * Prompt for password - */ - public function prompt_for_password() - { - $this->response['prompt_password'] = 1; - $this->send(); - } - - /** - * Prompt for confirmation - */ - public function prompt_for_confirm($confirm_msg) - { - if (empty($confirm_msg)) { - $this->ajax_die('false'); - } - - $this->response['prompt_confirm'] = 1; - $this->response['confirm_msg'] = $confirm_msg; - $this->send(); - } - - /** - * Verify mod rights - */ - public function verify_mod_rights($forum_id) - { - global $userdata, $lang; - - $is_auth = auth(AUTH_MOD, $forum_id, $userdata); - - if (!$is_auth['auth_mod']) { - $this->ajax_die($lang['ONLY_FOR_MOD']); - } - } - - public function edit_user_profile() - { - require AJAX_DIR . '/edit_user_profile.php'; - } - - public function change_user_rank() - { - require AJAX_DIR . '/change_user_rank.php'; - } - - public function change_user_opt() - { - require AJAX_DIR . '/change_user_opt.php'; - } - - public function gen_passkey() - { - require AJAX_DIR . '/gen_passkey.php'; - } - - public function group_membership() - { - require AJAX_DIR . '/group_membership.php'; - } - - public function manage_group() - { - require AJAX_DIR . '/edit_group_profile.php'; - } - - public function post_mod_comment() - { - require AJAX_DIR . '/post_mod_comment.php'; - } - - public function view_post() - { - require AJAX_DIR . '/view_post.php'; - } - - public function change_tor_status() - { - require AJAX_DIR . '/change_tor_status.php'; - } - - public function change_torrent() - { - require AJAX_DIR . '/change_torrent.php'; - } - - public function view_torrent() - { - require AJAX_DIR . '/view_torrent.php'; - } - - public function user_register() - { - require AJAX_DIR . '/user_register.php'; - } - - public function mod_action() - { - require AJAX_DIR . '/mod_action.php'; - } - - public function posts() - { - require AJAX_DIR . '/posts.php'; - } - - public function manage_user() - { - require AJAX_DIR . '/manage_user.php'; - } - - public function manage_admin() - { - require AJAX_DIR . '/manage_admin.php'; - } - - public function topic_tpl() - { - require AJAX_DIR . '/topic_tpl.php'; - } - - public function index_data() - { - require AJAX_DIR . '/index_data.php'; - } - - public function avatar() - { - require AJAX_DIR . '/avatar.php'; - } - - public function sitemap() - { - require AJAX_DIR . '/sitemap.php'; - } -} +/** + * @deprecated ajax_common + * Dirty class removed from here since 2.1.6 + * To add new actions see at src/Legacy/Ajax.php + */ diff --git a/common.php b/common.php index 4d0257045..e801cc30d 100644 --- a/common.php +++ b/common.php @@ -100,16 +100,8 @@ define('BOT_UID', -746); /** * Database */ -// Core DB class -require CORE_DIR . '/dbs.php'; -require CORE_DIR . '/mysql.php'; -$DBS = new DBS($bb_cfg); +$DBS = new TorrentPier\Legacy\Dbs($bb_cfg); -/** - * @param string $db_alias - * @return \sql_db - * @deprecated - */ function DB($db_alias = 'db1') { global $DBS; @@ -119,14 +111,7 @@ function DB($db_alias = 'db1') /** * Cache */ -// Main cache class -require INC_DIR . '/cache/common.php'; -// Main datastore class -require INC_DIR . '/datastore/common.php'; - -// Core CACHE class -require CORE_DIR . '/caches.php'; -$CACHES = new CACHES($bb_cfg); +$CACHES = new TorrentPier\Legacy\Caches($bb_cfg); function CACHE($cache_name) { @@ -134,29 +119,12 @@ function CACHE($cache_name) return $CACHES->get_cache_obj($cache_name); } -// Common cache classes -require INC_DIR . '/cache/memcache.php'; -require INC_DIR . '/cache/sqlite.php'; -require INC_DIR . '/cache/redis.php'; -require INC_DIR . '/cache/apc.php'; -require INC_DIR . '/cache/xcache.php'; -require INC_DIR . '/cache/file.php'; - /** * Datastore */ -// Common datastore classes -require INC_DIR . '/datastore/memcache.php'; -require INC_DIR . '/datastore/sqlite.php'; -require INC_DIR . '/datastore/redis.php'; -require INC_DIR . '/datastore/apc.php'; -require INC_DIR . '/datastore/xcache.php'; -require INC_DIR . '/datastore/file.php'; - -// Initialize datastore switch ($bb_cfg['datastore_type']) { case 'memcache': - $datastore = new datastore_memcache($bb_cfg['cache']['memcache'], $bb_cfg['cache']['prefix']); + $datastore = new TorrentPier\Legacy\Datastore\Memcache($bb_cfg['cache']['memcache'], $bb_cfg['cache']['prefix']); break; case 'sqlite': @@ -165,24 +133,24 @@ switch ($bb_cfg['datastore_type']) { 'pconnect' => true, 'con_required' => true, ); - $datastore = new datastore_sqlite($default_cfg, $bb_cfg['cache']['prefix']); + $datastore = new TorrentPier\Legacy\Datastore\Sqlite($default_cfg, $bb_cfg['cache']['prefix']); break; case 'redis': - $datastore = new datastore_redis($bb_cfg['cache']['redis'], $bb_cfg['cache']['prefix']); + $datastore = new TorrentPier\Legacy\Datastore\Redis($bb_cfg['cache']['redis'], $bb_cfg['cache']['prefix']); break; case 'apc': - $datastore = new datastore_apc($bb_cfg['cache']['prefix']); + $datastore = new TorrentPier\Legacy\Datastore\Apc($bb_cfg['cache']['prefix']); break; case 'xcache': - $datastore = new datastore_xcache($bb_cfg['cache']['prefix']); + $datastore = new TorrentPier\Legacy\Datastore\Xcache($bb_cfg['cache']['prefix']); break; case 'filecache': default: - $datastore = new datastore_file($bb_cfg['cache']['db_dir'] . 'datastore/', $bb_cfg['cache']['prefix']); + $datastore = new TorrentPier\Legacy\Datastore\File($bb_cfg['cache']['db_dir'] . 'datastore/', $bb_cfg['cache']['prefix']); } function sql_dbg_enabled() @@ -201,7 +169,7 @@ function short_query($sql, $esc_html = false) } } - return ($esc_html) ? htmlCHR($sql, true) : $sql; + return $esc_html ? htmlCHR($sql, true) : $sql; } // Functions @@ -270,7 +238,7 @@ function mkdir_rec($path, $mode) return ($path !== '.' && $path !== '..') ? is_writable($path) : false; } - return (mkdir_rec(dirname($path), $mode)) ? @mkdir($path, $mode) : false; + return mkdir_rec(dirname($path), $mode) ? @mkdir($path, $mode) : false; } function verify_id($id, $length) diff --git a/group_edit.php b/group_edit.php index 3d1c6bcf9..960fc3b1c 100644 --- a/group_edit.php +++ b/group_edit.php @@ -56,8 +56,7 @@ if ($is_moderator) { // Avatar if ($submit) { if (!empty($_FILES['avatar']['name']) && $bb_cfg['group_avatars']['up_allowed']) { - require INC_DIR . '/functions_upload.php'; - $upload = new upload_common(); + $upload = new TorrentPier\Legacy\Common\Upload(); if ($upload->init($bb_cfg['group_avatars'], $_FILES['avatar']) and $upload->store('avatar', array("user_id" => GROUP_AVATAR_MASK . $group_id, "avatar_ext_id" => $group_info['avatar_ext_id']))) { $avatar_ext_id = (int)$upload->file_ext_id; diff --git a/install/upgrade/r583-convert_avatars.php b/install/upgrade/r583-convert_avatars.php index 60b938a42..700f17131 100644 --- a/install/upgrade/r583-convert_avatars.php +++ b/install/upgrade/r583-convert_avatars.php @@ -26,7 +26,6 @@ define('IN_FORUM', true); define('BB_ROOT', './'); require(BB_ROOT . 'common.php'); -require(INC_DIR . 'functions_upload.php'); while (@ob_end_flush()) ; ob_implicit_flush(); @@ -74,7 +73,7 @@ if ($confirm) { 'tmp_name' => BB_ROOT . $bb_cfg['avatar_path'] . '/' . basename($row['user_avatar']), 'error' => 0, ); - $upload = new upload_common(); + $upload = new TorrentPier\Legacy\Common\Upload(); if ($upload->init($bb_cfg['avatars'], $FILE, false) and $upload->store('avatar', $row)) { DB()->query("UPDATE " . BB_USERS . " SET avatar_ext_id = {$upload->file_ext_id} WHERE user_id = {$row['user_id']} LIMIT 1"); diff --git a/library/ajax/sitemap.php b/library/ajax/sitemap.php index 3403021b3..49e2c8dd5 100644 --- a/library/ajax/sitemap.php +++ b/library/ajax/sitemap.php @@ -30,7 +30,7 @@ if (!defined('IN_AJAX')) { global $bb_cfg, $lang; $mode = (string)$this->request['mode']; -$map = new sitemap(); +$map = new TorrentPier\Legacy\Sitemap(); $html = ''; switch ($mode) { diff --git a/library/ajax/view_torrent.php b/library/ajax/view_torrent.php index 5cc22c5ca..6e41e0b06 100644 --- a/library/ajax/view_torrent.php +++ b/library/ajax/view_torrent.php @@ -52,122 +52,7 @@ if (!$tor = bdecode($file_contents)) { return $lang['TORFILE_INVALID']; } -$torrent = new TorrentFileList($tor); +$torrent = new TorrentPier\Legacy\TorrentFileList($tor); $tor_filelist = $torrent->get_filelist(); $this->response['html'] = $tor_filelist; - -/** - * Class TorrentFileList - */ -class TorrentFileList -{ - public $tor_decoded = []; - public $files_ary = [ - '/' => [] - ]; - public $multiple = false; - public $root_dir = ''; - public $files_html = ''; - - public function __construct($decoded_file_contents) - { - $this->tor_decoded = $decoded_file_contents; - } - - public function get_filelist() - { - global $html; - - $this->build_filelist_array(); - - if ($this->multiple) { - if ($this->files_ary['/'] !== '') { - $this->files_ary = array_merge($this->files_ary, $this->files_ary['/']); - unset($this->files_ary['/']); - } - $filelist = $html->array2html($this->files_ary); - return "
{$this->root_dir}
$filelist"; - } else { - return implode('', $this->files_ary['/']); - } - } - - private function build_filelist_array() - { - $info = $this->tor_decoded['info']; - - if (isset($info['name.utf-8'])) { - $info['name'] =& $info['name.utf-8']; - } - - if (isset($info['files']) && is_array($info['files'])) { - $this->root_dir = isset($info['name']) ? '../' . clean_tor_dirname($info['name']) : '...'; - $this->multiple = true; - - foreach ($info['files'] as $f) { - if (isset($f['path.utf-8'])) { - $f['path'] =& $f['path.utf-8']; - } - if (!isset($f['path']) || !is_array($f['path'])) { - continue; - } - array_deep($f['path'], 'clean_tor_dirname'); - - $length = isset($f['length']) ? (float)$f['length'] : 0; - $subdir_count = count($f['path']) - 1; - - if ($subdir_count > 0) { - $name = array_pop($f['path']); - $cur_files_ary =& $this->files_ary; - - for ($i = 0, $j = 1; $i < $subdir_count; $i++, $j++) { - $subdir = $f['path'][$i]; - - if (!isset($cur_files_ary[$subdir])) { - $cur_files_ary[$subdir] = array(); - } - $cur_files_ary =& $cur_files_ary[$subdir]; - - if ($j == $subdir_count) { - if (is_string($cur_files_ary)) { - $GLOBALS['bnc_error'] = 1; - break(1); - } - $cur_files_ary[] = $this->build_file_item($name, $length); - } - } - natsort($cur_files_ary); - } else { - $name = $f['path'][0]; - $this->files_ary['/'][] = $this->build_file_item($name, $length); - natsort($this->files_ary['/']); - } - } - } else { - $name = clean_tor_dirname($info['name']); - $length = (float)$info['length']; - $this->files_ary['/'][] = $this->build_file_item($name, $length); - natsort($this->files_ary['/']); - } - } - - private function build_file_item($name, $length) - { - global $bb_cfg, $images, $lang; - - $magnet_name = $magnet_ext = ''; - - if ($bb_cfg['magnet_links_enabled']) { - $magnet_name = ''; - $magnet_ext = ''; - } - - return "$name $length $magnet_name $magnet_ext"; - } -} - -function clean_tor_dirname($dirname) -{ - return str_replace(array('[', ']', '<', '>', "'"), array('[', ']', '<', '>', '''), $dirname); -} diff --git a/library/attach_mod/posting_attachments.php b/library/attach_mod/posting_attachments.php index 3046d5aa9..59f453323 100644 --- a/library/attach_mod/posting_attachments.php +++ b/library/attach_mod/posting_attachments.php @@ -33,1153 +33,6 @@ define('FILENAME_MAX_LENGTH', 180); define('FILENAME_CRYPTIC', false); define('FILENAME_CRYPTIC_LENGTH', 64); -class attach_parent -{ - public $post_attach = false; - public $attach_filename = ''; - public $filename = ''; - public $type = ''; - public $extension = ''; - public $file_comment = ''; - public $num_attachments = 0; // number of attachments in message - public $filesize = 0; - public $filetime = 0; - public $thumbnail = 0; - public $page = 0; // On which page we are on ? This should be filled by child classes. - - // Switches - public $add_attachment_body = 0; - public $posted_attachments_body = 0; - - /** - * Constructor - */ - public function __construct() - { - $this->add_attachment_body = get_var('add_attachment_body', 0); - $this->posted_attachments_body = get_var('posted_attachments_body', 0); - - $this->file_comment = get_var('filecomment', ''); - $this->attachment_id_list = get_var('attach_id_list', array(0)); - $this->attachment_comment_list = get_var('comment_list', array('')); - $this->attachment_filesize_list = get_var('filesize_list', array(0)); - $this->attachment_filetime_list = get_var('filetime_list', array(0)); - $this->attachment_filename_list = get_var('filename_list', array('')); - $this->attachment_extension_list = get_var('extension_list', array('')); - $this->attachment_mimetype_list = get_var('mimetype_list', array('')); - - $this->filename = (isset($_FILES['fileupload']) && isset($_FILES['fileupload']['name']) && $_FILES['fileupload']['name'] !== 'none') ? trim(stripslashes($_FILES['fileupload']['name'])) : ''; - - $this->attachment_list = get_var('attachment_list', array('')); - $this->attachment_thumbnail_list = get_var('attach_thumbnail_list', array(0)); - } - - /** - * Get Quota Limits - * @param array $userdata_quota - * @param int $user_id - */ - public function get_quota_limits(array $userdata_quota, $user_id = 0) - { - global $attach_config; - - $priority = 'user;group'; - - if (IS_ADMIN) { - $attach_config['pm_filesize_limit'] = 0; // Unlimited - $attach_config['upload_filesize_limit'] = 0; // Unlimited - return; - } - - $quota_type = QUOTA_UPLOAD_LIMIT; - $limit_type = 'upload_filesize_limit'; - $default = 'attachment_quota'; - - if (!$user_id) { - $user_id = (int) $userdata_quota['user_id']; - } - - $priority = explode(';', $priority); - $found = false; - - foreach ($priority as $item) { - if ($item === 'group' && !$found) { - // Get Group Quota, if we find one, we have our quota - $sql = 'SELECT u.group_id - FROM ' . BB_USER_GROUP . ' u, ' . BB_GROUPS . ' g - WHERE g.group_single_user = 0 - AND u.user_pending = 0 - AND u.group_id = g.group_id - AND u.user_id = ' . (int) $user_id; - - if (!($result = DB()->sql_query($sql))) { - bb_die('Could not get user group'); - } - - $rows = DB()->sql_fetchrowset($result); - DB()->sql_freeresult($result); - - if ($rows) { - $group_id = array(); - - foreach ($rows as $row) { - $group_id[] = (int) $row['group_id']; - } - - $sql = 'SELECT l.quota_limit - FROM ' . BB_QUOTA . ' q, ' . BB_QUOTA_LIMITS . ' l - WHERE q.group_id IN (' . implode(', ', $group_id) . ') - AND q.group_id <> 0 - AND q.quota_type = ' . (int) $quota_type . ' - AND q.quota_limit_id = l.quota_limit_id - ORDER BY l.quota_limit DESC - LIMIT 1'; - - if (!($result = DB()->sql_query($sql))) { - bb_die('Could not get group quota'); - } - - if (DB()->num_rows($result)) { - $row = DB()->sql_fetchrow($result); - $attach_config[$limit_type] = $row['quota_limit']; - $found = true; - } - DB()->sql_freeresult($result); - } - } - - if ($item === 'user' && !$found) { - // Get User Quota, if the user is not in a group or the group has no quotas - $sql = 'SELECT l.quota_limit - FROM ' . BB_QUOTA . ' q, ' . BB_QUOTA_LIMITS . ' l - WHERE q.user_id = ' . $user_id . ' - AND q.user_id <> 0 - AND q.quota_type = ' . $quota_type . ' - AND q.quota_limit_id = l.quota_limit_id - LIMIT 1'; - - if (!($result = DB()->sql_query($sql))) { - bb_die('Could not get user quota'); - } - - if (DB()->num_rows($result)) { - $row = DB()->sql_fetchrow($result); - $attach_config[$limit_type] = $row['quota_limit']; - $found = true; - } - DB()->sql_freeresult($result); - } - } - - if (!$found) { - // Set Default Quota Limit - $quota_id = (int) ((int) $quota_type === QUOTA_UPLOAD_LIMIT) ? $attach_config['default_upload_quota'] : $attach_config['default_pm_quota']; - - if (!$quota_id) { - $attach_config[$limit_type] = $attach_config[$default]; - } else { - $sql = 'SELECT quota_limit - FROM ' . BB_QUOTA_LIMITS . ' - WHERE quota_limit_id = ' . (int) $quota_id . ' - LIMIT 1'; - - if (!($result = DB()->sql_query($sql))) { - bb_die('Could not get default quota limit'); - } - - if (DB()->num_rows($result) > 0) { - $row = DB()->sql_fetchrow($result); - $attach_config[$limit_type] = $row['quota_limit']; - } else { - $attach_config[$limit_type] = $attach_config[$default]; - } - DB()->sql_freeresult($result); - } - } - - // Never exceed the complete Attachment Upload Quota - if ($quota_type === QUOTA_UPLOAD_LIMIT) { - if ($attach_config[$limit_type] > $attach_config[$default]) { - $attach_config[$limit_type] = $attach_config[$default]; - } - } - } - - /** - * Handle all modes... (intern) - * @private - */ - public function handle_attachments($mode) - { - global $is_auth, $attach_config, $refresh, $post_id, $submit, $preview, $error, $error_msg, $lang; - - // - // ok, what shall we do ;) - // - - if (IS_ADMIN) { - $max_attachments = ADMIN_MAX_ATTACHMENTS; - } else { - $max_attachments = (int) $attach_config['max_attachments']; - } - - $sql_id = 'post_id'; - - // nothing, if the user is not authorized or attachment mod disabled - if ($attach_config['disable_mod'] || !$is_auth['auth_attachments']) { - return false; - } - - // Init Vars - $attachments = array(); - - if (!$refresh) { - $add = isset($_POST['add_attachment']); - $delete = isset($_POST['del_attachment']); - $edit = isset($_POST['edit_comment']); - $update_attachment = isset($_POST['update_attachment']); - $del_thumbnail = isset($_POST['del_thumbnail']); - - $add_attachment_box = !empty($_POST['add_attachment_box']); - $posted_attachments_box = !empty($_POST['posted_attachments_box']); - - $refresh = $add || $delete || $edit || $del_thumbnail || $update_attachment || $add_attachment_box || $posted_attachments_box; - } - - // Get Attachments - $attachments = get_attachments_from_post($post_id); - - $auth = $is_auth['auth_edit'] || $is_auth['auth_mod']; - - if (!$submit && $mode === 'editpost' && $auth) { - if (!$refresh && !$preview && !$error) { - foreach ($attachments as $attachment) { - $this->attachment_list[] = $attachment['physical_filename']; - $this->attachment_comment_list[] = $attachment['comment']; - $this->attachment_filename_list[] = $attachment['real_filename']; - $this->attachment_extension_list[] = $attachment['extension']; - $this->attachment_mimetype_list[] = $attachment['mimetype']; - $this->attachment_filesize_list[] = $attachment['filesize']; - $this->attachment_filetime_list[] = $attachment['filetime']; - $this->attachment_id_list[] = $attachment['attach_id']; - $this->attachment_thumbnail_list[] = $attachment['thumbnail']; - } - } - } - - $this->num_attachments = count($this->attachment_list); - - if ($submit) { - if ($mode === 'newtopic' || $mode === 'reply' || $mode === 'editpost') { - if ($this->filename) { - if ($this->num_attachments < (int) $max_attachments) { - $this->upload_attachment(); - - if (!$error && $this->post_attach) { - array_unshift($this->attachment_list, $this->attach_filename); - array_unshift($this->attachment_comment_list, $this->file_comment); - array_unshift($this->attachment_filename_list, $this->filename); - array_unshift($this->attachment_extension_list, $this->extension); - array_unshift($this->attachment_mimetype_list, $this->type); - array_unshift($this->attachment_filesize_list, $this->filesize); - array_unshift($this->attachment_filetime_list, $this->filetime); - array_unshift($this->attachment_id_list, '0'); - array_unshift($this->attachment_thumbnail_list, $this->thumbnail); - - $this->file_comment = ''; - $this->post_attach = false; - } - } else { - $error = true; - if (!empty($error_msg)) { - $error_msg .= '
'; - } - $error_msg .= sprintf($lang['TOO_MANY_ATTACHMENTS'], (int) $max_attachments); - } - } - } - } - - if ($preview || $refresh || $error) { - $delete_attachment = isset($_POST['del_attachment']); - $delete_thumbnail = isset($_POST['del_thumbnail']); - - $add_attachment = isset($_POST['add_attachment']); - $edit_attachment = isset($_POST['edit_comment']); - $update_attachment = isset($_POST['update_attachment']); - - // Perform actions on temporary attachments - if ($delete_attachment || $delete_thumbnail) { - // store old values - $actual_id_list = get_var('attach_id_list', array(0)); - $actual_comment_list = get_var('comment_list', array('')); - $actual_filename_list = get_var('filename_list', array('')); - $actual_extension_list = get_var('extension_list', array('')); - $actual_mimetype_list = get_var('mimetype_list', array('')); - $actual_filesize_list = get_var('filesize_list', array(0)); - $actual_filetime_list = get_var('filetime_list', array(0)); - - $actual_list = get_var('attachment_list', array('')); - $actual_thumbnail_list = get_var('attach_thumbnail_list', array(0)); - - // clean values - $this->attachment_list = array(); - $this->attachment_comment_list = array(); - $this->attachment_filename_list = array(); - $this->attachment_extension_list = array(); - $this->attachment_mimetype_list = array(); - $this->attachment_filesize_list = array(); - $this->attachment_filetime_list = array(); - $this->attachment_id_list = array(); - $this->attachment_thumbnail_list = array(); - - // restore values :) - if (isset($_POST['attachment_list'])) { - for ($i = 0, $iMax = count($actual_list); $i < $iMax; $i++) { - $restore = false; - $del_thumb = false; - - if ($delete_thumbnail) { - if (!isset($_POST['del_thumbnail'][$actual_list[$i]])) { - $restore = true; - } else { - $del_thumb = true; - } - } - if ($delete_attachment) { - if (!isset($_POST['del_attachment'][$actual_list[$i]])) { - $restore = true; - } - } - - if ($restore) { - $this->attachment_list[] = $actual_list[$i]; - $this->attachment_comment_list[] = $actual_comment_list[$i]; - $this->attachment_filename_list[] = $actual_filename_list[$i]; - $this->attachment_extension_list[] = $actual_extension_list[$i]; - $this->attachment_mimetype_list[] = $actual_mimetype_list[$i]; - $this->attachment_filesize_list[] = $actual_filesize_list[$i]; - $this->attachment_filetime_list[] = $actual_filetime_list[$i]; - $this->attachment_id_list[] = $actual_id_list[$i]; - $this->attachment_thumbnail_list[] = $actual_thumbnail_list[$i]; - } elseif (!$del_thumb) { - // delete selected attachment - if ($actual_id_list[$i] == '0') { - unlink_attach($actual_list[$i]); - - if ($actual_thumbnail_list[$i] == 1) { - unlink_attach($actual_list[$i], MODE_THUMBNAIL); - } - } else { - delete_attachment($post_id, $actual_id_list[$i], $this->page); - } - } elseif ($del_thumb) { - // delete selected thumbnail - $this->attachment_list[] = $actual_list[$i]; - $this->attachment_comment_list[] = $actual_comment_list[$i]; - $this->attachment_filename_list[] = $actual_filename_list[$i]; - $this->attachment_extension_list[] = $actual_extension_list[$i]; - $this->attachment_mimetype_list[] = $actual_mimetype_list[$i]; - $this->attachment_filesize_list[] = $actual_filesize_list[$i]; - $this->attachment_filetime_list[] = $actual_filetime_list[$i]; - $this->attachment_id_list[] = $actual_id_list[$i]; - $this->attachment_thumbnail_list[] = 0; - - if ($actual_id_list[$i] == 0) { - unlink_attach($actual_list[$i], MODE_THUMBNAIL); - } else { - $sql = 'UPDATE ' . BB_ATTACHMENTS_DESC . ' SET thumbnail = 0 WHERE attach_id = ' . (int) $actual_id_list[$i]; - - if (!(DB()->sql_query($sql))) { - bb_die('Unable to update ' . BB_ATTACHMENTS_DESC); - } - } - } - } - } - } elseif ($edit_attachment || $update_attachment || $add_attachment || $preview) { - if ($edit_attachment) { - $actual_comment_list = get_var('comment_list', array('')); - - $this->attachment_comment_list = array(); - - for ($i = 0, $iMax = count($this->attachment_list); $i < $iMax; $i++) { - $this->attachment_comment_list[$i] = $actual_comment_list[$i]; - } - } - - if ($update_attachment) { - if (empty($this->filename)) { - $error = true; - if (!empty($error_msg)) { - $error_msg .= '
'; - } - $error_msg .= $lang['ERROR_EMPTY_ADD_ATTACHBOX']; - } - - $this->upload_attachment(); - - if (!$error) { - $actual_id_list = get_var('attach_id_list', array(0)); - - $attachment_id = 0; - $actual_element = 0; - - for ($i = 0, $iMax = count($actual_id_list); $i < $iMax; $i++) { - if (isset($_POST['update_attachment'][$actual_id_list[$i]])) { - $attachment_id = (int) $actual_id_list[$i]; - $actual_element = $i; - } - } - - // Get current informations to delete the Old Attachment - $sql = 'SELECT physical_filename, comment, thumbnail - FROM ' . BB_ATTACHMENTS_DESC . ' - WHERE attach_id = ' . (int) $attachment_id; - - if (!($result = DB()->sql_query($sql))) { - bb_die('Unable to select old attachment entry'); - } - - if (DB()->num_rows($result) != 1) { - $error = true; - if (!empty($error_msg)) { - $error_msg .= '
'; - } - $error_msg .= $lang['ERROR_MISSING_OLD_ENTRY']; - } - - $row = DB()->sql_fetchrow($result); - DB()->sql_freeresult($result); - - $comment = !trim($this->file_comment) ? trim($row['comment']) : trim($this->file_comment); - - // Update Entry - $sql_ary = array( - 'physical_filename' => (string) basename($this->attach_filename), - 'real_filename' => (string) basename($this->filename), - 'comment' => (string) $comment, - 'extension' => (string) strtolower($this->extension), - 'mimetype' => (string) strtolower($this->type), - 'filesize' => (int) $this->filesize, - 'filetime' => (int) $this->filetime, - 'thumbnail' => (int) $this->thumbnail - ); - - $sql = 'UPDATE ' . BB_ATTACHMENTS_DESC . ' SET ' . attach_mod_sql_build_array('UPDATE', $sql_ary) . ' - WHERE attach_id = ' . (int) $attachment_id; - - if (!(DB()->sql_query($sql))) { - bb_die('Unable to update the attachment'); - } - - // Delete the Old Attachment - unlink_attach($row['physical_filename']); - - if ((int) $row['thumbnail'] === 1) { - unlink_attach($row['physical_filename'], MODE_THUMBNAIL); - } - - //bt - if ($this->attachment_extension_list[$actual_element] === TORRENT_EXT && $attachments[$actual_element]['tracker_status']) { - include INC_DIR . '/functions_torrent.php'; - tracker_unregister($attachment_id); - } - //bt end - - // Make sure it is displayed - $this->attachment_list[$actual_element] = $this->attach_filename; - $this->attachment_comment_list[$actual_element] = $comment; - $this->attachment_filename_list[$actual_element] = $this->filename; - $this->attachment_extension_list[$actual_element] = $this->extension; - $this->attachment_mimetype_list[$actual_element] = $this->type; - $this->attachment_filesize_list[$actual_element] = $this->filesize; - $this->attachment_filetime_list[$actual_element] = $this->filetime; - $this->attachment_id_list[$actual_element] = $actual_id_list[$actual_element]; - $this->attachment_thumbnail_list[$actual_element] = $this->thumbnail; - $this->file_comment = ''; - } - } - - if (($add_attachment || $preview) && !empty($this->filename)) { - if ($this->num_attachments < (int) $max_attachments) { - $this->upload_attachment(); - - if (!$error) { - array_unshift($this->attachment_list, $this->attach_filename); - array_unshift($this->attachment_comment_list, $this->file_comment); - array_unshift($this->attachment_filename_list, $this->filename); - array_unshift($this->attachment_extension_list, $this->extension); - array_unshift($this->attachment_mimetype_list, $this->type); - array_unshift($this->attachment_filesize_list, $this->filesize); - array_unshift($this->attachment_filetime_list, $this->filetime); - array_unshift($this->attachment_id_list, '0'); - array_unshift($this->attachment_thumbnail_list, $this->thumbnail); - - $this->file_comment = ''; - } - } else { - $error = true; - if (!empty($error_msg)) { - $error_msg .= '
'; - } - $error_msg .= sprintf($lang['TOO_MANY_ATTACHMENTS'], (int) $max_attachments); - } - } - } - } - - return true; - } - - /** - * Basic Insert Attachment Handling for all Message Types - */ - public function do_insert_attachment($mode, $message_type, $message_id) - { - global $upload_dir; - - if ((int) $message_id < 0) { - return false; - } - - global $post_info, $userdata; - - $post_id = (int) $message_id; - $user_id_1 = (isset($post_info['poster_id'])) ? (int) $post_info['poster_id'] : 0; - - if (!$user_id_1) { - $user_id_1 = (int) $userdata['user_id']; - } - - if ($mode === 'attach_list') { - for ($i = 0, $iMax = count($this->attachment_list); $i < $iMax; $i++) { - if ($this->attachment_id_list[$i]) { - //bt - if ($this->attachment_extension_list[$i] === TORRENT_EXT && !defined('TORRENT_ATTACH_ID')) { - define('TORRENT_ATTACH_ID', $this->attachment_id_list[$i]); - } - //bt end - - // update entry in db if attachment already stored in db and filespace - $sql = 'UPDATE ' . BB_ATTACHMENTS_DESC . " - SET comment = '" . @attach_mod_sql_escape($this->attachment_comment_list[$i]) . "' - WHERE attach_id = " . $this->attachment_id_list[$i]; - - if (!(DB()->sql_query($sql))) { - bb_die('Unable to update the file comment'); - } - } else { - if (empty($this->attachment_mimetype_list[$i]) && $this->attachment_extension_list[$i] === TORRENT_EXT) { - $this->attachment_mimetype_list[$i] = 'application/x-bittorrent'; - } - - // insert attachment into db - $sql_ary = array( - 'physical_filename' => (string) basename($this->attachment_list[$i]), - 'real_filename' => (string) basename($this->attachment_filename_list[$i]), - 'comment' => (string) @$this->attachment_comment_list[$i], - 'extension' => (string) strtolower($this->attachment_extension_list[$i]), - 'mimetype' => (string) strtolower($this->attachment_mimetype_list[$i]), - 'filesize' => (int) $this->attachment_filesize_list[$i], - 'filetime' => (int) $this->attachment_filetime_list[$i], - 'thumbnail' => (int) $this->attachment_thumbnail_list[$i] - ); - - $sql = 'INSERT INTO ' . BB_ATTACHMENTS_DESC . ' ' . attach_mod_sql_build_array('INSERT', $sql_ary); - - if (!(DB()->sql_query($sql))) { - bb_die('Could not store Attachment.
Your ' . $message_type . ' has been stored'); - } - - $attach_id = DB()->sql_nextid(); - - //bt - if ($this->attachment_extension_list[$i] === TORRENT_EXT && !defined('TORRENT_ATTACH_ID')) { - define('TORRENT_ATTACH_ID', $attach_id); - } - //bt end - - $sql_ary = array( - 'attach_id' => (int) $attach_id, - 'post_id' => (int) $post_id, - 'user_id_1' => (int) $user_id_1, - ); - - $sql = 'INSERT INTO ' . BB_ATTACHMENTS . ' ' . attach_mod_sql_build_array('INSERT', $sql_ary); - - if (!(DB()->sql_query($sql))) { - bb_die('Could not store Attachment.
Your ' . $message_type . ' has been stored'); - } - } - } - - return true; - } - - if ($mode === 'last_attachment') { - if ($this->post_attach && !isset($_POST['update_attachment'])) { - // insert attachment into db, here the user submited it directly - $sql_ary = array( - 'physical_filename' => (string) basename($this->attach_filename), - 'real_filename' => (string) basename($this->filename), - 'comment' => (string) $this->file_comment, - 'extension' => (string) strtolower($this->extension), - 'mimetype' => (string) strtolower($this->type), - 'filesize' => (int) $this->filesize, - 'filetime' => (int) $this->filetime, - 'thumbnail' => (int) $this->thumbnail - ); - - $sql = 'INSERT INTO ' . BB_ATTACHMENTS_DESC . ' ' . attach_mod_sql_build_array('INSERT', $sql_ary); - - // Inform the user that his post has been created, but nothing is attached - if (!(DB()->sql_query($sql))) { - bb_die('Could not store Attachment.
Your ' . $message_type . ' has been stored'); - } - - $attach_id = DB()->sql_nextid(); - - $sql_ary = array( - 'attach_id' => (int) $attach_id, - 'post_id' => (int) $post_id, - 'user_id_1' => (int) $user_id_1, - ); - - $sql = 'INSERT INTO ' . BB_ATTACHMENTS . ' ' . attach_mod_sql_build_array('INSERT', $sql_ary); - - if (!(DB()->sql_query($sql))) { - bb_die('Could not store Attachment.
Your ' . $message_type . ' has been stored'); - } - } - } - } - - /** - * Attachment Mod entry switch/output (intern) - * @private - */ - public function display_attachment_bodies() - { - global $attach_config, $is_auth, $lang, $template, $upload_dir, $forum_id; - - // Choose what to display - $value_add = $value_posted = 0; - - $this->add_attachment_body = 1; - $this->posted_attachments_body = 1; - - $s_hidden = ''; - $s_hidden .= ''; - - $template->assign_vars(array( - 'ADD_ATTACH_HIDDEN_FIELDS' => $s_hidden, - )); - - $attachments = array(); - - if ($this->attachment_list) { - $hidden = ''; - for ($i = 0, $iMax = count($this->attachment_list); $i < $iMax; $i++) { - $hidden .= ''; - $hidden .= ''; - $hidden .= ''; - $hidden .= ''; - $hidden .= ''; - $hidden .= ''; - $hidden .= ''; - $hidden .= ''; - - if (!$this->posted_attachments_body || !$this->attachment_list) { - $hidden .= ''; - } - } - $template->assign_var('POSTED_ATTACHMENTS_HIDDEN_FIELDS', $hidden); - } - - if ($this->add_attachment_body) { - $template->assign_vars(array( - 'TPL_ADD_ATTACHMENT' => true, - 'FILE_COMMENT' => htmlspecialchars($this->file_comment), - 'FILESIZE' => $attach_config['max_filesize'], - 'FILENAME' => htmlspecialchars($this->filename), - 'S_FORM_ENCTYPE' => 'enctype="multipart/form-data"', - )); - } - - if ($this->posted_attachments_body && $this->attachment_list) { - $template->assign_vars(array( - 'TPL_POSTED_ATTACHMENTS' => true, - )); - - for ($i = 0, $iMax = count($this->attachment_list); $i < $iMax; $i++) { - if (@$this->attachment_id_list[$i] == 0) { - $download_link = $upload_dir . '/' . basename($this->attachment_list[$i]); - } else { - $download_link = BB_ROOT . DOWNLOAD_URL . $this->attachment_id_list[$i]; - } - - $template->assign_block_vars('attach_row', array( - 'FILE_NAME' => @htmlspecialchars($this->attachment_filename_list[$i]), - 'ATTACH_FILENAME' => @$this->attachment_list[$i], - 'FILE_COMMENT' => @htmlspecialchars($this->attachment_comment_list[$i]), - 'ATTACH_ID' => @$this->attachment_id_list[$i], - 'U_VIEW_ATTACHMENT' => $download_link, - )); - - // Thumbnail there ? And is the User Admin or Mod ? Then present the 'Delete Thumbnail' Button - if ((int) $this->attachment_thumbnail_list[$i] === 1 && ((isset($is_auth['auth_mod']) && $is_auth['auth_mod']) || IS_ADMIN)) { - $template->assign_block_vars('attach_row.switch_thumbnail', array()); - } - - if (@$this->attachment_id_list[$i]) { - $template->assign_block_vars('attach_row.switch_update_attachment', array()); - } - } - } - - $template->assign_var('ATTACHBOX'); - } - - /** - * Upload an Attachment to Filespace (intern) - */ - public function upload_attachment() - { - global $error, $error_msg, $lang, $attach_config, $userdata, $upload_dir, $forum_id; - - $this->post_attach = (bool) $this->filename; - - if ($this->post_attach) { - $r_file = trim(basename($this->filename)); - $file = $_FILES['fileupload']['tmp_name']; - $this->type = $_FILES['fileupload']['type']; - - if (isset($_FILES['fileupload']['size']) && $_FILES['fileupload']['size'] == 0) { - bb_die('Tried to upload empty file'); - } - - $this->type = strtolower($this->type); - $this->extension = strtolower(get_extension($this->filename)); - - $this->filesize = @filesize($file); - $this->filesize = (int) $this->filesize; - - $sql = 'SELECT g.allow_group, g.max_filesize, g.cat_id, g.forum_permissions - FROM ' . BB_EXTENSION_GROUPS . ' g, ' . BB_EXTENSIONS . " e - WHERE g.group_id = e.group_id - AND e.extension = '" . attach_mod_sql_escape($this->extension) . "' - LIMIT 1"; - - if (!($result = DB()->sql_query($sql))) { - bb_die('Could not query extensions'); - } - - $row = DB()->sql_fetchrow($result); - DB()->sql_freeresult($result); - - $allowed_filesize = $row['max_filesize'] ?: $attach_config['max_filesize']; - $cat_id = (int) $row['cat_id']; - $auth_cache = trim($row['forum_permissions']); - - // check Filename - if (preg_match("#[\\/:*?\"<>|]#i", $this->filename)) { - $error = true; - if (!empty($error_msg)) { - $error_msg .= '
'; - } - $error_msg .= sprintf($lang['INVALID_FILENAME'], htmlspecialchars($this->filename)); - } - - // check php upload-size - if (!$error && $file === 'none') { - $error = true; - if (!empty($error_msg)) { - $error_msg .= '
'; - } - $ini_val = 'ini_get'; - - $max_size = @$ini_val('upload_max_filesize'); - - if (empty($max_size)) { - $error_msg .= $lang['ATTACHMENT_PHP_SIZE_NA']; - } else { - $error_msg .= sprintf($lang['ATTACHMENT_PHP_SIZE_OVERRUN'], $max_size); - } - } - - // Check Extension - if (!$error && (int) $row['allow_group'] == 0) { - $error = true; - if (!empty($error_msg)) { - $error_msg .= '
'; - } - $error_msg .= sprintf($lang['DISALLOWED_EXTENSION'], htmlspecialchars($this->extension)); - } - - // Check Forum Permissions - if (!$error && !IS_ADMIN && !is_forum_authed($auth_cache, $forum_id) && trim($auth_cache)) { - $error = true; - if (!empty($error_msg)) { - $error_msg .= '
'; - } - $error_msg .= sprintf($lang['DISALLOWED_EXTENSION_WITHIN_FORUM'], htmlspecialchars($this->extension)); - } - - //bt - // Check if user can post torrent - global $post_data; - - if (!$error && $this->extension === TORRENT_EXT && !$post_data['first_post']) { - $error = true; - if (!empty($error_msg)) { - $error_msg .= '
'; - } - $error_msg .= $lang['ALLOWED_ONLY_1ST_POST_ATTACH']; - } - //bt end - - // Upload File - - $this->thumbnail = 0; - - if (!$error) { - // - // Prepare Values - $this->filetime = TIMENOW; - - $this->filename = $r_file; - - // physical filename - //$this->attach_filename = strtolower($this->filename); - $this->attach_filename = $this->filename; - - //bt - if (FILENAME_CRYPTIC) { - $this->attach_filename = make_rand_str(FILENAME_CRYPTIC_LENGTH); - } else { // original - $this->attach_filename = html_entity_decode(trim(stripslashes($this->attach_filename))); - $this->attach_filename = delete_extension($this->attach_filename); - $this->attach_filename = str_replace(array(' ', '-'), '_', $this->attach_filename); - $this->attach_filename = str_replace('__', '_', $this->attach_filename); - $this->attach_filename = str_replace(array(',', '.', '!', '?', 'ь', 'Ь', 'ц', 'Ц', 'д', 'Д', ';', ':', '@', "'", '"', '&'), array('', '', '', '', 'ue', 'ue', 'oe', 'oe', 'ae', 'ae', '', '', '', '', '', 'and'), $this->attach_filename); - $this->attach_filename = str_replace(array('$', 'Я', '>', '<', '§', '%', '=', '/', '(', ')', '#', '*', '+', "\\", '{', '}', '[', ']'), array('dollar', 'ss', 'greater', 'lower', 'paragraph', 'percent', 'equal', '', '', '', '', '', '', '', '', '', '', ''), $this->attach_filename); - // Remove non-latin characters - $this->attach_filename = preg_replace('#([\xC2\xC3])([\x80-\xBF])#', 'chr(ord(\'$1\')<<6&0xC0|ord(\'$2\')&0x3F)', $this->attach_filename); - $this->attach_filename = rawurlencode($this->attach_filename); - $this->attach_filename = preg_replace("/(%[0-9A-F]{1,2})/i", '', $this->attach_filename); - $this->attach_filename = trim($this->attach_filename); - } - $this->attach_filename = str_replace(array('&', '&', ' '), '_', $this->attach_filename); - $this->attach_filename = str_replace('php', '_php_', $this->attach_filename); - $this->attach_filename = substr(trim($this->attach_filename), 0, FILENAME_MAX_LENGTH); - - for ($i = 0, $max_try = 5; $i <= $max_try; $i++) { - $fn_prefix = make_rand_str(FILENAME_PREFIX_LENGTH) . '_'; - $new_physical_filename = clean_filename($fn_prefix . $this->attach_filename); - - if (!physical_filename_already_stored($new_physical_filename)) { - break; - } - if ($i === $max_try) { - bb_die('Could not create filename for attachment'); - } - - $this->attach_filename = $new_physical_filename; - } - - - // Do we have to create a thumbnail ? - if ($cat_id == IMAGE_CAT && (int) $attach_config['img_create_thumbnail']) { - $this->thumbnail = 1; - } - } - - if ($error) { - $this->post_attach = false; - return; - } - - // Upload Attachment - if (!$error) { - // Descide the Upload method - $ini_val = 'ini_get'; - - if (@$ini_val('open_basedir')) { - $upload_mode = 'move'; - } elseif (@$ini_val('safe_mode')) { - $upload_mode = 'move'; - } else { - $upload_mode = 'copy'; - } - - // Ok, upload the Attachment - if (!$error) { - $this->move_uploaded_attachment($upload_mode, $file); - } - } - - // Now, check filesize parameters - if (!$error) { - if (!$this->filesize) { - $this->filesize = (int) @filesize($upload_dir . '/' . $this->attach_filename); - } - } - - // Check Image Size, if it's an image - if (!$error && !IS_ADMIN && $cat_id === IMAGE_CAT) { - list($width, $height) = image_getdimension($upload_dir . '/' . $this->attach_filename); - - if ($width && $height && (int) $attach_config['img_max_width'] && (int) $attach_config['img_max_height']) { - if ($width > (int) $attach_config['img_max_width'] || $height > (int) $attach_config['img_max_height']) { - $error = true; - if (!empty($error_msg)) { - $error_msg .= '
'; - } - $error_msg .= sprintf($lang['ERROR_IMAGESIZE'], (int) $attach_config['img_max_width'], (int) $attach_config['img_max_height']); - } - } - } - - // check Filesize - if (!$error && $allowed_filesize && $this->filesize > $allowed_filesize && !(IS_ADMIN || IS_MOD || IS_GROUP_MEMBER)) { - $allowed_filesize = humn_size($allowed_filesize); - - $error = true; - if (!empty($error_msg)) { - $error_msg .= '
'; - } - $error_msg .= sprintf($lang['ATTACHMENT_TOO_BIG'], $allowed_filesize); - } - - // Check our complete quota - if ($attach_config['attachment_quota']) { - $sql = 'SELECT sum(filesize) as total FROM ' . BB_ATTACHMENTS_DESC; - - if (!($result = DB()->sql_query($sql))) { - bb_die('Could not query total filesize #1'); - } - - $row = DB()->sql_fetchrow($result); - DB()->sql_freeresult($result); - - $total_filesize = $row['total']; - - if (($total_filesize + $this->filesize) > $attach_config['attachment_quota']) { - $error = true; - if (!empty($error_msg)) { - $error_msg .= '
'; - } - $error_msg .= $lang['ATTACH_QUOTA_REACHED']; - } - } - - $this->get_quota_limits($userdata); - - // Check our user quota - if ($attach_config['upload_filesize_limit']) { - $sql = 'SELECT attach_id - FROM ' . BB_ATTACHMENTS . ' - WHERE user_id_1 = ' . (int) $userdata['user_id'] . ' - GROUP BY attach_id'; - - if (!($result = DB()->sql_query($sql))) { - bb_die('Could not query attachments'); - } - - $attach_ids = DB()->sql_fetchrowset($result); - $num_attach_ids = DB()->num_rows($result); - DB()->sql_freeresult($result); - - $attach_id = array(); - - for ($i = 0; $i < $num_attach_ids; $i++) { - $attach_id[] = (int) $attach_ids[$i]['attach_id']; - } - - if ($num_attach_ids > 0) { - // Now get the total filesize - $sql = 'SELECT sum(filesize) as total - FROM ' . BB_ATTACHMENTS_DESC . ' - WHERE attach_id IN (' . implode(', ', $attach_id) . ')'; - - if (!($result = DB()->sql_query($sql))) { - bb_die('Could not query total filesize #2'); - } - - $row = DB()->sql_fetchrow($result); - DB()->sql_freeresult($result); - $total_filesize = $row['total']; - } else { - $total_filesize = 0; - } - - if (($total_filesize + $this->filesize) > $attach_config['upload_filesize_limit']) { - $upload_filesize_limit = $attach_config['upload_filesize_limit']; - $size_lang = ($upload_filesize_limit >= 1048576) ? $lang['MB'] : (($upload_filesize_limit >= 1024) ? $lang['KB'] : $lang['BYTES']); - - if ($upload_filesize_limit >= 1048576) { - $upload_filesize_limit = round($upload_filesize_limit / 1048576 * 100) / 100; - } elseif ($upload_filesize_limit >= 1024) { - $upload_filesize_limit = round($upload_filesize_limit / 1024 * 100) / 100; - } - - $error = true; - if (!empty($error_msg)) { - $error_msg .= '
'; - } - $error_msg .= sprintf($lang['USER_UPLOAD_QUOTA_REACHED'], $upload_filesize_limit, $size_lang); - } - } - - if ($error) { - unlink_attach($this->attach_filename); - unlink_attach($this->attach_filename, MODE_THUMBNAIL); - $this->post_attach = false; - } - } - } - - // Copy the temporary attachment to the right location (copy, move_uploaded_file) - public function move_uploaded_attachment($upload_mode, $file) - { - global $error, $error_msg, $lang, $upload_dir; - - if (!is_uploaded_file($file)) { - bb_die('Unable to upload file. The given source has not been uploaded'); - } - - switch ($upload_mode) { - case 'copy': - - if (!@copy($file, $upload_dir . '/' . basename($this->attach_filename))) { - if (!@move_uploaded_file($file, $upload_dir . '/' . basename($this->attach_filename))) { - $error = true; - if (!empty($error_msg)) { - $error_msg .= '
'; - } - $error_msg .= sprintf($lang['GENERAL_UPLOAD_ERROR'], './' . $upload_dir . '/' . $this->attach_filename); - return; - } - } - @chmod($upload_dir . '/' . basename($this->attach_filename), 0666); - - break; - - case 'move': - - if (!@move_uploaded_file($file, $upload_dir . '/' . basename($this->attach_filename))) { - if (!@copy($file, $upload_dir . '/' . basename($this->attach_filename))) { - $error = true; - if (!empty($error_msg)) { - $error_msg .= '
'; - } - $error_msg .= sprintf($lang['GENERAL_UPLOAD_ERROR'], './' . $upload_dir . '/' . $this->attach_filename); - return; - } - } - @chmod($upload_dir . '/' . $this->attach_filename, 0666); - - break; - } - - if (!$error && $this->thumbnail === 1) { - $source = $upload_dir . '/' . basename($this->attach_filename); - $dest_file = amod_realpath($upload_dir); - $dest_file .= '/' . THUMB_DIR . '/t_' . basename($this->attach_filename); - - if (!create_thumbnail($source, $dest_file, $this->type)) { - if (!$file || !create_thumbnail($file, $dest_file, $this->type)) { - $this->thumbnail = 0; - } - } - } - } -} - -/** - * @package attachment_mod - * Attachment posting - */ -class attach_posting extends attach_parent -{ - /** - * Constructor - */ - public function __construct() - { - parent::__construct(); - $this->page = 0; - } - - /** - * Insert an Attachment into a Post (this is the second function called from posting.php) - */ - public function insert_attachment($post_id) - { - global $is_auth, $mode; - - // Insert Attachment ? - if ($post_id && ($mode === 'newtopic' || $mode === 'reply' || $mode === 'editpost') && $is_auth['auth_attachments']) { - $this->do_insert_attachment('attach_list', 'post', $post_id); - $this->do_insert_attachment('last_attachment', 'post', $post_id); - - if ((count($this->attachment_list) > 0 || $this->post_attach) && !isset($_POST['update_attachment'])) { - $sql = 'UPDATE ' . BB_POSTS . ' SET post_attachment = 1 WHERE post_id = ' . (int) $post_id; - - if (!(DB()->sql_query($sql))) { - bb_die('Unable to update posts table'); - } - - $sql = 'SELECT topic_id FROM ' . BB_POSTS . ' WHERE post_id = ' . (int) $post_id; - - if (!($result = DB()->sql_query($sql))) { - bb_die('Unable to select posts table'); - } - - $row = DB()->sql_fetchrow($result); - DB()->sql_freeresult($result); - - $sql = 'UPDATE ' . BB_TOPICS . ' SET topic_attachment = 1 WHERE topic_id = ' . (int) $row['topic_id']; - - if (!(DB()->sql_query($sql))) { - bb_die('Unable to update topics table'); - } - } - } - } - - /** - * Handle Attachments (Add/Delete/Edit/Show) - This is the first function called from every message handler - */ - public function posting_attachment_mod() - { - global $mode, $confirm, $is_auth, $post_id, $delete, $refresh; - - if (!$refresh) { - $add_attachment_box = (!empty($_POST['add_attachment_box'])) ? true : false; - $posted_attachments_box = (!empty($_POST['posted_attachments_box'])) ? true : false; - - $refresh = $add_attachment_box || $posted_attachments_box; - } - - // Choose what to display - $result = $this->handle_attachments($mode); - - if ($result === false) { - return; - } - - if ($confirm && ($delete || $mode === 'delete' || $mode === 'editpost') && ($is_auth['auth_delete'] || $is_auth['auth_mod'])) { - if ($post_id) { - delete_attachment($post_id); - } - } - - $this->display_attachment_bodies(); - } -} - /** * Entry Point */ @@ -1187,6 +40,6 @@ function execute_posting_attachment_handling() { global $attachment_mod; - $attachment_mod['posting'] = new attach_posting(); + $attachment_mod['posting'] = new TorrentPier\Legacy\AttachPosting(); $attachment_mod['posting']->posting_attachment_mod(); } diff --git a/library/config.php b/library/config.php index 20207bb23..d4e3a3870 100644 --- a/library/config.php +++ b/library/config.php @@ -285,7 +285,6 @@ define('ATTACH_DIR', BB_PATH . '/library/attach_mod'); define('CFG_DIR', BB_PATH . '/library/config'); define('INC_DIR', BB_PATH . '/library/includes'); define('CLASS_DIR', BB_PATH . '/library/includes/classes'); -define('CORE_DIR', BB_PATH . '/library/includes/core'); define('UCP_DIR', BB_PATH . '/library/includes/ucp'); define('LANG_ROOT_DIR', BB_PATH . '/library/language'); define('IMAGES_DIR', BB_PATH . '/styles/images'); diff --git a/library/includes/bbcode.php b/library/includes/bbcode.php index 3f3fcafc7..99e62851f 100644 --- a/library/includes/bbcode.php +++ b/library/includes/bbcode.php @@ -403,378 +403,18 @@ function add_search_words($post_id, $post_message, $topic_title = '', $only_retu } } -class bbcode -{ - public $tpl = array(); // шаблоны для замены тегов - public $smilies; // смайлы - public $found_spam; // найденные спам "слова" - public $del_words = array(); // см. get_words_rate() - public $tidy_cfg = array( - 'drop-empty-paras' => false, - 'fix-uri' => false, - 'force-output' => true, - 'hide-comments' => true, - 'join-classes' => false, - 'join-styles' => false, - 'merge-divs' => false, - 'newline' => 'LF', - 'output-xhtml' => true, - 'preserve-entities' => true, - 'quiet' => true, - 'quote-ampersand' => false, - 'show-body-only' => true, - 'show-errors' => false, - 'show-warnings' => false, - 'wrap' => 0, - ); - public $block_tags = array( - 'align', - 'br', - 'clear', - 'hr', - 'list', - 'pre', - 'quote', - 'spoiler', - ); - public $preg = array(); - public $str = array(); - public $preg_search = array(); - public $preg_repl = array(); - public $str_search = array(); - public $str_repl = array(); - - /** - * Constructor - */ - public function __construct() - { - $this->tpl = get_bbcode_tpl(); - - $this->init_replacements(); - } - - /** - * init_replacements - */ - public function init_replacements() - { - $tpl = $this->tpl; - $img_exp = '(https?:)?//[^\s\?&;=\#\"<>]+?\.(jpg|jpeg|gif|png)([a-z0-9/?&%;][^\[\]]*)?'; - $email_exp = '[a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+'; - - $this->preg = array( - '#\[quote="(.+?)"\]#isu' => $tpl['quote_username_open'], - '#\[spoiler="(.+?)"\]#isu' => $tpl['spoiler_title_open'], - '#\[list=(a|A|i|I|1)\]#isu' => '