improve custom fields and add function displayHotAndClassic()

This commit is contained in:
xiaomlove
2021-03-05 02:05:27 +08:00
parent ee6660f9a8
commit f4c402a87b
9 changed files with 140 additions and 103 deletions
+58
View File
@@ -4622,4 +4622,62 @@ function canDoLogin()
return true; return true;
} }
function displayHotAndClassic()
{
global $showextinfo, $showmovies, $Cache, $lang_functions;
if (($showextinfo['imdb'] == 'yes' || get_setting('main.enable_pt_gen_system')) && ($showmovies['hot'] == "yes" || $showmovies['classic'] == "yes"))
{
$imdb = new \Nexus\Imdb\Imdb();
$type = array('hot', 'classic');
foreach($type as $type_each)
{
if($showmovies[$type_each] == 'yes' && (!isset($CURUSER) || $CURUSER['show' . $type_each] == 'yes'))
{
$Cache->new_page($type_each.'_resources', 900, true);
if (!$Cache->get_page())
{
$Cache->add_whole_row();
$res = sql_query("SELECT * FROM torrents WHERE picktype = " . sqlesc($type_each) . " AND seeders > 0 AND url != '' ORDER BY id DESC LIMIT 30") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) > 0)
{
$movies_list = "";
$count = 0;
$allImdb = array();
while($array = mysql_fetch_array($res))
{
$pro_torrent = get_torrent_promotion_append($array['sp_state'],'word');
if ($imdb_id = parse_imdb_id($array["url"]))
{
if (array_search($imdb_id, $allImdb) !== false) { //a torrent with the same IMDb url already exists
continue;
}
$allImdb[]=$imdb_id;
$photo_url = $imdb->getMovie($imdb_id)->photo(true);
$thumbnail = "<img width=\"101\" height=\"140\" src=\"".$photo_url."\" border=\"0\" alt=\"poster\" />";
}
else continue;
$thumbnail = "<a href=\"details.php?id=" . $array['id'] . "&amp;hit=1\" onmouseover=\"domTT_activate(this, event, 'content', '" . htmlspecialchars("<font class=\'big\'><b>" . (addslashes($array['name'] . $pro_torrent)) . "</b></font><br /><font class=\'medium\'>".(addslashes($array['small_descr'])) ."</font>"). "', 'trail', true, 'delay', 0,'lifetime',5000,'styleClass','niceTitle','maxWidth', 600);\">" . $thumbnail . "</a>";
$movies_list .= $thumbnail;
$count++;
if ($count >= 9)
break;
}
?>
<h2><?php echo $lang_functions['text_' . $type_each] ?></h2>
<table width="100%" border="1" cellspacing="0" cellpadding="5"><tr><td class="text nowrap" align="center">
<?php echo $movies_list ?></td></tr></table>
<?php
}
$Cache->end_whole_row();
$Cache->cache_page();
}
echo $Cache->next_row();
}
}
}
}
?> ?>
+1 -1
View File
@@ -19,7 +19,7 @@ $lang_fields = [
'js_sure_to_delete_this' => '你确信要删除此项目吗?', 'js_sure_to_delete_this' => '你确信要删除此项目吗?',
'submit_submit' => '提交', 'submit_submit' => '提交',
'field_type_text' => '短文本', 'field_type_text' => '短文本',
'field_type_textara' => '长文本', 'field_type_textarea' => '长文本',
'field_type_radio' => '横向单选', 'field_type_radio' => '横向单选',
'field_type_checkbox' => '横向多选', 'field_type_checkbox' => '横向多选',
'field_type_select' => '下拉单选', 'field_type_select' => '下拉单选',
+60 -37
View File
@@ -57,7 +57,7 @@ class Field
global $lang_fields; global $lang_fields;
$map = [ $map = [
self::TYPE_TEXT => $lang_fields['field_type_text'], self::TYPE_TEXT => $lang_fields['field_type_text'],
self::TYPE_TEXTAREA => $lang_fields['field_type_textara'], self::TYPE_TEXTAREA => $lang_fields['field_type_textarea'],
self::TYPE_RADIO => $lang_fields['field_type_radio'], self::TYPE_RADIO => $lang_fields['field_type_radio'],
self::TYPE_CHECKBOX => $lang_fields['field_type_checkbox'], self::TYPE_CHECKBOX => $lang_fields['field_type_checkbox'],
self::TYPE_SELECT => $lang_fields['field_type_select'], self::TYPE_SELECT => $lang_fields['field_type_select'],
@@ -227,7 +227,7 @@ HEAD;
return $result; return $result;
} }
public function buildTable(array $header, array $rows) protected function buildTable(array $header, array $rows)
{ {
$table = '<table border="1" cellspacing="0" cellpadding="5" width="100%"><thead><tr>'; $table = '<table border="1" cellspacing="0" cellpadding="5" width="100%"><thead><tr>';
foreach ($header as $key => $value) { foreach ($header as $key => $value) {
@@ -264,19 +264,20 @@ HEAD;
} }
public function renderUploadPage(array $customValues = []) public function renderOnUploadPage($torrentId = 0)
{ {
$searchBoxId = get_setting('main.browsecat'); global $browsecatmode;
$searchBox = DB::getOne('searchbox', "id = $searchBoxId"); $searchBox = DB::getOne('searchbox', "id = $browsecatmode");
if (empty($searchBox)) { if (empty($searchBox)) {
throw new \RuntimeException("Invalid search box: $searchBoxId"); throw new \RuntimeException("Invalid search box: $browsecatmode");
} }
$customValues = $this->listTorrentCustomField($torrentId);
$sql = sprintf('select * from torrents_custom_fields where id in (%s)', $searchBox['custom_fields']); $sql = sprintf('select * from torrents_custom_fields where id in (%s)', $searchBox['custom_fields']);
$res = sql_query($sql); $res = sql_query($sql);
$html = ''; $html = '';
while ($row = mysql_fetch_assoc($res)) { while ($row = mysql_fetch_assoc($res)) {
$name = "custom_fields[{$row['id']}]"; $name = "custom_fields[{$row['id']}]";
$currentValue = $customValues[$row['id']] ?? ''; $currentValue = $customValues[$row['id']]['custom_field_value'] ?? '';
if ($row['type'] == self::TYPE_TEXT) { if ($row['type'] == self::TYPE_TEXT) {
$html .= tr($row['label'], sprintf('<input type="text" name="%s" value="%s" style="width: 650px"/>', $name, $currentValue), 1); $html .= tr($row['label'], sprintf('<input type="text" name="%s" value="%s" style="width: 650px"/>', $name, $currentValue), 1);
} elseif ($row['type'] == self::TYPE_TEXTAREA) { } elseif ($row['type'] == self::TYPE_TEXTAREA) {
@@ -402,43 +403,16 @@ JS;
return $result; return $result;
} }
public function renderTorrentDetailPageMixed($torretnId) public function renderOnTorrentDetailsPage($torrentId)
{ {
global $browsecatmode; global $browsecatmode;
$displayName = get_searchbox_value($browsecatmode, 'custom_fields_display_name'); $displayName = get_searchbox_value($browsecatmode, 'custom_fields_display_name');
$displayOrder = get_searchbox_value($browsecatmode, 'custom_fields_display_order'); $displayOrder = get_searchbox_value($browsecatmode, 'custom_fields_display_order');
$customFields = $this->listTorrentCustomField($torretnId); $customFields = $this->listTorrentCustomField($torrentId);
$mixedRowContent = nl2br($displayOrder); $mixedRowContent = nl2br($displayOrder);
$rowByRowHtml = ''; $rowByRowHtml = '';
foreach ($customFields as $field) { foreach ($customFields as $field) {
$content = ''; $content = $this->formatCustomFieldValue($field);
$fieldValue = $field['custom_field_value'];
$typeInfo = self::$types[$field['type']];
switch ($field['type']) {
case self::TYPE_TEXT:
case self::TYPE_TEXTAREA:
case self::TYPE_FILE:
$content .= format_comment($fieldValue);
break;
case self::TYPE_IMAGE:
if (substr($fieldValue, 0, 4) == 'http') {
$content .= formatImg($fieldValue, true, 700, 0, "attach{$field['id']}");
} else {
$content .= format_comment($fieldValue);
}
break;
case self::TYPE_RADIO:
case self::TYPE_CHECKBOX:
case self::TYPE_SELECT;
$fieldContent = [];
foreach ((array)$fieldValue as $item) {
$fieldContent[] = $field['options'][$item] ?? '';
}
$content .= implode(' ', $fieldContent);
break;
default:
break;
}
$mixedRowContent = str_replace("<%{$field['name']}.label%>", $field['label'], $mixedRowContent); $mixedRowContent = str_replace("<%{$field['name']}.label%>", $field['label'], $mixedRowContent);
$mixedRowContent = str_replace("<%{$field['name']}.value%>", $content, $mixedRowContent); $mixedRowContent = str_replace("<%{$field['name']}.value%>", $content, $mixedRowContent);
if ($field['is_single_row']) { if ($field['is_single_row']) {
@@ -453,4 +427,53 @@ JS;
} }
protected function formatCustomFieldValue(array $customFieldWithValue)
{
$result = '';
$fieldValue = $customFieldWithValue['custom_field_value'];
switch ($customFieldWithValue['type']) {
case self::TYPE_TEXT:
case self::TYPE_TEXTAREA:
case self::TYPE_FILE:
$result .= format_comment($fieldValue);
break;
case self::TYPE_IMAGE:
if (substr($fieldValue, 0, 4) == 'http') {
$result .= formatImg($fieldValue, true, 700, 0, "attach{$customFieldWithValue['id']}");
} else {
$result .= format_comment($fieldValue);
}
break;
case self::TYPE_RADIO:
case self::TYPE_CHECKBOX:
case self::TYPE_SELECT;
$fieldContent = [];
foreach ((array)$fieldValue as $item) {
$fieldContent[] = $customFieldWithValue['options'][$item] ?? '';
}
$result .= implode(' ', $fieldContent);
break;
default:
break;
}
return $result;
}
public function getFieldValue($torrentId, $fieldName = null)
{
static $result;
if (is_null($result)) {
$customFields = $this->listTorrentCustomField($torrentId);
$result = [];
foreach ($customFields as &$field) {
$field['custom_field_value_formatted'] = $this->formatCustomFieldValue($field);
$result[$field['name']] = $field;
}
}
return is_null($fieldName) ? $result : ($result[$fieldName] ?? '');
}
} }
+12
View File
@@ -271,4 +271,16 @@ class Imdb
$result .= '</div></td>'; $result .= '</div></td>';
return $result; return $result;
} }
public function renderHotAndClassic()
{
global $showextinfo, $showmovies;
$shouldDisplay = ($showextinfo['imdb'] == 'yes' || get_setting('main.enable_pt_gen_system')) && ($showmovies['hot'] == "yes" || $showmovies['classic'] == "yes");
if (!$shouldDisplay) {
return '';
}
}
} }
+1 -1
View File
@@ -155,7 +155,7 @@ else {
// ---------------- end subtitle block -------------------// // ---------------- end subtitle block -------------------//
/**************start custom fields****************/ /**************start custom fields****************/
echo $customField->renderTorrentDetailPageMixed($id); echo $customField->renderOnTorrentDetailsPage($id);
/**************end custom fields****************/ /**************end custom fields****************/
+1 -3
View File
@@ -17,8 +17,6 @@ if (!$row) die();
* @since v1.6 * @since v1.6
*/ */
$customField = new \Nexus\Field\Field(); $customField = new \Nexus\Field\Field();
$customFieldValues = $customField->listTorrentCustomField($id);
//dd($customFieldValues);
if ($enablespecial == 'yes' && get_user_class() >= $movetorrent_class) if ($enablespecial == 'yes' && get_user_class() >= $movetorrent_class)
$allowmove = true; //enable moving torrent to other section $allowmove = true; //enable moving torrent to other section
@@ -67,7 +65,7 @@ else {
echo $ptGen->renderUploadPageFormInput($row['pt_gen']); echo $ptGen->renderUploadPageFormInput($row['pt_gen']);
} }
$customField->renderUploadPage($customFieldValues); $customField->renderOnUploadPage($id);
if ($enablenfo_main=='yes') if ($enablenfo_main=='yes')
tr($lang_edit['row_nfo_file'], "<font class=\"medium\"><input type=\"radio\" name=\"nfoaction\" value=\"keep\" checked=\"checked\" />".$lang_edit['radio_keep_current']. tr($lang_edit['row_nfo_file'], "<font class=\"medium\"><input type=\"radio\" name=\"nfoaction\" value=\"keep\" checked=\"checked\" />".$lang_edit['radio_keep_current'].
+1 -56
View File
@@ -4,8 +4,6 @@ dbconn(true);
require_once(get_langfile_path()); require_once(get_langfile_path());
loggedinorreturn(true); loggedinorreturn(true);
$userid = $CURUSER["id"]; $userid = $CURUSER["id"];
if ($showextinfo['imdb'] == 'yes')
require_once ("imdb/imdb.class.php");
if ($_SERVER["REQUEST_METHOD"] == "POST") if ($_SERVER["REQUEST_METHOD"] == "POST")
{ {
if ($showpolls_main == "yes") if ($showpolls_main == "yes")
@@ -87,60 +85,7 @@ while($Cache->next_row()){
echo $Cache->next_row(); echo $Cache->next_row();
// ------------- end: recent news ------------------// // ------------- end: recent news ------------------//
// ------------- start: hot and classic movies ------------------// // ------------- start: hot and classic movies ------------------//
if ($showextinfo['imdb'] == 'yes' && ($showmovies['hot'] == "yes" || $showmovies['classic'] == "yes")) displayHotAndClassic();
{
$type = array('hot', 'classic');
foreach($type as $type_each)
{
if($showmovies[$type_each] == 'yes' && (!isset($CURUSER) || $CURUSER['show' . $type_each] == 'yes'))
{
$Cache->new_page($type_each.'_resources', 900, true);
if (!$Cache->get_page())
{
$Cache->add_whole_row();
$imdbcfg = new imdb_config();
$res = sql_query("SELECT * FROM torrents WHERE picktype = " . sqlesc($type_each) . " AND seeders > 0 AND url != '' ORDER BY id DESC LIMIT 30") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) > 0)
{
$movies_list = "";
$count = 0;
$allImdb = array();
while($array = mysql_fetch_array($res))
{
$pro_torrent = get_torrent_promotion_append($array[sp_state],'word');
if ($imdb_id = parse_imdb_id($array["url"]))
{
if (array_search($imdb_id, $allImdb) !== false) { //a torrent with the same IMDb url already exists
continue;
}
$allImdb[]=$imdb_id;
$photo_url = $imdbcfg->photodir . $imdb_id. $imdbcfg->imageext;
if (file_exists($photo_url))
$thumbnail = "<img width=\"101\" height=\"140\" src=\"".$photo_url."\" border=\"0\" alt=\"poster\" />";
else continue;
}
else continue;
$thumbnail = "<a href=\"details.php?id=" . $array['id'] . "&amp;hit=1\" onmouseover=\"domTT_activate(this, event, 'content', '" . htmlspecialchars("<font class=\'big\'><b>" . (addslashes($array['name'] . $pro_torrent)) . "</b></font><br /><font class=\'medium\'>".(addslashes($array['small_descr'])) ."</font>"). "', 'trail', true, 'delay', 0,'lifetime',5000,'styleClass','niceTitle','maxWidth', 600);\">" . $thumbnail . "</a>";
$movies_list .= $thumbnail;
$count++;
if ($count >= 9)
break;
}
?>
<h2><?php echo $lang_index['text_' . $type_each . 'movies'] ?></h2>
<table width="100%" border="1" cellspacing="0" cellpadding="5"><tr><td class="text nowrap" align="center">
<?php echo $movies_list ?></td></tr></table>
<?php
}
$Cache->end_whole_row();
$Cache->cache_page();
}
echo $Cache->next_row();
}
}
}
// ------------- end: hot and classic movies ------------------// // ------------- end: hot and classic movies ------------------//
// ------------- start: funbox ------------------// // ------------- start: funbox ------------------//
if ($showfunbox_main == "yes" && (!isset($CURUSER) || $CURUSER['showfb'] == "yes")){ if ($showfunbox_main == "yes" && (!isset($CURUSER) || $CURUSER['showfb'] == "yes")){
+5 -4
View File
@@ -1,12 +1,9 @@
<?php <?php
require_once("../include/bittorrent.php"); require_once("../include/bittorrent.php");
dbconn(true); dbconn(true);
require_once(get_langfile_path("torrents.php")); require_once(get_langfile_path());
loggedinorreturn(); loggedinorreturn();
parked(); parked();
if ($showextinfo['imdb'] == 'yes') {
$imdb = new \Nexus\Imdb\Imdb();
}
//check searchbox //check searchbox
$sectiontype = $browsecatmode; $sectiontype = $browsecatmode;
@@ -875,6 +872,10 @@ elseif ($sectiontype == $browsecatmode)
stdhead($lang_torrents['head_torrents']); stdhead($lang_torrents['head_torrents']);
else stdhead($lang_torrents['head_music']); else stdhead($lang_torrents['head_music']);
print("<table width=\"940\" class=\"main\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td class=\"embedded\">"); print("<table width=\"940\" class=\"main\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td class=\"embedded\">");
displayHotAndClassic();
if ($allsec != 1 || $enablespecial != 'yes'){ //do not print searchbox if showing bookmarked torrents from all sections; if ($allsec != 1 || $enablespecial != 'yes'){ //do not print searchbox if showing bookmarked torrents from all sections;
?> ?>
<form method="get" name="searchbox" action="?"> <form method="get" name="searchbox" action="?">
+1 -1
View File
@@ -65,7 +65,7 @@ stdhead($lang_upload['head_upload']);
echo $ptGen->renderUploadPageFormInput(""); echo $ptGen->renderUploadPageFormInput("");
} }
$field = new \Nexus\Field\Field(); $field = new \Nexus\Field\Field();
$field->renderUploadPage(); $field->renderOnUploadPage();
if ($enablenfo_main=='yes') { if ($enablenfo_main=='yes') {
tr($lang_upload['row_nfo_file'], "<input type=\"file\" class=\"file\" name=\"nfo\" /><br /><font class=\"medium\">".$lang_upload['text_only_viewed_by'].get_user_class_name($viewnfo_class,false,true,true).$lang_upload['text_or_above']."</font>", 1); tr($lang_upload['row_nfo_file'], "<input type=\"file\" class=\"file\" name=\"nfo\" /><br /><font class=\"medium\">".$lang_upload['text_only_viewed_by'].get_user_class_name($viewnfo_class,false,true,true).$lang_upload['text_or_above']."</font>", 1);
} }