Replaced some file exists to is file (#1276)

* Replaced some file_exists to is_file

* Update functions_thumbs.php

* Updated

* Update CronHelper.php

* Updated

* Update IPHelper.php

* Updated

* Update update_forums_atom.php

* Update functions.php

* Update Validate.php
This commit is contained in:
Roman Kelesidis 2023-12-27 20:08:00 +07:00 committed by GitHub
commit 3626143879
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 107 additions and 89 deletions

View file

@ -79,7 +79,7 @@ switch ($mode) {
)); ));
//detect cron status //detect cron status
if (file_exists(CRON_RUNNING)) { if (is_file(CRON_RUNNING)) {
$template->assign_vars(array( $template->assign_vars(array(
'CRON_RUNNING' => true, 'CRON_RUNNING' => true,
)); ));
@ -87,7 +87,7 @@ switch ($mode) {
break; break;
case 'repair': case 'repair':
if (file_exists(CRON_RUNNING)) { if (is_file(CRON_RUNNING)) {
rename(CRON_RUNNING, CRON_ALLOWED); rename(CRON_RUNNING, CRON_ALLOWED);
} }
redirect('admin/' . basename(__FILE__) . '?mode=list'); redirect('admin/' . basename(__FILE__) . '?mode=list');

View file

@ -40,7 +40,7 @@ if (!$result = DB()->sql_query($sql)) {
} }
$s_mess = $lang['SITEMAP_CREATED'] . ': <b>' . bb_date($new['sitemap_time'], $bb_cfg['post_date_format']) . '</b> ' . $lang['SITEMAP_AVAILABLE'] . ': <a href="' . make_url('sitemap/sitemap.xml') . '" target="_blank">' . make_url('sitemap/sitemap.xml') . '</a>'; $s_mess = $lang['SITEMAP_CREATED'] . ': <b>' . bb_date($new['sitemap_time'], $bb_cfg['post_date_format']) . '</b> ' . $lang['SITEMAP_AVAILABLE'] . ': <a href="' . make_url('sitemap/sitemap.xml') . '" target="_blank">' . make_url('sitemap/sitemap.xml') . '</a>';
$message = file_exists(SITEMAP_DIR . '/sitemap.xml') ? $s_mess : $lang['SITEMAP_NOT_CREATED']; $message = is_file(SITEMAP_DIR . '/sitemap.xml') ? $s_mess : $lang['SITEMAP_NOT_CREATED'];
$template->assign_vars([ $template->assign_vars([
'STATIC_SITEMAP' => $new['static_sitemap'], 'STATIC_SITEMAP' => $new['static_sitemap'],

View file

@ -67,7 +67,7 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') {
$template->assign_vars([ $template->assign_vars([
'TPL_ADMIN_MAIN' => true, 'TPL_ADMIN_MAIN' => true,
'ADMIN_LOCK' => (bool)$bb_cfg['board_disable'], 'ADMIN_LOCK' => (bool)$bb_cfg['board_disable'],
'ADMIN_LOCK_CRON' => file_exists(BB_DISABLED), 'ADMIN_LOCK_CRON' => is_file(BB_DISABLED),
]); ]);
// Get forum statistics // Get forum statistics

View file

@ -49,7 +49,7 @@ if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
require_once BB_PATH . '/library/defines.php'; require_once BB_PATH . '/library/defines.php';
// Composer // Composer
if (!file_exists(BB_PATH . '/vendor/autoload.php')) { if (!is_file(BB_PATH . '/vendor/autoload.php')) {
die('Please <a href="https://getcomposer.org/download/" target="_blank" rel="noreferrer" style="color:#0a25bb;">install composer</a> and run <code style="background:#222;color:#00e01f;padding:2px 6px;border-radius:3px;">composer install</code>'); die('Please <a href="https://getcomposer.org/download/" target="_blank" rel="noreferrer" style="color:#0a25bb;">install composer</a> and run <code style="background:#222;color:#00e01f;padding:2px 6px;border-radius:3px;">composer install</code>');
} }
require_once BB_PATH . '/vendor/autoload.php'; require_once BB_PATH . '/vendor/autoload.php';
@ -58,10 +58,10 @@ require_once BB_PATH . '/vendor/autoload.php';
* Gets the value of an environment variable. * Gets the value of an environment variable.
* *
* @param string $key * @param string $key
* @param mixed $default * @param mixed|null $default
* @return mixed * @return mixed
*/ */
function env(string $key, $default = null) function env(string $key, mixed $default = null): mixed
{ {
return \TorrentPier\Env::get($key, $default); return \TorrentPier\Env::get($key, $default);
} }
@ -78,7 +78,7 @@ try {
require_once BB_PATH . '/library/config.php'; require_once BB_PATH . '/library/config.php';
// Local config // Local config
if (file_exists(BB_PATH . '/library/config.local.php')) { if (is_file(BB_PATH . '/library/config.local.php')) {
require_once BB_PATH . '/library/config.local.php'; require_once BB_PATH . '/library/config.local.php';
} }
@ -357,7 +357,7 @@ if (!defined('IN_TRACKER')) {
if (!defined('IN_ADMIN')) { if (!defined('IN_ADMIN')) {
// Exit if tracker is disabled via ON/OFF trigger // Exit if tracker is disabled via ON/OFF trigger
if (file_exists(BB_DISABLED)) { if (is_file(BB_DISABLED)) {
dummy_exit(random_int(60, 2400)); dummy_exit(random_int(60, 2400));
} }
} }

View file

@ -34,7 +34,7 @@ if ($mode === 'get_feed_url' && ($type === 'f' || $type === 'u') && $id >= 0) {
bb_simple_die($lang['ATOM_ERROR'] . ' #1'); bb_simple_die($lang['ATOM_ERROR'] . ' #1');
} }
} }
if (file_exists($bb_cfg['atom']['path'] . '/f/' . $id . '.atom') && filemtime($bb_cfg['atom']['path'] . '/f/' . $id . '.atom') > $timecheck) { if (is_file($bb_cfg['atom']['path'] . '/f/' . $id . '.atom') && filemtime($bb_cfg['atom']['path'] . '/f/' . $id . '.atom') > $timecheck) {
redirect($bb_cfg['atom']['url'] . '/f/' . $id . '.atom'); redirect($bb_cfg['atom']['url'] . '/f/' . $id . '.atom');
} else { } else {
if (\TorrentPier\Legacy\Atom::update_forum_feed($id, $forum_data)) { if (\TorrentPier\Legacy\Atom::update_forum_feed($id, $forum_data)) {
@ -52,7 +52,7 @@ if ($mode === 'get_feed_url' && ($type === 'f' || $type === 'u') && $id >= 0) {
if (!$username = get_username($id)) { if (!$username = get_username($id)) {
bb_simple_die($lang['ATOM_ERROR'] . ' #3'); bb_simple_die($lang['ATOM_ERROR'] . ' #3');
} }
if (file_exists($bb_cfg['atom']['path'] . '/u/' . floor($id / 5000) . '/' . ($id % 100) . '/' . $id . '.atom') && filemtime($bb_cfg['atom']['path'] . '/u/' . floor($id / 5000) . '/' . ($id % 100) . '/' . $id . '.atom') > $timecheck) { if (is_file($bb_cfg['atom']['path'] . '/u/' . floor($id / 5000) . '/' . ($id % 100) . '/' . $id . '.atom') && filemtime($bb_cfg['atom']['path'] . '/u/' . floor($id / 5000) . '/' . ($id % 100) . '/' . $id . '.atom') > $timecheck) {
redirect($bb_cfg['atom']['url'] . '/u/' . floor($id / 5000) . '/' . ($id % 100) . '/' . $id . '.atom'); redirect($bb_cfg['atom']['url'] . '/u/' . floor($id / 5000) . '/' . ($id % 100) . '/' . $id . '.atom');
} else { } else {
if (\TorrentPier\Legacy\Atom::update_user_feed($id, $username)) { if (\TorrentPier\Legacy\Atom::update_user_feed($id, $username)) {

View file

@ -304,7 +304,7 @@ $template->assign_vars([
'U_SEARCH_SELF_BY_MY' => "search.php?uid={$userdata['user_id']}&amp;o=1", 'U_SEARCH_SELF_BY_MY' => "search.php?uid={$userdata['user_id']}&amp;o=1",
'U_SEARCH_LATEST' => 'search.php?search_id=latest', 'U_SEARCH_LATEST' => 'search.php?search_id=latest',
'U_SEARCH_UNANSWERED' => 'search.php?search_id=unanswered', 'U_SEARCH_UNANSWERED' => 'search.php?search_id=unanswered',
'U_ATOM_FEED' => file_exists($bb_cfg['atom']['path'] . '/f/0.atom') ? make_url($bb_cfg['atom']['url'] . '/f/0.atom') : false, 'U_ATOM_FEED' => is_file($bb_cfg['atom']['path'] . '/f/0.atom') ? make_url($bb_cfg['atom']['url'] . '/f/0.atom') : false,
'SHOW_LAST_TOPIC' => $show_last_topic, 'SHOW_LAST_TOPIC' => $show_last_topic,
'BOARD_START' => $bb_cfg['show_board_start_index'] ? ($lang['BOARD_STARTED'] . ':&nbsp;' . '<b>' . bb_date($bb_cfg['board_startdate']) . '</b>') : false, 'BOARD_START' => $bb_cfg['show_board_start_index'] ? ($lang['BOARD_STARTED'] . ':&nbsp;' . '<b>' . bb_date($bb_cfg['board_startdate']) . '</b>') : false,
@ -395,8 +395,8 @@ if ($bb_cfg['birthday_check_day'] && $bb_cfg['birthday_enabled']) {
// Allow cron // Allow cron
if (IS_AM) { if (IS_AM) {
if (file_exists(CRON_RUNNING)) { if (is_file(CRON_RUNNING)) {
if (file_exists(CRON_ALLOWED)) { if (is_file(CRON_ALLOWED)) {
unlink(CRON_ALLOWED); unlink(CRON_ALLOWED);
} }
rename(CRON_RUNNING, CRON_ALLOWED); rename(CRON_RUNNING, CRON_ALLOWED);

View file

@ -40,7 +40,7 @@ switch ((string)$_REQUEST['show'] ?? 'not_found') {
break; break;
} }
$require = file_exists($htmlDir . $info['src']) ? ($htmlDir . $info['src']) : false; $require = is_file($htmlDir . $info['src']) ? ($htmlDir . $info['src']) : false;
$template->assign_vars([ $template->assign_vars([
'PAGE_TITLE' => mb_strtoupper($info['title'], 'UTF-8'), 'PAGE_TITLE' => mb_strtoupper($info['title'], 'UTF-8'),

View file

@ -23,7 +23,7 @@ $html = '';
switch ($mode) { switch ($mode) {
case 'create': case 'create':
$map->createSitemap(); $map->createSitemap();
if (file_exists(SITEMAP_DIR . '/sitemap.xml')) { if (is_file(SITEMAP_DIR . '/sitemap.xml')) {
$html .= $lang['SITEMAP_CREATED'] . ': <b>' . bb_date(TIMENOW, $bb_cfg['post_date_format']) . '</b> ' . $lang['SITEMAP_AVAILABLE'] . ': <a href="' . make_url('sitemap/sitemap.xml') . '" target="_blank">' . make_url('sitemap/sitemap.xml') . '</a>'; $html .= $lang['SITEMAP_CREATED'] . ': <b>' . bb_date(TIMENOW, $bb_cfg['post_date_format']) . '</b> ' . $lang['SITEMAP_AVAILABLE'] . ': <a href="' . make_url('sitemap/sitemap.xml') . '" target="_blank">' . make_url('sitemap/sitemap.xml') . '</a>';
} else { } else {
$html .= $lang['SITEMAP_NOT_CREATED']; $html .= $lang['SITEMAP_NOT_CREATED'];
@ -31,7 +31,7 @@ switch ($mode) {
break; break;
case 'search_update': case 'search_update':
if (!file_exists(SITEMAP_DIR . '/sitemap.xml')) { if (!is_file(SITEMAP_DIR . '/sitemap.xml')) {
$map->createSitemap(); $map->createSitemap();
} }

View file

@ -23,8 +23,9 @@ if (!$torrent) {
$this->ajax_die($lang['ERROR_BUILD']); $this->ajax_die($lang['ERROR_BUILD']);
} }
$file_contents = null;
$filename = get_attachments_dir() . '/' . $torrent['physical_filename']; $filename = get_attachments_dir() . '/' . $torrent['physical_filename'];
if (!file_exists($filename) || !$file_contents = file_get_contents($filename)) { if (!is_file($filename) || !$file_contents = file_get_contents($filename)) {
$this->ajax_die($lang['ERROR_NO_ATTACHMENT'] . "\n\n" . htmlCHR($filename)); $this->ajax_die($lang['ERROR_NO_ATTACHMENT'] . "\n\n" . htmlCHR($filename));
} }

View file

@ -24,13 +24,14 @@ function createThumbnail(string $source, string $newFile, string $mimeType): boo
{ {
global $attach_config; global $attach_config;
// Get the file information // Check for source image existence
$source = realpath($source); if (!$source = realpath($source)) {
$min_filesize = (int)$attach_config['img_min_thumb_filesize']; return false;
$img_filesize = file_exists($source) ? filesize($source) : false; }
// Checks the max allowed filesize // Checks the max allowed filesize
if (!$img_filesize || $img_filesize <= $min_filesize) { $min_filesize = (int)$attach_config['img_min_thumb_filesize'];
if (!filesize($source) || filesize($source) <= $min_filesize) {
return false; return false;
} }
@ -48,7 +49,7 @@ function createThumbnail(string $source, string $newFile, string $mimeType): boo
} }
// Check the thumbnail existence after creating // Check the thumbnail existence after creating
if (!file_exists($newFile)) { if (!is_file($newFile)) {
return false; return false;
} }

View file

@ -765,7 +765,7 @@ $bb_cfg['post_img_width_decr'] = 52;
$bb_cfg['attach_img_width_decr'] = 130; $bb_cfg['attach_img_width_decr'] = 130;
// Get default lang // Get default lang
if (isset($bb_cfg['default_lang']) && file_exists(LANG_ROOT_DIR . '/' . $bb_cfg['default_lang'])) { if (isset($bb_cfg['default_lang']) && is_file(LANG_ROOT_DIR . '/' . $bb_cfg['default_lang'])) {
$bb_cfg['default_lang_dir'] = LANG_ROOT_DIR . '/' . $bb_cfg['default_lang'] . '/'; $bb_cfg['default_lang_dir'] = LANG_ROOT_DIR . '/' . $bb_cfg['default_lang'] . '/';
} else { } else {
$bb_cfg['default_lang_dir'] = LANG_ROOT_DIR . '/en/'; $bb_cfg['default_lang_dir'] = LANG_ROOT_DIR . '/en/';

View file

@ -43,7 +43,7 @@ DB()->add_shutdown_query("
foreach ($cron_jobs as $job) { foreach ($cron_jobs as $job) {
$job_script = CRON_JOB_DIR . basename($job['cron_script']); $job_script = CRON_JOB_DIR . basename($job['cron_script']);
if (file_exists($job_script)) { if (is_file($job_script)) {
$cron_start_time = utime(); $cron_start_time = utime();
$cron_runtime_log = ''; $cron_runtime_log = '';
$cron_write_log = (CRON_LOG_ENABLED && (CRON_FORCE_LOG || $job['log_enabled'] >= 1)); $cron_write_log = (CRON_LOG_ENABLED && (CRON_FORCE_LOG || $job['log_enabled'] >= 1));

View file

@ -14,7 +14,7 @@ if (!defined('BB_ROOT')) {
$map = new TorrentPier\Sitemap(); $map = new TorrentPier\Sitemap();
$map->createSitemap(); $map->createSitemap();
if (file_exists(SITEMAP_DIR . '/sitemap.xml')) { if (is_file(SITEMAP_DIR . '/sitemap.xml')) {
$map_link = make_url(hide_bb_path(SITEMAP_DIR . '/sitemap.xml')); $map_link = make_url(hide_bb_path(SITEMAP_DIR . '/sitemap.xml'));
foreach ($bb_cfg['sitemap_sending'] as $source_name => $source_link) { foreach ($bb_cfg['sitemap_sending'] as $source_name => $source_link) {

View file

@ -16,7 +16,7 @@ global $bb_cfg;
$timecheck = TIMENOW - 600; $timecheck = TIMENOW - 600;
$forums_data = DB()->fetch_rowset("SELECT forum_id, allow_reg_tracker, forum_name FROM " . BB_FORUMS); $forums_data = DB()->fetch_rowset("SELECT forum_id, allow_reg_tracker, forum_name FROM " . BB_FORUMS);
if (file_exists($bb_cfg['atom']['path'] . '/f/0.atom')) { if (is_file($bb_cfg['atom']['path'] . '/f/0.atom')) {
if (filemtime($bb_cfg['atom']['path'] . '/f/0.atom') <= $timecheck) { if (filemtime($bb_cfg['atom']['path'] . '/f/0.atom') <= $timecheck) {
\TorrentPier\Legacy\Atom::update_forum_feed(0, $forums_data); \TorrentPier\Legacy\Atom::update_forum_feed(0, $forums_data);
} }
@ -25,7 +25,7 @@ if (file_exists($bb_cfg['atom']['path'] . '/f/0.atom')) {
} }
foreach ($forums_data as $forum_data) { foreach ($forums_data as $forum_data) {
if (file_exists($bb_cfg['atom']['path'] . '/f/' . $forum_data['forum_id'] . '.atom')) { if (is_file($bb_cfg['atom']['path'] . '/f/' . $forum_data['forum_id'] . '.atom')) {
if (filemtime($bb_cfg['atom']['path'] . '/f/' . $forum_data['forum_id'] . '.atom') <= $timecheck) { if (filemtime($bb_cfg['atom']['path'] . '/f/' . $forum_data['forum_id'] . '.atom') <= $timecheck) {
\TorrentPier\Legacy\Atom::update_forum_feed($forum_data['forum_id'], $forum_data); \TorrentPier\Legacy\Atom::update_forum_feed($forum_data['forum_id'], $forum_data);
} }

View file

@ -35,7 +35,7 @@ function get_attach_path($id, $ext_id = '', $base_path = null, $first_div = 1000
function delete_avatar($user_id, $avatar_ext_id) function delete_avatar($user_id, $avatar_ext_id)
{ {
$avatar_file = $avatar_ext_id ? get_avatar_path($user_id, $avatar_ext_id) : false; $avatar_file = $avatar_ext_id ? get_avatar_path($user_id, $avatar_ext_id) : false;
return ($avatar_file && file_exists($avatar_file) && unlink($avatar_file)); return ($avatar_file && is_file($avatar_file) && unlink($avatar_file));
} }
function get_tracks($type) function get_tracks($type)
@ -2001,7 +2001,7 @@ function get_avatar($user_id, $ext_id, $allow_avatar = true, $height = '', $widt
if ($user_id == BOT_UID && $bb_cfg['avatars']['bot_avatar']) { if ($user_id == BOT_UID && $bb_cfg['avatars']['bot_avatar']) {
$user_avatar = '<img src="' . make_url($bb_cfg['avatars']['display_path'] . $bb_cfg['avatars']['bot_avatar']) . '" alt="' . $user_id . '" ' . $height . ' ' . $width . ' />'; $user_avatar = '<img src="' . make_url($bb_cfg['avatars']['display_path'] . $bb_cfg['avatars']['bot_avatar']) . '" alt="' . $user_id . '" ' . $height . ' ' . $width . ' />';
} elseif ($allow_avatar && $ext_id) { } elseif ($allow_avatar && $ext_id) {
if (file_exists(get_avatar_path($user_id, $ext_id))) { if (is_file(get_avatar_path($user_id, $ext_id))) {
$user_avatar = '<img src="' . make_url(get_avatar_path($user_id, $ext_id, $bb_cfg['avatars']['display_path'])) . '" alt="' . $user_id . '" ' . $height . ' ' . $width . ' />'; $user_avatar = '<img src="' . make_url(get_avatar_path($user_id, $ext_id, $bb_cfg['avatars']['display_path'])) . '" alt="' . $user_id . '" ' . $height . ' ' . $width . ' />';
} }
} }

View file

@ -400,7 +400,7 @@ $userdata =& $user->data;
if ( if (
empty($_POST) && empty($_POST) &&
!defined('IN_ADMIN') && !defined('IN_AJAX') && !defined('IN_ADMIN') && !defined('IN_AJAX') &&
!file_exists(CRON_RUNNING) && !is_file(CRON_RUNNING) &&
(TorrentPier\Helpers\CronHelper::isEnabled() || defined('START_CRON')) (TorrentPier\Helpers\CronHelper::isEnabled() || defined('START_CRON'))
) { ) {
if (TIMENOW - $bb_cfg['cron_last_check'] > $bb_cfg['cron_check_interval']) { if (TIMENOW - $bb_cfg['cron_last_check'] > $bb_cfg['cron_check_interval']) {
@ -443,13 +443,13 @@ if (
/** /**
* Exit if board is disabled via trigger * Exit if board is disabled via trigger
*/ */
if (($bb_cfg['board_disable'] || file_exists(BB_DISABLED)) && !defined('IN_ADMIN') && !defined('IN_AJAX') && !defined('IN_LOGIN')) { if (($bb_cfg['board_disable'] || is_file(BB_DISABLED)) && !defined('IN_ADMIN') && !defined('IN_AJAX') && !defined('IN_LOGIN')) {
http_response_code(503); http_response_code(503);
if ($bb_cfg['board_disable']) { if ($bb_cfg['board_disable']) {
// admin lock // admin lock
send_no_cache_headers(); send_no_cache_headers();
bb_die('BOARD_DISABLE'); bb_die('BOARD_DISABLE');
} elseif (file_exists(BB_DISABLED)) { } elseif (is_file(BB_DISABLED)) {
// trigger lock // trigger lock
TorrentPier\Helpers\CronHelper::releaseDeadlock(); TorrentPier\Helpers\CronHelper::releaseDeadlock();
send_no_cache_headers(); send_no_cache_headers();

View file

@ -88,11 +88,11 @@ class Ajax
} }
// Exit if board is disabled via ON/OFF trigger or by admin // Exit if board is disabled via ON/OFF trigger or by admin
if ($bb_cfg['board_disable'] || file_exists(BB_DISABLED)) { if ($bb_cfg['board_disable'] || is_file(BB_DISABLED)) {
if (!isset($action_params[1]) || $action_params[1] !== true) { if (!isset($action_params[1]) || $action_params[1] !== true) {
if ($bb_cfg['board_disable']) { if ($bb_cfg['board_disable']) {
$this->ajax_die($lang['BOARD_DISABLE']); $this->ajax_die($lang['BOARD_DISABLE']);
} elseif (file_exists(BB_DISABLED)) { } elseif (is_file(BB_DISABLED)) {
$this->ajax_die($lang['BOARD_DISABLE_CRON']); $this->ajax_die($lang['BOARD_DISABLE_CRON']);
} }
} }

View file

@ -94,10 +94,10 @@ class Emailer
if (empty($this->tpl_msg[$template_lang . $template_file])) { if (empty($this->tpl_msg[$template_lang . $template_file])) {
$tpl_file = LANG_ROOT_DIR . '/' . $template_lang . '/email/' . $template_file . '.html'; $tpl_file = LANG_ROOT_DIR . '/' . $template_lang . '/email/' . $template_file . '.html';
if (!file_exists($tpl_file)) { if (!is_file($tpl_file)) {
$tpl_file = LANG_ROOT_DIR . '/' . $bb_cfg['default_lang'] . '/email/' . $template_file . '.html'; $tpl_file = LANG_ROOT_DIR . '/' . $bb_cfg['default_lang'] . '/email/' . $template_file . '.html';
if (!file_exists($tpl_file)) { if (!is_file($tpl_file)) {
bb_die('Could not find email template file: ' . $template_file); bb_die('Could not find email template file: ' . $template_file);
} }
} }

View file

@ -32,7 +32,7 @@ class CronHelper
*/ */
public static function releaseDeadlock(): void public static function releaseDeadlock(): void
{ {
if (file_exists(CRON_RUNNING)) { if (is_file(CRON_RUNNING)) {
if (TIMENOW - filemtime(CRON_RUNNING) > 2400) { if (TIMENOW - filemtime(CRON_RUNNING) > 2400) {
self::enableBoard(); self::enableBoard();
self::releaseLockFile(); self::releaseLockFile();
@ -47,7 +47,7 @@ class CronHelper
*/ */
public static function releaseLockFile(): void public static function releaseLockFile(): void
{ {
if (file_exists(CRON_RUNNING)) { if (is_file(CRON_RUNNING)) {
rename(CRON_RUNNING, CRON_ALLOWED); rename(CRON_RUNNING, CRON_ALLOWED);
} }
self::touchLockFile(CRON_ALLOWED); self::touchLockFile(CRON_ALLOWED);
@ -57,7 +57,6 @@ class CronHelper
* Создание файла блокировки * Создание файла блокировки
* *
* @param string $lock_file * @param string $lock_file
*
* @return void * @return void
*/ */
public static function touchLockFile(string $lock_file): void public static function touchLockFile(string $lock_file): void
@ -72,7 +71,7 @@ class CronHelper
*/ */
public static function enableBoard(): void public static function enableBoard(): void
{ {
if (file_exists(BB_DISABLED)) { if (is_file(BB_DISABLED)) {
rename(BB_DISABLED, BB_ENABLED); rename(BB_DISABLED, BB_ENABLED);
} }
} }
@ -84,7 +83,7 @@ class CronHelper
*/ */
public static function disableBoard(): void public static function disableBoard(): void
{ {
if (file_exists(BB_ENABLED)) { if (is_file(BB_ENABLED)) {
rename(BB_ENABLED, BB_DISABLED); rename(BB_ENABLED, BB_DISABLED);
} }
} }
@ -98,11 +97,11 @@ class CronHelper
{ {
$lock_obtained = false; $lock_obtained = false;
if (file_exists(CRON_ALLOWED)) { if (is_file(CRON_ALLOWED)) {
$lock_obtained = rename(CRON_ALLOWED, CRON_RUNNING); $lock_obtained = rename(CRON_ALLOWED, CRON_RUNNING);
} elseif (file_exists(CRON_RUNNING)) { } elseif (is_file(CRON_RUNNING)) {
self::releaseDeadlock(); self::releaseDeadlock();
} elseif (!file_exists(CRON_ALLOWED) && !file_exists(CRON_RUNNING)) { } elseif (!is_file(CRON_ALLOWED) && !is_file(CRON_RUNNING)) {
file_write('', CRON_ALLOWED); file_write('', CRON_ALLOWED);
$lock_obtained = rename(CRON_ALLOWED, CRON_RUNNING); $lock_obtained = rename(CRON_ALLOWED, CRON_RUNNING);
} }
@ -114,8 +113,9 @@ class CronHelper
* Отслеживание запуска задач * Отслеживание запуска задач
* *
* @param string $mode * @param string $mode
* @return void
*/ */
public static function trackRunning(string $mode) public static function trackRunning(string $mode): void
{ {
if (!defined('START_MARK')) { if (!defined('START_MARK')) {
define('START_MARK', TRIGGERS_DIR . '/cron_started_at_' . date('Y-m-d_H-i-s') . '_by_pid_' . getmypid()); define('START_MARK', TRIGGERS_DIR . '/cron_started_at_' . date('Y-m-d_H-i-s') . '_by_pid_' . getmypid());
@ -127,7 +127,7 @@ class CronHelper
file_write('', START_MARK); file_write('', START_MARK);
break; break;
case 'end': case 'end':
if (file_exists(START_MARK)) { if (is_file(START_MARK)) {
unlink(START_MARK); unlink(START_MARK);
} }
break; break;

View file

@ -60,7 +60,6 @@ class IPHelper extends Ip
* @param string $ip * @param string $ip
* @return string * @return string
*/ */
public static function long2ip_extended(string $ip): string public static function long2ip_extended(string $ip): string
{ {
return self::long2ip($ip, $ip > 0xFFFFFFFF); return self::long2ip($ip, $ip > 0xFFFFFFFF);

View file

@ -30,38 +30,4 @@ class IsHelper
} }
return $is_secure; return $is_secure;
} }
/**
* Return true if $value contains numbers
*
* @param string $value
* @return bool
*/
public static function isContainsNums(string $value): bool
{
return preg_match('@[[:digit:]]@', $value);
}
/**
* Return true if $value contains letters (Uppercase included)
*
* @param string $value
* @param bool $uppercase
* @return bool
*/
public static function isContainsLetters(string $value, bool $uppercase = false): bool
{
return $uppercase ? preg_match('@[A-Z]@', $value) : preg_match('@[a-z]@', $value);
}
/**
* Return true if $value contains special symbols
*
* @param string $value
* @return bool
*/
public static function isContainsSpecSymbols(string $value): bool
{
return preg_match('@[[:punct:]]@', $value);
}
} }

View file

@ -0,0 +1,51 @@
<?php
/**
* TorrentPier Bull-powered BitTorrent tracker engine
*
* @copyright Copyright (c) 2005-2024 TorrentPier (https://torrentpier.com)
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
*/
namespace TorrentPier\Helpers;
/**
* Class StringHelper
* @package TorrentPier\Helpers
*/
class StringHelper
{
/**
* Return true if $value contains numbers
*
* @param string $value
* @return bool
*/
public static function isContainsNums(string $value): bool
{
return preg_match('@[[:digit:]]@', $value);
}
/**
* Return true if $value contains letters (Uppercase included)
*
* @param string $value
* @param bool $uppercase
* @return bool
*/
public static function isContainsLetters(string $value, bool $uppercase = false): bool
{
return $uppercase ? preg_match('@[A-Z]@', $value) : preg_match('@[a-z]@', $value);
}
/**
* Return true if $value contains special symbols
*
* @param string $value
* @return bool
*/
public static function isContainsSpecSymbols(string $value): bool
{
return preg_match('@[[:punct:]]@', $value);
}
}

View file

@ -111,7 +111,7 @@ class Template
$this->use_cache = $bb_cfg['xs_use_cache']; $this->use_cache = $bb_cfg['xs_use_cache'];
// Check template exists // Check template exists
if (!file_exists($this->root) || !is_dir($this->root)) { if (!is_dir($this->root)) {
die("Theme ({$this->tpl}) directory not found"); die("Theme ({$this->tpl}) directory not found");
} }
} }

View file

@ -16,7 +16,7 @@ use Egulias\EmailValidator\Validation\RFCValidation;
use Egulias\EmailValidator\Validation\MessageIDValidation; use Egulias\EmailValidator\Validation\MessageIDValidation;
use Egulias\EmailValidator\Validation\Extra\SpoofCheckValidation; use Egulias\EmailValidator\Validation\Extra\SpoofCheckValidation;
use TorrentPier\Helpers\IsHelper; use TorrentPier\Helpers\StringHelper;
/** /**
* Class Validate * Class Validate
@ -181,24 +181,24 @@ class Validate
if ($bb_cfg['password_symbols']) { if ($bb_cfg['password_symbols']) {
// Numbers // Numbers
if ($bb_cfg['password_symbols']['nums']) { if ($bb_cfg['password_symbols']['nums']) {
if (!IsHelper::isContainsNums($password)) { if (!StringHelper::isContainsNums($password)) {
return $lang['CHOOSE_PASS_ERR_NUM']; return $lang['CHOOSE_PASS_ERR_NUM'];
} }
} }
// Letters // Letters
if ($bb_cfg['password_symbols']['letters']['lowercase']) { if ($bb_cfg['password_symbols']['letters']['lowercase']) {
if (!IsHelper::isContainsLetters($password)) { if (!StringHelper::isContainsLetters($password)) {
return $lang['CHOOSE_PASS_ERR_LETTER']; return $lang['CHOOSE_PASS_ERR_LETTER'];
} }
} }
if ($bb_cfg['password_symbols']['letters']['uppercase']) { if ($bb_cfg['password_symbols']['letters']['uppercase']) {
if (!IsHelper::isContainsLetters($password, true)) { if (!StringHelper::isContainsLetters($password, true)) {
return $lang['CHOOSE_PASS_ERR_LETTER_UPPERCASE']; return $lang['CHOOSE_PASS_ERR_LETTER_UPPERCASE'];
} }
} }
// Spec symbols // Spec symbols
if ($bb_cfg['password_symbols']['spec_symbols']) { if ($bb_cfg['password_symbols']['spec_symbols']) {
if (!IsHelper::isContainsSpecSymbols($password)) { if (!StringHelper::isContainsSpecSymbols($password)) {
return $lang['CHOOSE_PASS_ERR_SPEC_SYMBOL']; return $lang['CHOOSE_PASS_ERR_SPEC_SYMBOL'];
} }
} }