diff --git a/include/functions.php b/include/functions.php
index 1e535c3c..085a33d0 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -1253,11 +1253,14 @@ function allowedemails()
function redirect($url)
{
+ if (substr($url, 0, 4) != 'http') {
+ $url = getSchemeAndHttpHost() . '/' . trim($url, '/');
+ }
if(!headers_sent()){
- header("Location : $url");
- }
- else
- echo "";
+ header("Location: $url", true, 302);
+ } else {
+ echo "";
+ }
exit;
}
diff --git a/lang/chs/lang_fields.php b/lang/chs/lang_fields.php
new file mode 100644
index 00000000..6bf717fb
--- /dev/null
+++ b/lang/chs/lang_fields.php
@@ -0,0 +1,21 @@
+ '字段管理',
+ 'text_manage' => '管理',
+ 'text_add' => '添加',
+ 'text_field' => '字段',
+ 'text_delete' => '删除',
+ 'text_edit' => '编辑',
+ 'col_id' => 'ID',
+ 'col_name' => 'Name',
+ 'col_label' => '显示标签',
+ 'col_type' => '类型',
+ 'col_required' => '不能为空',
+ 'col_help' => '辅助说明',
+ 'col_options' => '选项',
+ 'col_action' => '操作',
+ 'js_sure_to_delete_this' => '你确信要删除此项目吗?',
+ 'submit_submit' => '提交'
+
+];
\ No newline at end of file
diff --git a/nexus/Database/DB.php b/nexus/Database/DB.php
index 3d59e62a..8060185d 100644
--- a/nexus/Database/DB.php
+++ b/nexus/Database/DB.php
@@ -150,4 +150,18 @@ class DB
return mysql_insert_id();
}
+ public static function update($table, $data, $whereStr)
+ {
+ if (empty($table) || empty($data) || !is_array($data) || empty($whereStr)) {
+ throw new DatabaseException("require table and data(array) and whereStr.");
+ }
+ $updateArr = [];
+ foreach ($data as $field => $value) {
+ $updateArr[] = "`$field` = " . sqlesc($value);
+ }
+ $sql = sprintf("update `%s` set %s where %s", $table, implode(', ', $updateArr), $whereStr);
+ sql_query($sql);
+ return mysql_affected_rows();
+ }
+
}
\ No newline at end of file
diff --git a/nexus/Field/Field.php b/nexus/Field/Field.php
new file mode 100644
index 00000000..2d70310f
--- /dev/null
+++ b/nexus/Field/Field.php
@@ -0,0 +1,160 @@
+ '短文本',
+ self::TYPE_TEXTAREA => '长文本',
+ self::TYPE_RADIO => '横向单选',
+ self::TYPE_CHECKBOX => '横向多选',
+ self::TYPE_SELECT => '下拉单选',
+ self::TYPE_FILE => '文件',
+ ];
+
+ public function radio($name, $options, $current = null)
+ {
+ $arr = [];
+ foreach ($options as $value => $label) {
+ $arr[] = sprintf(
+ '',
+ $name, $value, (string)$current === (string)$value ? ' checked' : '', $label
+ );
+ }
+ return implode('', $arr);
+ }
+
+ function buildFieldForm(array $row = [])
+ {
+ global $lang_fields;
+ $trName = tr($lang_fields['col_name'] . '*', ' 仅允许数字、字母、下划线', 1, '', true);
+ $trLabel = tr($lang_fields['col_label'] . '*', '', 1, '', true);
+ $trType = tr($lang_fields['col_type'] . '*', $this->radio('type', self::$types, $row['type'] ?? null), 1, '', true);
+ $trRequired = tr($lang_fields['col_required'] . '*', $this->radio('required', ['0' => '否', '1' => '是'], $row['required'] ?? null), 1, '', true);
+ $trHelp = tr($lang_fields['col_help'], '', 1, '', true);
+ $trOptions = tr($lang_fields['col_options'], '
类型为单选、多选、下拉时必填,一行一个,格式:选项值|选项描述文本', 1, '', true);
+ $id = $row['id'] ?? 0;
+ $form = <<
+
+
+
+HTML;
+ return $form;
+ }
+
+ function buildFieldTable()
+ {
+ global $lang_fields;
+ $sql = 'select * from torrents_custom_fields';
+ $res = sql_query($sql);
+ $header = [
+ 'id' => $lang_fields['col_id'],
+ 'name' => $lang_fields['col_name'],
+ 'label' => $lang_fields['col_label'],
+ 'type' => $lang_fields['col_type'],
+ 'required_text' => $lang_fields['col_required'],
+ 'action' => $lang_fields['col_action'],
+ ];
+ $rows = [];
+ while ($row = mysql_fetch_assoc($res)) {
+ $row['required_text'] = $row['required'] ? '是' : '否';
+ $row['action'] = sprintf(
+ "%s | %s",
+ $row['id'], $lang_fields['js_sure_to_delete_this'], $lang_fields['text_delete'], $row['id'], $lang_fields['text_edit']
+ );
+ $rows[] = $row;
+ }
+ $table = $this->buildTable($header, $rows);
+ return $table;
+ }
+
+ public function save($data)
+ {
+ $attributes = [];
+ if (empty($data['name'])) {
+ throw new \InvalidArgumentException("Name 必须");
+ }
+ if (!preg_match('/^\w+$/', $data['name'])) {
+ throw new \InvalidArgumentException("Name 非法");
+ }
+ $attributes['name'] = $data['name'];
+
+ if (empty($data['label'])) {
+ throw new \InvalidArgumentException("显示标签 必须");
+ }
+ $attributes['label'] = $data['label'];
+
+ if (empty($data['type'])) {
+ throw new \InvalidArgumentException("类型 必须");
+ }
+ if (!isset(self::$types[$data['type']])) {
+ throw new \InvalidArgumentException("类型 非法");
+ }
+ $attributes['type'] = $data['type'];
+
+ if (!isset($data['required'])) {
+ throw new \InvalidArgumentException("不能为空 必须");
+ }
+ if (!in_array($data['required'], ["0", "1"], true)) {
+ throw new \InvalidArgumentException("不能为空 非法");
+ }
+ $attributes['required'] = $data['required'];
+
+ $attributes['help'] = $data['help'] ?? '';
+ $attributes['options'] = trim($data['options'] ?? '');
+ $now = date('Y-m-d H:i:s');
+ $attributes['updated_at'] = $now;
+ $table = 'torrents_custom_fields';
+ if (!empty($data['id'])) {
+ $result = DB::update($table, $attributes, "id = " . sqlesc($data['id']));
+ } else {
+ $attributes['created_at'] = $now;
+ $result = DB::insert($table, $attributes);
+ }
+ return $result;
+ }
+
+ public function buildTable(array $header, array $rows)
+ {
+ $table = '';
+ foreach ($header as $key => $value) {
+ $table .= sprintf('| %s | ', $value);
+ }
+ $table .= '
';
+ foreach ($rows as $row) {
+ $table .= '';
+ foreach ($header as $headerKey => $headerValue) {
+ $table .= sprintf('| %s | ', $row[$headerKey] ?? '');
+ }
+ $table .= '
';
+ }
+ $table .= '';
+ return $table;
+ }
+}
\ No newline at end of file
diff --git a/public/fields.php b/public/fields.php
new file mode 100644
index 00000000..8c2a74bc
--- /dev/null
+++ b/public/fields.php
@@ -0,0 +1,69 @@
+{$lang_fields['field_management']} -
+
+HEAD;
+ return $head;
+}
+
+
+
+$action = $_GET['action'] ?? 'view';
+if ($action == 'view') {
+ stdhead($lang_fields['field_management']." - ".$lang_fields['text_field']);
+ begin_main_frame();
+ echo buildTableHead();
+ echo $field->buildFieldTable();
+} elseif ($action == 'add') {
+ stdhead($lang_fields['field_management']." - ".$lang_fields['text_add']);
+ begin_main_frame();
+ echo $field->buildFieldForm();
+} elseif ($action == 'submit') {
+ try {
+ $result = $field->save($_REQUEST);
+ redirect('fields.php?action=view&type=');
+ } catch (\Exception $e) {
+ stderr($lang_fields['field_management']." - ".$lang_fields['text_field'], $e->getMessage());
+ }
+} elseif ($action == 'edit') {
+ $id = intval($_GET['id'] ?? 0);
+ if ($id == 0) {
+ stderr($lang_fields['field_management'], "invalid id");
+ }
+ $sql = "select * from torrents_custom_fields where id = $id";
+ $res = sql_query($sql);
+ $row = mysql_fetch_assoc($res);
+ if (empty($row)) {
+ stderr('', 'invlaid id');
+ }
+ stdhead($lang_fields['field_management']." - ".$lang_fields['text_edit']);
+ begin_main_frame();
+ echo $field->buildFieldForm($row);
+}
+
+
+
diff --git a/public/pic/chrome-logo.svg b/public/pic/chrome-logo.svg
new file mode 100644
index 00000000..5a3fc4bb
--- /dev/null
+++ b/public/pic/chrome-logo.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/public/pic/firefox.png b/public/pic/firefox.png
new file mode 100644
index 00000000..1e812a90
Binary files /dev/null and b/public/pic/firefox.png differ
diff --git a/public/takeupload.php b/public/takeupload.php
index 7208778e..e04d7af3 100644
--- a/public/takeupload.php
+++ b/public/takeupload.php
@@ -343,7 +343,7 @@ if (empty($url) && !empty($ptGenImdbLink)) {
}
$ret = sql_query("INSERT INTO torrents (filename, owner, visible, anonymous, name, size, numfiles, type, url, small_descr, descr, ori_descr, category, source, medium, codec, audiocodec, standard, processing, team, save_as, sp_state, added, last_action, nfo, info_hash, pt_gen, tags) VALUES (".sqlesc($fname).", ".sqlesc($CURUSER["id"]).", 'yes', ".sqlesc($anonymous).", ".sqlesc($torrent).", ".sqlesc($totallen).", ".count($filelist).", ".sqlesc($type).", ".sqlesc($url).", ".sqlesc($small_descr).", ".sqlesc($descr).", ".sqlesc($descr).", ".sqlesc($catid).", ".sqlesc($sourceid).", ".sqlesc($mediumid).", ".sqlesc($codecid).", ".sqlesc($audiocodecid).", ".sqlesc($standardid).", ".sqlesc($processingid).", ".sqlesc($teamid).", ".sqlesc($dname).", ".sqlesc($sp_state) .
-", " . sqlesc(date("Y-m-d H:i:s")) . ", " . sqlesc(date("Y-m-d H:i:s")) . ", ".sqlesc($nfo).", " . sqlesc($infohash). ", " . sqlesc(json_encode($postPtGen)) . ", " . array_sum($_POST['tags']) . ")");
+", " . sqlesc(date("Y-m-d H:i:s")) . ", " . sqlesc(date("Y-m-d H:i:s")) . ", ".sqlesc($nfo).", " . sqlesc($infohash). ", " . sqlesc(json_encode($postPtGen)) . ", " . array_sum($_POST['tags'] ?? []) . ")");
if (!$ret) {
if (mysql_errno() == 1062)
bark($lang_takeupload['std_torrent_existed']);