diff --git a/admin/admin_cron.php b/admin/admin_cron.php index 74d8bd24a..65bab3b8a 100644 --- a/admin/admin_cron.php +++ b/admin/admin_cron.php @@ -79,7 +79,7 @@ switch ($mode) { )); //detect cron status - if (file_exists(CRON_RUNNING)) { + if (is_file(CRON_RUNNING)) { $template->assign_vars(array( 'CRON_RUNNING' => true, )); @@ -87,7 +87,7 @@ switch ($mode) { break; case 'repair': - if (file_exists(CRON_RUNNING)) { + if (is_file(CRON_RUNNING)) { rename(CRON_RUNNING, CRON_ALLOWED); } redirect('admin/' . basename(__FILE__) . '?mode=list'); diff --git a/admin/admin_sitemap.php b/admin/admin_sitemap.php index 4da8d36a3..8aef3b309 100644 --- a/admin/admin_sitemap.php +++ b/admin/admin_sitemap.php @@ -40,7 +40,7 @@ if (!$result = DB()->sql_query($sql)) { } $s_mess = $lang['SITEMAP_CREATED'] . ': ' . bb_date($new['sitemap_time'], $bb_cfg['post_date_format']) . ' ' . $lang['SITEMAP_AVAILABLE'] . ': ' . make_url('sitemap/sitemap.xml') . ''; -$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([ 'STATIC_SITEMAP' => $new['static_sitemap'], diff --git a/admin/index.php b/admin/index.php index 45a635ed0..5628bd95e 100644 --- a/admin/index.php +++ b/admin/index.php @@ -67,7 +67,7 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') { $template->assign_vars([ 'TPL_ADMIN_MAIN' => true, 'ADMIN_LOCK' => (bool)$bb_cfg['board_disable'], - 'ADMIN_LOCK_CRON' => file_exists(BB_DISABLED), + 'ADMIN_LOCK_CRON' => is_file(BB_DISABLED), ]); // Get forum statistics diff --git a/common.php b/common.php index 72cafbf27..cfd102232 100644 --- a/common.php +++ b/common.php @@ -49,7 +49,7 @@ if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) { require_once BB_PATH . '/library/defines.php'; // Composer -if (!file_exists(BB_PATH . '/vendor/autoload.php')) { +if (!is_file(BB_PATH . '/vendor/autoload.php')) { die('Please install composer and run composer install'); } 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. * * @param string $key - * @param mixed $default + * @param mixed|null $default * @return mixed */ -function env(string $key, $default = null) +function env(string $key, mixed $default = null): mixed { return \TorrentPier\Env::get($key, $default); } @@ -78,7 +78,7 @@ try { require_once BB_PATH . '/library/config.php'; // 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'; } @@ -357,7 +357,7 @@ if (!defined('IN_TRACKER')) { if (!defined('IN_ADMIN')) { // 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)); } } diff --git a/feed.php b/feed.php index 6409116f7..e0ec37e0b 100644 --- a/feed.php +++ b/feed.php @@ -34,7 +34,7 @@ if ($mode === 'get_feed_url' && ($type === 'f' || $type === 'u') && $id >= 0) { 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'); } else { 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)) { 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'); } else { if (\TorrentPier\Legacy\Atom::update_user_feed($id, $username)) { diff --git a/index.php b/index.php index e2b48e3c1..42121c302 100644 --- a/index.php +++ b/index.php @@ -304,7 +304,7 @@ $template->assign_vars([ 'U_SEARCH_SELF_BY_MY' => "search.php?uid={$userdata['user_id']}&o=1", 'U_SEARCH_LATEST' => 'search.php?search_id=latest', '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, 'BOARD_START' => $bb_cfg['show_board_start_index'] ? ($lang['BOARD_STARTED'] . ': ' . '' . bb_date($bb_cfg['board_startdate']) . '') : false, @@ -395,8 +395,8 @@ if ($bb_cfg['birthday_check_day'] && $bb_cfg['birthday_enabled']) { // Allow cron if (IS_AM) { - if (file_exists(CRON_RUNNING)) { - if (file_exists(CRON_ALLOWED)) { + if (is_file(CRON_RUNNING)) { + if (is_file(CRON_ALLOWED)) { unlink(CRON_ALLOWED); } rename(CRON_RUNNING, CRON_ALLOWED); diff --git a/info.php b/info.php index 049b4fe14..3a66fae2a 100644 --- a/info.php +++ b/info.php @@ -40,7 +40,7 @@ switch ((string)$_REQUEST['show'] ?? 'not_found') { break; } -$require = file_exists($htmlDir . $info['src']) ? ($htmlDir . $info['src']) : false; +$require = is_file($htmlDir . $info['src']) ? ($htmlDir . $info['src']) : false; $template->assign_vars([ 'PAGE_TITLE' => mb_strtoupper($info['title'], 'UTF-8'), diff --git a/library/ajax/sitemap.php b/library/ajax/sitemap.php index 531bd2b89..b710fdc8f 100644 --- a/library/ajax/sitemap.php +++ b/library/ajax/sitemap.php @@ -23,7 +23,7 @@ $html = ''; switch ($mode) { case 'create': $map->createSitemap(); - if (file_exists(SITEMAP_DIR . '/sitemap.xml')) { + if (is_file(SITEMAP_DIR . '/sitemap.xml')) { $html .= $lang['SITEMAP_CREATED'] . ': ' . bb_date(TIMENOW, $bb_cfg['post_date_format']) . ' ' . $lang['SITEMAP_AVAILABLE'] . ': ' . make_url('sitemap/sitemap.xml') . ''; } else { $html .= $lang['SITEMAP_NOT_CREATED']; @@ -31,7 +31,7 @@ switch ($mode) { break; case 'search_update': - if (!file_exists(SITEMAP_DIR . '/sitemap.xml')) { + if (!is_file(SITEMAP_DIR . '/sitemap.xml')) { $map->createSitemap(); } diff --git a/library/ajax/view_torrent.php b/library/ajax/view_torrent.php index 53625a63c..f2050d715 100644 --- a/library/ajax/view_torrent.php +++ b/library/ajax/view_torrent.php @@ -23,8 +23,9 @@ if (!$torrent) { $this->ajax_die($lang['ERROR_BUILD']); } +$file_contents = null; $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)); } diff --git a/library/attach_mod/includes/functions_thumbs.php b/library/attach_mod/includes/functions_thumbs.php index d22a6fb31..457ebb277 100644 --- a/library/attach_mod/includes/functions_thumbs.php +++ b/library/attach_mod/includes/functions_thumbs.php @@ -24,13 +24,14 @@ function createThumbnail(string $source, string $newFile, string $mimeType): boo { global $attach_config; - // Get the file information - $source = realpath($source); - $min_filesize = (int)$attach_config['img_min_thumb_filesize']; - $img_filesize = file_exists($source) ? filesize($source) : false; + // Check for source image existence + if (!$source = realpath($source)) { + return false; + } // 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; } @@ -48,7 +49,7 @@ function createThumbnail(string $source, string $newFile, string $mimeType): boo } // Check the thumbnail existence after creating - if (!file_exists($newFile)) { + if (!is_file($newFile)) { return false; } diff --git a/library/config.php b/library/config.php index 19dc11afa..d86964f78 100644 --- a/library/config.php +++ b/library/config.php @@ -765,7 +765,7 @@ $bb_cfg['post_img_width_decr'] = 52; $bb_cfg['attach_img_width_decr'] = 130; // 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'] . '/'; } else { $bb_cfg['default_lang_dir'] = LANG_ROOT_DIR . '/en/'; diff --git a/library/includes/cron/cron_run.php b/library/includes/cron/cron_run.php index 333969ecc..b1dd95781 100644 --- a/library/includes/cron/cron_run.php +++ b/library/includes/cron/cron_run.php @@ -43,7 +43,7 @@ DB()->add_shutdown_query(" foreach ($cron_jobs as $job) { $job_script = CRON_JOB_DIR . basename($job['cron_script']); - if (file_exists($job_script)) { + if (is_file($job_script)) { $cron_start_time = utime(); $cron_runtime_log = ''; $cron_write_log = (CRON_LOG_ENABLED && (CRON_FORCE_LOG || $job['log_enabled'] >= 1)); diff --git a/library/includes/cron/jobs/sitemap.php b/library/includes/cron/jobs/sitemap.php index 5a91c2fd1..5a2c29508 100644 --- a/library/includes/cron/jobs/sitemap.php +++ b/library/includes/cron/jobs/sitemap.php @@ -14,7 +14,7 @@ if (!defined('BB_ROOT')) { $map = new TorrentPier\Sitemap(); $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')); foreach ($bb_cfg['sitemap_sending'] as $source_name => $source_link) { diff --git a/library/includes/cron/jobs/update_forums_atom.php b/library/includes/cron/jobs/update_forums_atom.php index bb7d72d92..13fe16a21 100644 --- a/library/includes/cron/jobs/update_forums_atom.php +++ b/library/includes/cron/jobs/update_forums_atom.php @@ -16,7 +16,7 @@ global $bb_cfg; $timecheck = TIMENOW - 600; $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) { \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) { - 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) { \TorrentPier\Legacy\Atom::update_forum_feed($forum_data['forum_id'], $forum_data); } diff --git a/library/includes/functions.php b/library/includes/functions.php index 6dbb0acba..5c26630d3 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -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) { $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) @@ -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']) { $user_avatar = '' . $user_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 = '' . $user_id . ''; } } diff --git a/library/includes/init_bb.php b/library/includes/init_bb.php index 005b65671..136e11c4e 100644 --- a/library/includes/init_bb.php +++ b/library/includes/init_bb.php @@ -400,7 +400,7 @@ $userdata =& $user->data; if ( empty($_POST) && !defined('IN_ADMIN') && !defined('IN_AJAX') && - !file_exists(CRON_RUNNING) && + !is_file(CRON_RUNNING) && (TorrentPier\Helpers\CronHelper::isEnabled() || defined('START_CRON')) ) { if (TIMENOW - $bb_cfg['cron_last_check'] > $bb_cfg['cron_check_interval']) { @@ -443,13 +443,13 @@ if ( /** * 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); if ($bb_cfg['board_disable']) { // admin lock send_no_cache_headers(); bb_die('BOARD_DISABLE'); - } elseif (file_exists(BB_DISABLED)) { + } elseif (is_file(BB_DISABLED)) { // trigger lock TorrentPier\Helpers\CronHelper::releaseDeadlock(); send_no_cache_headers(); diff --git a/src/Ajax.php b/src/Ajax.php index 7fcfc6511..f80406004 100644 --- a/src/Ajax.php +++ b/src/Ajax.php @@ -88,11 +88,11 @@ class Ajax } // 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 ($bb_cfg['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']); } } diff --git a/src/Emailer.php b/src/Emailer.php index 6fbd7ef78..4e669dee0 100644 --- a/src/Emailer.php +++ b/src/Emailer.php @@ -94,10 +94,10 @@ class Emailer if (empty($this->tpl_msg[$template_lang . $template_file])) { $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'; - if (!file_exists($tpl_file)) { + if (!is_file($tpl_file)) { bb_die('Could not find email template file: ' . $template_file); } } diff --git a/src/Helpers/CronHelper.php b/src/Helpers/CronHelper.php index c531cdb7b..3ee881be9 100644 --- a/src/Helpers/CronHelper.php +++ b/src/Helpers/CronHelper.php @@ -32,7 +32,7 @@ class CronHelper */ public static function releaseDeadlock(): void { - if (file_exists(CRON_RUNNING)) { + if (is_file(CRON_RUNNING)) { if (TIMENOW - filemtime(CRON_RUNNING) > 2400) { self::enableBoard(); self::releaseLockFile(); @@ -47,7 +47,7 @@ class CronHelper */ public static function releaseLockFile(): void { - if (file_exists(CRON_RUNNING)) { + if (is_file(CRON_RUNNING)) { rename(CRON_RUNNING, CRON_ALLOWED); } self::touchLockFile(CRON_ALLOWED); @@ -57,7 +57,6 @@ class CronHelper * Создание файла блокировки * * @param string $lock_file - * * @return void */ public static function touchLockFile(string $lock_file): void @@ -72,7 +71,7 @@ class CronHelper */ public static function enableBoard(): void { - if (file_exists(BB_DISABLED)) { + if (is_file(BB_DISABLED)) { rename(BB_DISABLED, BB_ENABLED); } } @@ -84,7 +83,7 @@ class CronHelper */ public static function disableBoard(): void { - if (file_exists(BB_ENABLED)) { + if (is_file(BB_ENABLED)) { rename(BB_ENABLED, BB_DISABLED); } } @@ -98,11 +97,11 @@ class CronHelper { $lock_obtained = false; - if (file_exists(CRON_ALLOWED)) { + if (is_file(CRON_ALLOWED)) { $lock_obtained = rename(CRON_ALLOWED, CRON_RUNNING); - } elseif (file_exists(CRON_RUNNING)) { + } elseif (is_file(CRON_RUNNING)) { self::releaseDeadlock(); - } elseif (!file_exists(CRON_ALLOWED) && !file_exists(CRON_RUNNING)) { + } elseif (!is_file(CRON_ALLOWED) && !is_file(CRON_RUNNING)) { file_write('', CRON_ALLOWED); $lock_obtained = rename(CRON_ALLOWED, CRON_RUNNING); } @@ -114,8 +113,9 @@ class CronHelper * Отслеживание запуска задач * * @param string $mode + * @return void */ - public static function trackRunning(string $mode) + public static function trackRunning(string $mode): void { if (!defined('START_MARK')) { 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); break; case 'end': - if (file_exists(START_MARK)) { + if (is_file(START_MARK)) { unlink(START_MARK); } break; diff --git a/src/Helpers/IPHelper.php b/src/Helpers/IPHelper.php index c39f346f5..47a6c3936 100644 --- a/src/Helpers/IPHelper.php +++ b/src/Helpers/IPHelper.php @@ -60,7 +60,6 @@ class IPHelper extends Ip * @param string $ip * @return string */ - public static function long2ip_extended(string $ip): string { return self::long2ip($ip, $ip > 0xFFFFFFFF); diff --git a/src/Helpers/IsHelper.php b/src/Helpers/IsHelper.php index abb8fe9eb..8368f13d4 100644 --- a/src/Helpers/IsHelper.php +++ b/src/Helpers/IsHelper.php @@ -30,38 +30,4 @@ class IsHelper } 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); - } } diff --git a/src/Helpers/StringHelper.php b/src/Helpers/StringHelper.php new file mode 100644 index 000000000..780e66b2d --- /dev/null +++ b/src/Helpers/StringHelper.php @@ -0,0 +1,51 @@ +use_cache = $bb_cfg['xs_use_cache']; // Check template exists - if (!file_exists($this->root) || !is_dir($this->root)) { + if (!is_dir($this->root)) { die("Theme ({$this->tpl}) directory not found"); } } diff --git a/src/Validate.php b/src/Validate.php index 515342d3d..95c742376 100644 --- a/src/Validate.php +++ b/src/Validate.php @@ -16,7 +16,7 @@ use Egulias\EmailValidator\Validation\RFCValidation; use Egulias\EmailValidator\Validation\MessageIDValidation; use Egulias\EmailValidator\Validation\Extra\SpoofCheckValidation; -use TorrentPier\Helpers\IsHelper; +use TorrentPier\Helpers\StringHelper; /** * Class Validate @@ -181,24 +181,24 @@ class Validate if ($bb_cfg['password_symbols']) { // Numbers if ($bb_cfg['password_symbols']['nums']) { - if (!IsHelper::isContainsNums($password)) { + if (!StringHelper::isContainsNums($password)) { return $lang['CHOOSE_PASS_ERR_NUM']; } } // Letters if ($bb_cfg['password_symbols']['letters']['lowercase']) { - if (!IsHelper::isContainsLetters($password)) { + if (!StringHelper::isContainsLetters($password)) { return $lang['CHOOSE_PASS_ERR_LETTER']; } } if ($bb_cfg['password_symbols']['letters']['uppercase']) { - if (!IsHelper::isContainsLetters($password, true)) { + if (!StringHelper::isContainsLetters($password, true)) { return $lang['CHOOSE_PASS_ERR_LETTER_UPPERCASE']; } } // Spec symbols if ($bb_cfg['password_symbols']['spec_symbols']) { - if (!IsHelper::isContainsSpecSymbols($password)) { + if (!StringHelper::isContainsSpecSymbols($password)) { return $lang['CHOOSE_PASS_ERR_SPEC_SYMBOL']; } }