подготовка для нового хранения файлов и работы с ними

This commit is contained in:
PheRum 2015-05-13 04:18:05 +03:00
commit 61851c63e7
12 changed files with 114 additions and 117 deletions

3
.gitignore vendored
View file

@ -34,6 +34,3 @@ $RECYCLE.BIN/
*.orig
*.rej
### TEMP ###
data/old_files/
data/torrent_files/

View file

@ -26,8 +26,7 @@ TorrentPier - движок торрент-трекера, написанный
Исходя из настроек вашего сервера, устанавливаем рекомендуемые права доступа (chmod) на указанные папки **777**, а на файлы внутри этих папок (кроме файлов **.htaccess** и **.keep**) **666**:
- data/avatars
- data/old_files
- data/torrent_files
- data/files
- internal_data/ajax_html
- internal_data/atom
- internal_data/cache
@ -47,7 +46,7 @@ TorrentPier - движок торрент-трекера, написанный
## Необходимые модули php
php5-tidy
php5-tidy php5-filter
Начиная с версии 2.0.9 (ревизия 592 в старой нумерации) данный модуль не является обязательным, но его установка крайне рекомендуется для повышения качества обработки html-кода тем и сообщений пользователей.
## Рекомендуемый способ запуска cron.php

View file

@ -1,3 +0,0 @@
php_flag engine off
RemoveHandler .php .php5 .php4 .php3 .phtml .pl .asp
AddType text/plain .php .php .htm .html .phtml .pl .asp

View file

@ -1,3 +0,0 @@
php_flag engine off
RemoveHandler .php .php5 .php4 .php3 .phtml .pl .asp
AddType text/plain .php .php .htm .html .phtml .pl .asp

View file

@ -136,7 +136,7 @@ INSERT INTO `bb_cron` VALUES (22, 1, 'Sitemap update', 'sitemap.php', 'daily', N
// добавлено 593 ↑
INSERT INTO `bb_cron` VALUES (23, 1, 'Update forums atom', 'update_forums_atom.php', 'interval', NULL, NULL, 255, '', '', '00:15:00', 0, '', 0, 0, 0);
// добавлено 595 ↑
UPDATE `bb_attachments_config` SET `config_value` = 'old_files' WHERE `config_name` = 'upload_dir';
UPDATE `bb_attachments_config` SET `config_value` = 'files' WHERE `config_name` = 'upload_dir';
// изменено 595 ↑
DELETE FROM `bb_smilies` WHERE `code` = ':cd:'; // удалено 596
ALTER TABLE `bb_groups` CHANGE `group_description` `group_description` text NOT NULL DEFAULT '';

View file

@ -167,7 +167,7 @@ class Upload
return false;
}
$this->file_ext_id = @$this->ext_ids[$this->file_ext];
$this->file_ext_id = $this->ext_ids[$this->file_ext];
return true;
}
@ -189,7 +189,7 @@ class Upload
}
else if ($mode == 'attach')
{
$file_path = get_attach_path($params['topic_id']);
$file_path = get_attach_path($params['topic_id'], $params['attach_ext_id']);
return $this->_move($file_path);
}

View file

@ -61,7 +61,7 @@
if (!defined('BB_ROOT')) die(basename(__FILE__));
$bb_cfg = $tr_cfg = $page_cfg = array();
$bb_cfg = $tr_cfg = $page_cfg = [];
// Increase number after changing js or css
$bb_cfg['js_ver'] = $bb_cfg['css_ver'] = 1;
@ -81,13 +81,13 @@ $pconnect = false;
// Настройка баз данных ['db']['srv_name'] => (array) srv_cfg;
// порядок параметров srv_cfg (хост, название базы, пользователь, пароль, charset, pconnect);
$bb_cfg['db'] = array(
'db1' => array('localhost', 'tp_216', 'user', 'pass', $charset, $pconnect),
$bb_cfg['db'] = [
'db1' => ['localhost', 'tp_216', 'user', 'pass', $charset, $pconnect],
//'db2' => array('localhost2', 'dbase2', 'user2', 'pass2', $charset, $pconnect),
//'db3' => array('localhost3', 'dbase3', 'user2', 'pass3', $charset, $pconnect),
);
];
$bb_cfg['db_alias'] = array(
$bb_cfg['db_alias'] = [
// 'alias' => 'srv_name'
# db1
'log' => 'db1', // BB_LOG
@ -101,36 +101,34 @@ $bb_cfg['db_alias'] = array(
# db3
'pm' => 'db1', // BB_PRIVMSGS, BB_PRIVMSGS_TEXT
'pt' => 'db1', // BB_POSTS_TEXT
);
];
// Cache
$bb_cfg['cache']['pconnect'] = true;
$bb_cfg['cache']['db_dir'] = realpath(BB_ROOT) .'/internal_data/cache/filecache/';
$bb_cfg['cache']['prefix'] = 'tp_'; // Префикс кеша ('tp_')
$bb_cfg['cache']['memcache'] = array(
$bb_cfg['cache']['memcache'] = [
'host' => '127.0.0.1',
'port' => 11211,
'pconnect' => true,
'con_required' => true,
);
$bb_cfg['cache']['redis'] = array(
];
$bb_cfg['cache']['redis'] = [
'host' => '127.0.0.1',
'port' => 6379,
'con_required' => true,
);
];
// Available cache types: memcache, sqlite, redis, apc, xcache (default of filecache)
# name => array( (string) type, (array) cfg )
$bb_cfg['cache']['engines'] = array(
'bb_cache' => array('filecache', array()),
'bb_config' => array('filecache', array()),
'tr_cache' => array('filecache', array()),
'bb_session' => array('filecache', array()),
'bb_login_err' => array('filecache', array()),
'bb_poll_data' => array('filecache', array()),
);
// Datastore
// Available datastore types: memcache, sqlite, redis, apc, xcache (default filecache)
$bb_cfg['cache']['engines'] = [
'bb_cache' => ['filecache', []],
'bb_config' => ['filecache', []],
'tr_cache' => ['filecache', []],
'bb_session' => ['filecache', []],
'bb_login_err' => ['filecache', []],
'bb_poll_data' => ['filecache', []],
];
$bb_cfg['datastore_type'] = 'filecache';
// Server
@ -155,14 +153,14 @@ $bb_cfg['verify_reported_ip'] = true; // Verify IP reported by clie
$bb_cfg['allow_internal_ip'] = false; // Allow internal IP (10.xx.. etc.)
// Ocelot
$bb_cfg['ocelot'] = array(
$bb_cfg['ocelot'] = [
'enabled' => false,
'host' => $domain_name,
'port' => 2710,
'url' => "http://$domain_name:2710/", // with '/'
'secret' => 'some_10_chars', // 10 chars
'stats' => 'some_10_chars', // 10 chars
);
];
// FAQ url help link
$bb_cfg['how_to_download_url_help'] = 'viewtopic.php?t=1'; // Как скачивать?
@ -174,7 +172,7 @@ $bb_cfg['search_help_url'] = 'viewtopic.php?t=4'; // Помощь по
$bb_cfg['bt_min_ratio_allow_dl_tor'] = 0.3; // 0 - disable
$bb_cfg['bt_min_ratio_warning'] = 0.6; // 0 - disable
$tr_cfg = array(
$tr_cfg = [
'autoclean' => true,
'off' => false,
'off_reason' => 'temporarily disabled',
@ -197,7 +195,7 @@ $tr_cfg = array(
'retracker' => true,
'retracker_host' => 'http://retracker.local/announce',
'freeleech' => false,
);
];
$bb_cfg['show_dl_status_in_search'] = true;
$bb_cfg['show_dl_status_in_forum'] = true;
@ -205,7 +203,6 @@ $bb_cfg['show_dl_status_in_forum'] = true;
$bb_cfg['show_tor_info_in_dl_list'] = true;
$bb_cfg['allow_dl_list_names_mode'] = true;
$bb_cfg['torrent_name_style'] = true; // use torrent name style [yoursite.com].txxx.torrent
$bb_cfg['tor_help_links'] = 'terms.php';
// Сколько дней сохранять торрент зарегистрированным / Days to keep torrent registered, if:
@ -221,11 +218,11 @@ define('MIN_DL_FOR_RATIO', 10737418240); // 10 GB in bytes, 0 - disable
// rating < 0.5 -- only 2
// rating < 0.6 -- only 3
// rating > 0.6 -- depend on your tracker config limits (in "ACP - Tracker Config - Limits")
$rating_limits = array(
$rating_limits = [
'0.4' => 1,
'0.5' => 2,
'0.6' => 3,
);
];
// DL-Status (days to keep user's dlstatus records)
$bb_cfg['dl_will_days_keep'] = 360;
@ -239,11 +236,11 @@ $bb_cfg['torstat_days_keep'] = 60; // days to keep user's per-torrent sta
// Tor-Help
$bb_cfg['torhelp_enabled'] = false; // find dead torrents (without seeder) that user might help seeding
$page_cfg['show_torhelp'] = array(
$page_cfg['show_torhelp'] = [
# BB_SCRIPT => true
'index' => true,
'tracker' => true,
);
];
// Path (trailing slash '/' at the end: XX_PATH - without, XX_DIR - with)
define('BB_PATH', realpath(BB_ROOT) );
@ -303,31 +300,31 @@ else
}
}
$bb_cfg['lang'] = array(
'ru' => array(
$bb_cfg['lang'] = [
'ru' => [
'name' => 'Русский',
'locale' => 'ru_RU.UTF-8',
'encoding' => 'UTF-8',
'captcha' => 'ru',
),
'uk' => array(
],
'uk' => [
'name' => 'Український',
'locale' => 'uk_UA.UTF-8',
'encoding' => 'UTF-8',
'captcha' => 'uk',
),
'en' => array(
],
'en' => [
'name' => 'English',
'locale' => 'en_US.UTF-8',
'encoding' => 'UTF-8',
'captcha' => 'en',
),
);
],
];
$bb_cfg['templates'] = array(
$bb_cfg['templates'] = [
// 'folder' => 'Name',
'default' => 'Стандартный',
);
];
$bb_cfg['tpl_name'] = 'default';
$bb_cfg['stylesheet'] = 'main.css';
@ -335,17 +332,17 @@ $bb_cfg['stylesheet'] = 'main.css';
$bb_cfg['show_sidebar1_on_every_page'] = false;
$bb_cfg['show_sidebar2_on_every_page'] = false;
$page_cfg['show_sidebar1'] = array(
$page_cfg['show_sidebar1'] = [
# BB_SCRIPT => true
'index' => true,
);
$page_cfg['show_sidebar2'] = array(
];
$page_cfg['show_sidebar2'] = [
# BB_SCRIPT => true
'index' => true,
);
];
// Cookie
$bb_cfg['cookie_domain'] = in_array($domain_name, array(getenv('SERVER_ADDR'), 'localhost')) ? '' : ".$domain_name";
$bb_cfg['cookie_domain'] = in_array($domain_name, [getenv('SERVER_ADDR'), 'localhost']) ? '' : ".$domain_name";
$bb_cfg['cookie_secure'] = (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https') ? 1 : 0;
$bb_cfg['cookie_prefix'] = 'bb_'; // 'bb_'
@ -375,17 +372,17 @@ $bb_cfg['smtp_port'] = 25; // SMTP server port
$bb_cfg['smtp_username'] = ''; // enter a username if your SMTP server requires it
$bb_cfg['smtp_password'] = ''; // enter a password if your SMTP server requires it
$bb_cfg['smtp'] = array(
$bb_cfg['smtp'] = [
'name' => 'yandex.ru',
'host' => 'smtp.yandex.ru',
'port' => 465,
'connection_class' => 'login',
'connection_config' => array(
'connection_config' => [
'username' => '',
'password' => '',
'ssl' => 'ssl',
),
);
],
];
$bb_cfg['board_email'] = "noreply@$domain_name"; // admin email address
$bb_cfg['board_email_form'] = false; // can users send email to each other via board
@ -413,20 +410,20 @@ define('SQL_SLOW_QUERY_TIME', 10); // slow query in seconds
define('SQL_PREPEND_SRC_COMM', false); // prepend source file comment to sql query
// Special users
$bb_cfg['dbg_users'] = array(
$bb_cfg['dbg_users'] = [
# user_id => 'name',
2 => 'admin',
);
];
$bb_cfg['unlimited_users'] = array(
$bb_cfg['unlimited_users'] = [
# user_id => 'name',
2 => 'admin',
);
];
$bb_cfg['super_admins'] = array(
$bb_cfg['super_admins'] = [
# user_id => 'name',
2 => 'admin',
);
];
// Log options
define('LOG_EXT', 'log');
@ -453,7 +450,7 @@ $bb_cfg['date_format'] = 'Y-m-d';
$bb_cfg['sf_on_first_page_only'] = true;
// Forums
$bb_cfg['allowed_topics_per_page'] = array(50, 100, 150, 200, 250, 300);
$bb_cfg['allowed_topics_per_page'] = [50, 100, 150, 200, 250, 300];
// Topics
$bb_cfg['show_quick_reply'] = true;
@ -470,7 +467,7 @@ $bb_cfg['ext_link_new_win'] = true; // open external links in new
$bb_cfg['topic_moved_days_keep'] = 7; // remove topic moved links after xx days (or FALSE to disable)
$bb_cfg['allowed_posts_per_page'] = array(15, 30, 50, 100);
$bb_cfg['allowed_posts_per_page'] = [15, 30, 50, 100];
$bb_cfg['user_signature_start'] = '<div class="signature"><br />_________________<br />';
$bb_cfg['user_signature_end'] = '</div>'; // Это позволит использовать html теги, которые требуют закрытия. Например <table> или <font color>
@ -533,20 +530,20 @@ $bb_cfg['last_visit_date_format'] = 'd-M H:i';
$bb_cfg['last_post_date_format'] = 'd-M-y H:i';
$bb_cfg['poll_max_days'] = 180; // сколько дней с момента создания темы опрос будет активным
$bb_cfg['allow_change'] = array(
$bb_cfg['allow_change'] = [
'language' => true,
'dateformat' => true,
);
];
define('GZIP_OUTPUT_ALLOWED', (extension_loaded('zlib') && !ini_get('zlib.output_compression')));
$banned_user_agents = array(
$banned_user_agents = [
// Download Master
# 'download',
# 'master',
// Others
# 'wget',
);
];
$bb_cfg['trash_forum_id'] = 0; // (int) 7
@ -558,7 +555,7 @@ $bb_cfg['copyright_holders_url'] = 'info.php?show=copyright_holders';
$bb_cfg['advert_url'] = 'info.php?show=advert';
// Extensions
$bb_cfg['file_id_ext'] = array(
$bb_cfg['file_id_ext'] = [
1 => 'gif',
2 => 'gz',
3 => 'jpg',
@ -568,20 +565,20 @@ $bb_cfg['file_id_ext'] = array(
7 => 'tiff',
8 => 'torrent',
9 => 'zip',
);
];
// Attachments
$bb_cfg['attach'] = array(
'upload_path' => DATA_DIR . 'torrent_files', // путь к директории с torrent файлами
$bb_cfg['attach'] = [
'upload_path' => DATA_DIR . 'files', // путь к директории с torrent файлами
'max_size' => 5 * 1024 * 1024, // максимальный размер файла в байтах
);
];
$bb_cfg['tor_forums_allowed_ext'] = array('torrent', 'zip', 'rar'); // для разделов с раздачами
$bb_cfg['gen_forums_allowed_ext'] = array('zip', 'rar'); // для обычных разделов
$bb_cfg['tor_forums_allowed_ext'] = ['torrent', 'zip', 'rar']; // для разделов с раздачами
$bb_cfg['gen_forums_allowed_ext'] = ['zip', 'rar']; // для обычных разделов
// Avatars
$bb_cfg['avatars'] = array(
'allowed_ext' => array('gif','jpg','jpeg','png'), // разрешенные форматы файлов
$bb_cfg['avatars'] = [
'allowed_ext' => ['gif', 'jpg', 'jpeg', 'png'], // разрешенные форматы файлов
'bot_avatar' => 'gallery/bot.gif', // аватара бота
'max_size' => 100 * 1024, // размер аватары в байтах
'max_height' => 100, // высота аватара в px
@ -589,39 +586,39 @@ $bb_cfg['avatars'] = array(
'no_avatar' => 'gallery/noavatar.png', // дефолтная аватара
'upload_path' => BB_ROOT . 'data/avatars/', // путь к директории с аватарами
'up_allowed' => true, // разрешить загрузку аватар
);
];
// Group avatars
$bb_cfg['group_avatars'] = array(
'allowed_ext' => array('gif','jpg','jpeg','png'), // разрешенные форматы файлов
$bb_cfg['group_avatars'] = [
'allowed_ext' => ['gif', 'jpg', 'jpeg', 'png'], // разрешенные форматы файлов
'max_size' => 300 * 1024, // размер аватары в байтах
'max_height' => 300, // высота аватара в px
'max_width' => 300, // ширина аватара в px
'no_avatar' => 'gallery/noavatar.png', // дефолтная аватара
'upload_path' => BB_ROOT . 'data/avatars/', // путь к директории с аватарами
'up_allowed' => true, // разрешить загрузку аватар
);
];
// Captcha
// Get a Google reCAPTCHA API Key: https://www.google.com/recaptcha/admin
$bb_cfg['captcha'] = array(
$bb_cfg['captcha'] = [
'disabled' => false,
'public_key' => '', // your public key
'secret_key' => '', // your secret key
'theme' => 'light', // light or dark
);
];
// Atom feed
$bb_cfg['atom'] = array(
$bb_cfg['atom'] = [
'path' => INT_DATA_DIR . 'atom', // without ending slash
'url' => './internal_data/atom', // without ending slash
);
];
// Nofollow
$bb_cfg['nofollow'] = array(
$bb_cfg['nofollow'] = [
'disabled' => false,
'allowed_url' => array($domain_name), // 'allowed.site', 'www.allowed.site'
);
'allowed_url' => [$domain_name], // 'allowed.site', 'www.allowed.site'
];
// Local config
if (file_exists(BB_ROOT . '/library/config.local.php'))

View file

@ -5,9 +5,9 @@ if (!defined('BB_ROOT')) die(basename(__FILE__));
$map = new sitemap();
$map->create();
if (@file_exists(BB_ROOT. "/sitemap/sitemap.xml"))
if (@file_exists(INT_DATA_DIR . '/sitemap/sitemap.xml'))
{
$map_link = make_url('/sitemap/sitemap.xml');
$map_link = make_url(INT_DATA_DIR . '/sitemap/sitemap.xml');
$map->send_url("http://google.com/webmasters/sitemaps/ping?sitemap=", $map_link);
$map->send_url("http://ping.blogs.yandex.ru/ping?sitemap=", $map_link);

View file

@ -16,19 +16,25 @@ function get_avatar_path ($id, $ext_id, $base_path = null, $first_div = 10000, $
return get_path_from_id($id, $ext_id, $base_path, $first_div, $sec_div);
}
function get_attach_path ($id, $ext_id = '', $base_path = null, $first_div = 10000, $sec_div = 100)
function get_attach_path ($id, $ext_id, $base_path = null, $first_div = 10000, $sec_div = 100)
{
global $bb_cfg;
$base_path = isset($base_path) ? $base_path : $bb_cfg['attach']['upload_path'];
return get_path_from_id($id, $ext_id, $base_path, $first_div, $sec_div);
}
function delete_avatar ($user_id, $avatar_ext_id)
function delete_avatar ($user_id, $ext_id)
{
$avatar_file = ($avatar_ext_id) ? get_avatar_path($user_id, $avatar_ext_id) : '';
$avatar_file = ($ext_id) ? get_avatar_path($user_id, $ext_id) : '';
return ($avatar_file && file_exists($avatar_file)) ? @unlink($avatar_file) : false;
}
function delete_attach ($id, $ext_id)
{
$attach_file = ($ext_id) ? get_attach_path($id, $ext_id) : '';
return ($attach_file && file_exists($attach_file)) ? @unlink($attach_file) : false;
}
function get_tracks ($type)
{
static $pattern = '#^a:\d+:{[i:;\d]+}$#';

View file

@ -12,6 +12,7 @@ function get_torrent_info ($attach_id)
SELECT
a.post_id, d.physical_filename, d.extension, d.tracker_status,
t.topic_first_post_id,
t.attach_ext_id,
p.poster_id, p.topic_id, p.forum_id,
f.allow_reg_tracker
FROM
@ -163,6 +164,7 @@ function delete_torrent ($attach_id, $mode = '')
}
$topic_id = $torrent['topic_id'];
$ext_id = $torrent['attach_ext_id'];
$forum_id = $torrent['forum_id'];
$poster_id = $torrent['poster_id'];
@ -174,6 +176,7 @@ function delete_torrent ($attach_id, $mode = '')
torrent_auth_check($forum_id, $poster_id);
tracker_unregister($attach_id);
delete_attachment(0, $attach_id);
delete_attach($topic_id, $ext_id);
return;
}
@ -259,7 +262,8 @@ function tracker_register ($attach_id, $mode = '', $tor_status = TOR_NOT_APPROVE
torrent_auth_check($forum_id, $torrent['poster_id']);
$filename = get_attachments_dir() .'/'. $torrent['physical_filename'];
$attach_dir = $bb_cfg['attach']['upload_path'];
$filename = $attach_dir .'/'. $torrent['physical_filename'];
if (!is_file($filename)) return torrent_error_exit('File name error');
if (!file_exists($filename)) return torrent_error_exit('File not exists');
@ -528,7 +532,7 @@ function send_torrent_with_passkey ($filename)
// Send torrent
$output = bencode($tor);
$dl_fname = ($bb_cfg['torrent_name_style'] ? '['.$bb_cfg['server_name'].'].t' . $topic_id . '.torrent' : clean_filename(basename($attachment['real_filename'])));
$dl_fname = '['.$bb_cfg['server_name'].'].t' . $topic_id . '.torrent';
if (!empty($_COOKIE['explain']))
{

View file

@ -86,10 +86,7 @@ if ($tor_auth_reg || $tor_auth_del)
$tracker_link = ($tor_reged) ? $unreg_tor_url : $reg_tor_url;
}
if ($bb_cfg['torrent_name_style'])
{
$display_name = '['.$bb_cfg['server_name'].'].t' . $bt_topic_id . '.torrent';
}
if (!$tor_reged)
{

View file

@ -8,11 +8,14 @@ require(INC_DIR .'bbcode.php');
// Start session management
$user->session_start();
if (!$bb_cfg['terms'] && !IS_ADMIN) redirect('index.php');
if (!$bb_cfg['terms'] && !IS_ADMIN)
{
redirect('/');
}
$template->assign_vars(array(
$template->assign_vars([
'TERMS_EDIT' => bbcode2html(sprintf($lang['TERMS_EMPTY_TEXT'], $domain_name)),
'TERMS_HTML' => bbcode2html($bb_cfg['terms']),
));
]);
print_page('terms.tpl');