Minor improvements (#1253)

* Minor improvements

* Update .gitignore

* Update admin_smilies.php

* Update CHANGELOG.md
This commit is contained in:
Roman Kelesidis 2023-12-23 14:20:06 +07:00 committed by GitHub
commit 94cb6ab73c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 50 deletions

1
.gitignore vendored
View file

@ -24,6 +24,7 @@ vendor
*.zip
*.7z
*.torrent
*.pak
### Windows ###
Thumbs.db

View file

@ -19,7 +19,7 @@
- search.php parameter sanitizing [\#1213](https://github.com/torrentpier/torrentpier/pull/1213) ([kovalensky](https://github.com/kovalensky), [belomaxorka](https://github.com/belomaxorka))
- Limit execution time for forum file-listing [\#1211](https://github.com/torrentpier/torrentpier/pull/1211) ([kovalensky](https://github.com/kovalensky), [belomaxorka](https://github.com/belomaxorka))
- Some reported bugfixes [\#1214](https://github.com/torrentpier/torrentpier/pull/1214) ([belomaxorka](https://github.com/belomaxorka))
- Minor improvements [\#1215](https://github.com/torrentpier/torrentpier/pull/1215), [\#1217](https://github.com/torrentpier/torrentpier/pull/1217), [\#1219](https://github.com/torrentpier/torrentpier/pull/1219), [\#1220](https://github.com/torrentpier/torrentpier/pull/1220), [\#1224](https://github.com/torrentpier/torrentpier/pull/1224), [\#1228](https://github.com/torrentpier/torrentpier/pull/1228), [\#1229](https://github.com/torrentpier/torrentpier/pull/1229), [\#1230](https://github.com/torrentpier/torrentpier/pull/1230), [\#1234](https://github.com/torrentpier/torrentpier/pull/1234), [\#1236](https://github.com/torrentpier/torrentpier/pull/1236), [\#1243](https://github.com/torrentpier/torrentpier/pull/1243), [\#1248](https://github.com/torrentpier/torrentpier/pull/1248) ([belomaxorka](https://github.com/belomaxorka))
- Minor improvements [\#1215](https://github.com/torrentpier/torrentpier/pull/1215), [\#1217](https://github.com/torrentpier/torrentpier/pull/1217), [\#1219](https://github.com/torrentpier/torrentpier/pull/1219), [\#1220](https://github.com/torrentpier/torrentpier/pull/1220), [\#1224](https://github.com/torrentpier/torrentpier/pull/1224), [\#1228](https://github.com/torrentpier/torrentpier/pull/1228), [\#1229](https://github.com/torrentpier/torrentpier/pull/1229), [\#1230](https://github.com/torrentpier/torrentpier/pull/1230), [\#1234](https://github.com/torrentpier/torrentpier/pull/1234), [\#1236](https://github.com/torrentpier/torrentpier/pull/1236), [\#1243](https://github.com/torrentpier/torrentpier/pull/1243), [\#1248](https://github.com/torrentpier/torrentpier/pull/1248), [\#1253](https://github.com/torrentpier/torrentpier/pull/1253) ([belomaxorka](https://github.com/belomaxorka))
- Fixed extensions issue [\#1218](https://github.com/torrentpier/torrentpier/pull/1218) ([belomaxorka](https://github.com/belomaxorka))
- Fixed broken sorting in group.php [\#1221](https://github.com/torrentpier/torrentpier/pull/1221) ([belomaxorka](https://github.com/belomaxorka))
- Code re-formatting [\#1225](https://github.com/torrentpier/torrentpier/pull/1225) ([kovalensky](https://github.com/kovalensky))

View file

@ -22,27 +22,25 @@ if (isset($_POST['mode']) || isset($_GET['mode'])) {
$mode = '';
}
$pathToSmilesDir = BB_ROOT . $bb_cfg['smilies_path'];
$delimeter = '=+:';
$s_hidden_fields = '';
$smiley_paks = [];
$smiley_paks = $smiley_images = [];
// Read a listing of uploaded smilies for use in the add or edit smliey code
$dir = opendir(BB_ROOT . $bb_cfg['smilies_path']);
// Read a listing of uploaded smiles
$smilesDirectory = new DirectoryIterator($pathToSmilesDir);
while ($file = @readdir($dir)) {
if (!is_dir(realpath(BB_ROOT . $bb_cfg['smilies_path'] . '/' . $file))) {
$img_size = getimagesize(BB_ROOT . $bb_cfg['smilies_path'] . '/' . $file);
if ($img_size[0] && $img_size[1]) {
$smiley_images[] = $file;
} elseif (preg_match('/.pak$/i', $file)) {
$smiley_paks[] = $file;
foreach ($smilesDirectory as $files) {
if ($files->isFile()) {
$extension = strtolower(pathinfo($files->getFilename(), PATHINFO_EXTENSION));
if (in_array($extension, ['png', 'gif'], true) && getimagesize($pathToSmilesDir . '/' . $files->getFilename())) {
$smiley_images[] = $files->getFilename();
} else if ($extension === 'pak') {
$smiley_paks[] = $files->getFilename();
}
}
}
closedir($dir);
// Select main mode
if (isset($_GET['import_pack']) || isset($_POST['import_pack'])) {
$smile_pak = (string)request_var('smile_pak', '');
@ -71,7 +69,7 @@ if (isset($_GET['import_pack']) || isset($_POST['import_pack'])) {
}
}
$fcontents = file(BB_ROOT . $bb_cfg['smilies_path'] . '/' . $smile_pak);
$fcontents = file($pathToSmilesDir . '/' . $smile_pak);
if (empty($fcontents)) {
bb_die('Could not read smiley pak file');
@ -167,11 +165,11 @@ if (isset($_GET['import_pack']) || isset($_POST['import_pack'])) {
$template->assign_vars([
'TPL_SMILE_EDIT' => true,
'SMILEY_IMG' => BB_ROOT . $bb_cfg['smilies_path'] . '/' . $smiley_images[0],
'SMILEY_IMG' => $pathToSmilesDir . '/' . $smiley_images[0],
'S_SMILEY_ACTION' => 'admin_smilies.php',
'S_HIDDEN_FIELDS' => $s_hidden_fields,
'S_FILENAME_OPTIONS' => $filename_list,
'S_SMILEY_BASEDIR' => BB_ROOT . $bb_cfg['smilies_path']
'S_SMILEY_BASEDIR' => $pathToSmilesDir
]);
} elseif ($mode != '') {
switch ($mode) {
@ -217,11 +215,11 @@ if (isset($_GET['import_pack']) || isset($_POST['import_pack'])) {
'TPL_SMILE_EDIT' => true,
'SMILEY_CODE' => $smile_data['code'],
'SMILEY_EMOTICON' => $smile_data['emoticon'],
'SMILEY_IMG' => BB_ROOT . $bb_cfg['smilies_path'] . '/' . $smiley_edit_img,
'SMILEY_IMG' => $pathToSmilesDir . '/' . $smiley_edit_img,
'S_SMILEY_ACTION' => 'admin_smilies.php',
'S_HIDDEN_FIELDS' => $s_hidden_fields,
'S_FILENAME_OPTIONS' => $filename_list,
'S_SMILEY_BASEDIR' => BB_ROOT . $bb_cfg['smilies_path']
'S_SMILEY_BASEDIR' => $pathToSmilesDir
]);
break;
@ -308,7 +306,7 @@ if (isset($_GET['import_pack']) || isset($_POST['import_pack'])) {
$template->assign_block_vars('smiles', [
'ROW_CLASS' => $row_class,
'SMILEY_IMG' => BB_ROOT . $bb_cfg['smilies_path'] . '/' . $smilies[$i]['smile_url'],
'SMILEY_IMG' => $pathToSmilesDir . '/' . $smilies[$i]['smile_url'],
'CODE' => $smilies[$i]['code'],
'EMOT' => $smilies[$i]['emoticon'],

View file

@ -275,18 +275,18 @@ function display_attachments($post_id)
}
if ($thumbnail) {
// Get the thumbnail image
$thumbnail_filename = $upload_dir . '/' . THUMB_DIR . '/t_' . basename($attachments['_' . $post_id][$i]['physical_filename']);
// Checks the thumbnail existence
if (!is_file($thumbnail_filename)) {
continue;
}
// Images, but display Thumbnail
if ($attach_config['upload_dir'][0] == '/' || ($attach_config['upload_dir'][0] != '/' && $attach_config['upload_dir'][1] == ':')) {
$thumb_source = BB_ROOT . DL_URL . $attachments['_' . $post_id][$i]['attach_id'] . '&thumb=1';
} else {
// Get the thumbnail image
$thumbnail_filename = $upload_dir . '/' . THUMB_DIR . '/t_' . basename($attachments['_' . $post_id][$i]['physical_filename']);
// Checks the thumbnail existence
if (!is_file($thumbnail_filename)) {
continue;
}
$thumb_source = $thumbnail_filename;
}

View file

@ -898,21 +898,13 @@ class Attach
// 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')) {
if (ini_get('open_basedir')) {
$upload_mode = 'move';
} else {
$upload_mode = 'copy';
}
// Ok, upload the Attachment
if (!$error) {
$this->move_uploaded_attachment($upload_mode, $file);
}
$this->move_uploaded_attachment($upload_mode, $file);
}
// Now, check filesize parameters

View file

@ -74,13 +74,6 @@ class Upload
*/
public array $errors = [];
/**
* Upload status code
*
* @var int
*/
public int $error = UPLOAD_ERR_OK;
/**
* Image types array
*
@ -109,7 +102,6 @@ class Upload
$this->cfg = array_merge($this->cfg, $cfg);
$this->file = $post_params;
$this->error = $this->file['error'];
// Check upload allowed
if (!$this->cfg['up_allowed']) {
@ -118,9 +110,9 @@ class Upload
}
// Handling errors while uploading
if (isset($this->error) && ($this->error !== UPLOAD_ERR_OK)) {
if (isset($lang['UPLOAD_ERRORS'][$this->error])) {
$this->errors[] = $lang['UPLOAD_ERROR_COMMON'] . '<br><br>' . $lang['UPLOAD_ERRORS'][$this->error];
if (isset($this->file['error']) && ($this->file['error'] !== UPLOAD_ERR_OK)) {
if (isset($lang['UPLOAD_ERRORS'][$this->file['error']])) {
$this->errors[] = $lang['UPLOAD_ERROR_COMMON'] . '<br><br>' . $lang['UPLOAD_ERRORS'][$this->file['error']];
} else {
$this->errors[] = $lang['UPLOAD_ERROR_COMMON'];
}
@ -158,7 +150,7 @@ class Upload
// Actions for images [E.g. Change avatar]
if ($this->cfg['max_width'] || $this->cfg['max_height']) {
if ($img_info = getimagesize($this->file['tmp_name'])) {
[$width, $height, $type, $attr] = $img_info;
[$width, $height, $type] = $img_info;
// redefine ext
if (!$width || !$height || !$type || !isset($this->img_types[$type])) {