mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-20 13:24:01 -07:00
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:
parent
e8a90b025c
commit
3626143879
24 changed files with 107 additions and 89 deletions
|
@ -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');
|
||||
|
|
|
@ -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>';
|
||||
$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'],
|
||||
|
|
|
@ -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
|
||||
|
|
10
common.php
10
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 <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';
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
4
feed.php
4
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)) {
|
||||
|
|
|
@ -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'] . ': ' . '<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
|
||||
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);
|
||||
|
|
2
info.php
2
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'),
|
||||
|
|
|
@ -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'] . ': <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 {
|
||||
$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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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/';
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 = '<img src="' . make_url($bb_cfg['avatars']['display_path'] . $bb_cfg['avatars']['bot_avatar']) . '" alt="' . $user_id . '" ' . $height . ' ' . $width . ' />';
|
||||
} 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 . ' />';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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']);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
51
src/Helpers/StringHelper.php
Normal file
51
src/Helpers/StringHelper.php
Normal 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);
|
||||
}
|
||||
}
|
|
@ -111,7 +111,7 @@ class Template
|
|||
$this->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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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'];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue