Merge branch 'php8' into section

This commit is contained in:
xiaomlove
2022-10-25 19:16:56 +08:00
168 changed files with 3072 additions and 621 deletions
+77 -30
View File
@@ -2,6 +2,11 @@
namespace Nexus\Field;
use App\Models\SearchBox;
use App\Models\Tag;
use App\Models\TorrentCustomField;
use App\Models\TorrentCustomFieldValue;
use Elasticsearch\Endpoints\Search;
use Nexus\Database\NexusDB;
class Field
@@ -86,7 +91,7 @@ class Field
function buildFieldForm(array $row = [])
{
global $lang_fields, $lang_functions;
global $lang_fields, $lang_functions, $lang_catmanage;
$trName = tr($lang_fields['col_name'] . '<font color="red">*</font>', '<input type="text" name="name" value="' . ($row['name'] ?? '') . '" style="width: 300px" />&nbsp;&nbsp;' . $lang_fields['col_name_help'], 1, '', true);
$trLabel = tr($lang_fields['col_label'] . '<font color="red">*</font>', '<input type="text" name="label" value="' . ($row['label'] ?? '') . '" style="width: 300px" />', 1, '', true);
$trType = tr($lang_fields['col_type'] . '<font color="red">*</font>', $this->radio('type', $this->getTypeRadioOptions(), $row['type'] ?? null), 1, '', true);
@@ -94,6 +99,9 @@ class Field
$trHelp = tr($lang_fields['col_help'], '<textarea name="help" rows="4" cols="80">' . ($row['help'] ?? '') . '</textarea>', 1, '', true);
$trOptions = tr($lang_fields['col_options'], '<textarea name="options" rows="6" cols="80">' . ($row['options'] ?? '') . '</textarea><br/>' . $lang_fields['col_options_help'], 1, '', true);
$trIsSingleRow = tr($lang_fields['col_is_single_row'] . '<font color="red">*</font>', $this->radio('is_single_row', ['0' => $lang_functions['text_no'], '1' => $lang_functions['text_yes']], $row['is_single_row'] ?? null), 1, '', true);
$trPriority = tr(nexus_trans('label.priority') . '<font color="red">*</font>', '<input type="number" name="priority" value="' . ($row['priority'] ?? '0') . '" style="width: 300px" />', 1, '', true);
$trDisplay = tr($lang_fields['col_display'], '<textarea name="display" rows="4" cols="80">' . ($row['display'] ?? '') . '</textarea><br/>' . $lang_catmanage['row_custom_field_display_help'], 1, '', true);
$id = $row['id'] ?? 0;
$form = <<<HTML
<div>
@@ -109,6 +117,8 @@ class Field
{$trHelp}
{$trOptions}
{$trIsSingleRow}
{$trPriority}
{$trDisplay}
</table>
</div>
<div style="text-align: center; margin-top: 10px;">
@@ -126,7 +136,7 @@ HTML;
$perPage = 10;
$total = get_row_count('torrents_custom_fields');
list($paginationTop, $paginationBottom, $limit) = pager($perPage, $total, "?");
$sql = "select * from torrents_custom_fields order by id asc $limit";
$sql = "select * from torrents_custom_fields order by priority desc $limit";
$res = sql_query($sql);
$header = [
'id' => $lang_fields['col_id'],
@@ -135,6 +145,7 @@ HTML;
'type_text' => $lang_fields['col_type'],
'required_text' => $lang_fields['col_required'],
'is_single_row_text' => $lang_fields['col_is_single_row'],
'priority' => nexus_trans('label.priority'),
'action' => $lang_fields['col_action'],
];
$rows = [];
@@ -203,6 +214,8 @@ HEAD;
$attributes['help'] = $data['help'] ?? '';
$attributes['options'] = trim($data['options'] ?? '');
$attributes['display'] = trim($data['display'] ?? '');
$attributes['priority'] = trim($data['priority'] ?? '0');
$now = date('Y-m-d H:i:s');
$attributes['updated_at'] = $now;
$table = 'torrents_custom_fields';
@@ -252,24 +265,29 @@ HEAD;
}
public function renderOnUploadPage($torrentId = 0)
public function renderOnUploadPage($torrentId = 0, $searchBoxId)
{
global $browsecatmode;
$searchBox = NexusDB::getOne('searchbox', "id = $browsecatmode");
$searchBox = NexusDB::getOne('searchbox', "id = $searchBoxId");
if (empty($searchBox)) {
throw new \RuntimeException("Invalid search box: $browsecatmode");
throw new \RuntimeException("Invalid search box: $searchBoxId");
}
$customValues = $this->listTorrentCustomField($torrentId);
$sql = sprintf('select * from torrents_custom_fields where id in (%s)', $searchBox['custom_fields'] ?: 0);
$customValues = $this->listTorrentCustomField($torrentId, $searchBoxId);
$sql = sprintf('select * from torrents_custom_fields where id in (%s) order by priority desc', $searchBox['custom_fields'] ?: 0);
$res = sql_query($sql);
$html = '';
while ($row = mysql_fetch_assoc($res)) {
$name = "custom_fields[{$row['id']}]";
$name = "custom_fields[$searchBoxId][{$row['id']}]";
$currentValue = $customValues[$row['id']]['custom_field_value'] ?? '';
$requireText = '';
if ($row['required']) {
$requireText = "<font color=\"red\">*</font>";
}
$trLabel = $row['label'] . $requireText;
$trRelation = "mode_$searchBoxId";
if ($row['type'] == self::TYPE_TEXT) {
$html .= tr($row['label'], sprintf('<input type="text" name="%s" value="%s" style="width: %s"/>', $name, $currentValue, '99%'), 1);
$html .= tr($trLabel, sprintf('<input type="text" name="%s" value="%s" style="width: %s"/>', $name, $currentValue, '99%'), 1, $trRelation);
} elseif ($row['type'] == self::TYPE_TEXTAREA) {
$html .= tr($row['label'], sprintf('<textarea name="%s" rows="4" style="width: %s">%s</textarea>', $name, '99%', $currentValue), 1);
$html .= tr($trLabel, sprintf('<textarea name="%s" rows="4" style="width: %s">%s</textarea>', $name, '99%', $currentValue), 1, $trRelation);
} elseif ($row['type'] == self::TYPE_RADIO || $row['type'] == self::TYPE_CHECKBOX) {
if ($row['type'] == self::TYPE_CHECKBOX) {
$name .= '[]';
@@ -293,7 +311,7 @@ HEAD;
$row['type'], $name, $value, $checked, $label
);
}
$html .= tr($row['label'], $part, 1);
$html .= tr($trLabel, $part, 1, $trRelation);
} elseif ($row['type'] == self::TYPE_SELECT) {
$part = '<select name="' . $name . '">';
foreach (preg_split('/[\r\n]+/', trim($row['options'])) as $option) {
@@ -312,7 +330,7 @@ HEAD;
);
}
$part .= '</select>';
$html .= tr($row['label'], $part, 1);
$html .= tr($trLabel, $part, 1, $trRelation);
} elseif ($row['type'] == self::TYPE_IMAGE) {
$callbackFunc = "preview_custom_field_image_" . $row['id'];
$iframeId = "iframe_$callbackFunc";
@@ -351,18 +369,14 @@ HEAD;
}
</script>
JS;
$html .= tr($row['label'], $y, 1);
$html .= tr($trLabel, $y, 1, $trRelation, true);
}
}
return $html;
}
public function listTorrentCustomField($torrentId, $searchBoxId = 0)
public function listTorrentCustomField($torrentId, $searchBoxId)
{
global $browsecatmode;
if ($searchBoxId <= 0) {
$searchBoxId = $browsecatmode;
}
//suppose torrentId is array
$isArray = true;
$torrentIdArr = $torrentId;
@@ -371,7 +385,7 @@ JS;
$torrentIdArr = [$torrentId];
}
$torrentIdStr = implode(',', $torrentIdArr);
$res = sql_query("select f.*, v.custom_field_value, v.torrent_id from torrents_custom_field_values v inner join torrents_custom_fields f on v.custom_field_id = f.id inner join searchbox box on box.id = $searchBoxId and find_in_set(f.id, box.custom_fields) where torrent_id in ($torrentIdStr)");
$res = sql_query("select f.*, v.custom_field_value, v.torrent_id from torrents_custom_field_values v inner join torrents_custom_fields f on v.custom_field_id = f.id inner join searchbox box on box.id = $searchBoxId and find_in_set(f.id, box.custom_fields) where torrent_id in ($torrentIdStr) order by f.priority desc");
$values = [];
$result = [];
while ($row = mysql_fetch_assoc($res)) {
@@ -402,12 +416,11 @@ JS;
return $isArray ? $result : ($result[$torrentId] ?? []);
}
public function renderOnTorrentDetailsPage($torrentId)
public function renderOnTorrentDetailsPage($torrentId, $searchBoxId)
{
global $browsecatmode;
$displayName = get_searchbox_value($browsecatmode, 'custom_fields_display_name');
$customFields = $this->listTorrentCustomField($torrentId);
$mixedRowContent = get_searchbox_value($browsecatmode, 'custom_fields_display');
$displayName = get_searchbox_value($searchBoxId, 'custom_fields_display_name');
$customFields = $this->listTorrentCustomField($torrentId, $searchBoxId);
$mixedRowContent = get_searchbox_value($searchBoxId, 'custom_fields_display');
$rowByRowHtml = '';
$shouldRenderMixRow = false;
foreach ($customFields as $field) {
@@ -422,12 +435,20 @@ JS;
$mixedRowContent = str_replace("<%{$field['name']}.label%>", $field['label'], $mixedRowContent);
$mixedRowContent = str_replace("<%{$field['name']}.value%>", $contentNotFormatted, $mixedRowContent);
if ($field['is_single_row']) {
$contentFormatted = $this->formatCustomFieldValue($field, true);
$rowByRowHtml .= tr($field['label'], $contentFormatted, 1);
if (!empty($field['display'])) {
$customFieldDisplay = $field['display'];
$customFieldDisplay = str_replace("<%{$field['name']}.label%>", $field['label'], $customFieldDisplay);
$customFieldDisplay = str_replace("<%{$field['name']}.value%>", $contentNotFormatted, $customFieldDisplay);
$rowByRowHtml .= tr($field['label'], format_comment($customFieldDisplay, false), 1);
} else {
$contentFormatted = $this->formatCustomFieldValue($field, true);
$rowByRowHtml .= tr($field['label'], $contentFormatted, 1);
}
}
}
$result = $rowByRowHtml;
if ($shouldRenderMixRow) {
if ($shouldRenderMixRow && $mixedRowContent) {
$result .= tr($displayName, format_comment($mixedRowContent), 1);
}
return $result;
@@ -442,13 +463,13 @@ JS;
switch ($customFieldWithValue['type']) {
case self::TYPE_TEXT:
case self::TYPE_TEXTAREA:
$result .= $doFormatComment ? format_comment($fieldValue) : $fieldValue;
$result .= $doFormatComment ? format_comment($fieldValue, false) : $fieldValue;
break;
case self::TYPE_IMAGE:
if (substr($fieldValue, 0, 4) == 'http') {
$result .= $doFormatComment ? formatImg($fieldValue, true, 700, 0, "attach{$customFieldWithValue['id']}") : $fieldValue;
} else {
$result .= $doFormatComment ? format_comment($fieldValue) : $fieldValue;
$result .= $doFormatComment ? format_comment($fieldValue, false) : $fieldValue;
}
break;
case self::TYPE_RADIO:
@@ -491,6 +512,32 @@ JS;
}
public function saveFieldValues($searchBoxId, $torrentId, array $data)
{
$searchBox = SearchBox::query()->findOrFail($searchBoxId);
$enabledFields = TorrentCustomField::query()->find($searchBox->custom_fields);
$insert = [];
$now = now();
foreach ($enabledFields as $field) {
if (empty($data[$field->id])) {
if ($field->required) {
// throw new \InvalidArgumentException(nexus_trans("nexus.require_argument", ['argument' => $field->label]));
do_log("Field: {$field->label} required, but empty");
}
continue;
}
$insert[] = [
'torrent_id' => $torrentId,
'custom_field_id' => $field->id,
'custom_field_value' => $data[$field->id],
'created_at' => $now,
'updated_at' => $now,
];
}
TorrentCustomFieldValue::query()->where('torrent_id', $torrentId)->delete();
TorrentCustomFieldValue::query()->insert($insert);
}
}
+2 -1
View File
@@ -34,7 +34,8 @@ class Imdb
public static function listSupportLanguages(): array
{
$data = require_once sprintf('%s/resources/lang/%s/imdb.php', ROOT_PATH, get_langfolder_cookie(true));
$file = sprintf('%s/resources/lang/%s/imdb.php', ROOT_PATH, get_langfolder_cookie(true));
$data = include $file;
return $data['languages'];
}
+3 -1
View File
@@ -15,6 +15,7 @@ use App\Models\Tag;
use App\Models\Torrent;
use App\Models\TorrentTag;
use App\Models\User;
use App\Models\UserBanLog;
use App\Repositories\AttendanceRepository;
use App\Repositories\BonusRepository;
use App\Repositories\ExamRepository;
@@ -391,6 +392,8 @@ class Update extends Install
$command .= " --exclude=$exclude";
}
$this->executeCommand($command);
//remove original file
unlink($filename);
break;
}
}
@@ -444,5 +447,4 @@ class Update extends Install
}
}
+11
View File
@@ -92,6 +92,7 @@ return array (
'show_top_uploader' => 'no',
'imdb_language' => 'en-US',
'offer_skip_approved_count' => 5,
'upload_deny_approval_deny_count' => 2,
),
'smtp' =>
array (
@@ -179,6 +180,8 @@ return array (
'torrent-delete' => User::CLASS_ADMINISTRATOR,
'user-delete' => User::CLASS_ADMINISTRATOR,
'user-change-class' => User::CLASS_ADMINISTRATOR,
'torrent-set-special-tag' => User::CLASS_ADMINISTRATOR,
'torrent-approval-allow-automatic' => User::CLASS_UPLOADER,
),
'tweak' =>
array (
@@ -233,6 +236,11 @@ return array (
'cancel_hr' => BonusLogs::DEFAULT_BONUS_CANCEL_ONE_HIT_AND_RUN,
'attendance_card' => BonusLogs::DEFAULT_BONUS_BUY_ATTENDANCE_CARD,
'harem_addition' => 0,
'hundredgbupload' => 10000,
'tengbdownload' => 1000,
'hundredgbdownload' => 8000,
'official_addition' => '0.5',
'zero_bonus_factor' => '0.2',
),
'account' =>
array (
@@ -296,6 +304,7 @@ return array (
8 => '5',
9 => '10',
),
'destroy_disabled' => 0,
),
'torrent' =>
array (
@@ -341,6 +350,7 @@ return array (
'claim_reach_standard_uploaded' => \App\Models\Claim::STANDARD_UPLOADED_TIMES,
'approval_status_icon_enabled' => 'no',
'approval_status_none_visible' => 'yes',
'nfo_view_style_default' => \App\Models\Torrent::NFO_VIEW_STYLE_DOS,
),
'attachment' =>
array (
@@ -418,6 +428,7 @@ return array (
'no_promotion' => 'yes',
'max_uploaded' => 3,
'not_seed_box_max_speed' => 10240,
'max_uploaded_duration' => 0,
],
'system' => [
'change_username_min_interval_in_days' => '365',
+11 -4
View File
@@ -163,21 +163,27 @@ class TechnicalInformation
$subtitles = $this->getSubtitles();
// dd($videos, $audios, $subtitles);
if (empty($videos) && empty($audios) && empty($subtitles)) {
// return '';
return sprintf('<div style="padding: 0 0.5rem"><pre>%s</pre></div>', $this->mediaInfo);
return sprintf('<div class="nexus-media-info-raw"><pre>%s</pre></div>', $this->mediaInfo);
}
$result = '<table style="border: none;width: 100%"><tbody><tr>';
$cols = 0;
if (!empty($videos)) {
$cols++;
$result .= $this->buildTdTable($videos);
}
if (!empty($audios)) {
$cols++;
$result .= $this->buildTdTable($audios);
}
if (!empty($subtitles)) {
$cols++;
$result .= $this->buildTdTable($subtitles);
}
$result .= '</tr></tbody></table>';
$result .= '</tr>';
$rawMediaInfo = sprintf('[spoiler=%s][raw]<pre>%s</pre>[/raw][/spoiler]', nexus_trans('torrent.show_hide_media_info'), $this->mediaInfo);
$result .= sprintf('<tr><td colspan="%s" class="nexus-media-info-raw">%s</td></tr>', $cols, format_comment($rawMediaInfo, false));
$result .= '</tbody></table>';
return $result;
}
@@ -189,7 +195,8 @@ class TechnicalInformation
$table .= sprintf('<td style="border: none; padding-right: 5px;padding-bottom: 5px;"><b>%s: </b>%s</td>', $key, $value);
$table .= '</tr>';
}
$table .= '</tbody></table>';
$table .= '</tbody>';
$table .= '</table>';
return sprintf('<td style="border: none; padding-right: 5px;padding-bottom: 5px">%s</td>', $table);
}