fix rss sticky

This commit is contained in:
xiaomlove
2023-01-16 19:43:56 +08:00
parent a47bc23138
commit 3bed01a03c
22 changed files with 88 additions and 68 deletions

View File

@@ -17,7 +17,7 @@ class CreateAgentAllowedFamilyTable extends Migration
return; return;
} }
Schema::create('agent_allowed_family', function (Blueprint $table) { Schema::create('agent_allowed_family', function (Blueprint $table) {
$table->tinyIncrements('id'); $table->increments('id');
$table->string('family', 50)->default(''); $table->string('family', 50)->default('');
$table->string('start_name', 100)->default(''); $table->string('start_name', 100)->default('');
$table->string('peer_id_pattern', 200)->default(''); $table->string('peer_id_pattern', 200)->default('');

View File

@@ -17,7 +17,7 @@ class CreateAudiocodecsTable extends Migration
return; return;
} }
Schema::create('audiocodecs', function (Blueprint $table) { Schema::create('audiocodecs', function (Blueprint $table) {
$table->tinyIncrements('id'); $table->increments('id');
$table->string('name', 30)->default(''); $table->string('name', 30)->default('');
$table->string('image')->default(''); $table->string('image')->default('');
$table->unsignedTinyInteger('sort_index')->default(0); $table->unsignedTinyInteger('sort_index')->default(0);

View File

@@ -17,7 +17,7 @@ class CreateCaticonsTable extends Migration
return; return;
} }
Schema::create('caticons', function (Blueprint $table) { Schema::create('caticons', function (Blueprint $table) {
$table->tinyIncrements('id'); $table->increments('id');
$table->string('name', 64)->default(''); $table->string('name', 64)->default('');
$table->string('folder')->default(''); $table->string('folder')->default('');
$table->string('cssfile')->default(''); $table->string('cssfile')->default('');

View File

@@ -17,7 +17,7 @@ class CreateCodecsTable extends Migration
return; return;
} }
Schema::create('codecs', function (Blueprint $table) { Schema::create('codecs', function (Blueprint $table) {
$table->tinyIncrements('id'); $table->increments('id');
$table->string('name', 30)->default(''); $table->string('name', 30)->default('');
$table->unsignedTinyInteger('sort_index')->default(0); $table->unsignedTinyInteger('sort_index')->default(0);
}); });

View File

@@ -17,7 +17,7 @@ class CreateDownloadspeedTable extends Migration
return; return;
} }
Schema::create('downloadspeed', function (Blueprint $table) { Schema::create('downloadspeed', function (Blueprint $table) {
$table->tinyIncrements('id'); $table->increments('id');
$table->string('name', 50)->default(''); $table->string('name', 50)->default('');
}); });
} }

View File

@@ -17,7 +17,7 @@ class CreateIspTable extends Migration
return; return;
} }
Schema::create('isp', function (Blueprint $table) { Schema::create('isp', function (Blueprint $table) {
$table->tinyIncrements('id'); $table->increments('id');
$table->string('name', 50)->nullable(); $table->string('name', 50)->nullable();
}); });
} }

View File

@@ -17,7 +17,7 @@ class CreateLinksTable extends Migration
return; return;
} }
Schema::create('links', function (Blueprint $table) { Schema::create('links', function (Blueprint $table) {
$table->tinyIncrements('id'); $table->increments('id');
$table->string('name', 30)->default(''); $table->string('name', 30)->default('');
$table->string('url')->default(''); $table->string('url')->default('');
$table->string('title', 50)->default(''); $table->string('title', 50)->default('');

View File

@@ -17,7 +17,7 @@ class CreateMediaTable extends Migration
return; return;
} }
Schema::create('media', function (Blueprint $table) { Schema::create('media', function (Blueprint $table) {
$table->tinyIncrements('id'); $table->increments('id');
$table->string('name', 30)->default(''); $table->string('name', 30)->default('');
$table->unsignedTinyInteger('sort_index')->default(0); $table->unsignedTinyInteger('sort_index')->default(0);
}); });

View File

@@ -17,7 +17,7 @@ class CreateProcessingsTable extends Migration
return; return;
} }
Schema::create('processings', function (Blueprint $table) { Schema::create('processings', function (Blueprint $table) {
$table->tinyIncrements('id'); $table->increments('id');
$table->string('name', 30)->default(''); $table->string('name', 30)->default('');
$table->unsignedTinyInteger('sort_index')->default(0); $table->unsignedTinyInteger('sort_index')->default(0);
}); });

View File

@@ -31,7 +31,7 @@ class CreateSnatchedTable extends Migration
$table->dateTime('startdat')->nullable(); $table->dateTime('startdat')->nullable();
$table->dateTime('completedat')->nullable(); $table->dateTime('completedat')->nullable();
$table->enum('finished', ['yes', 'no'])->default('no'); $table->enum('finished', ['yes', 'no'])->default('no');
$table->index(['torrentid', 'userid'], 'torrentid_userid'); $table->unique(['torrentid', 'userid'], 'torrentid_userid');
}); });
} }

View File

@@ -17,7 +17,7 @@ class CreateSourcesTable extends Migration
return; return;
} }
Schema::create('sources', function (Blueprint $table) { Schema::create('sources', function (Blueprint $table) {
$table->tinyIncrements('id'); $table->increments('id');
$table->string('name', 30)->default(''); $table->string('name', 30)->default('');
$table->unsignedTinyInteger('sort_index')->default(0); $table->unsignedTinyInteger('sort_index')->default(0);
}); });

View File

@@ -17,7 +17,7 @@ class CreateStandardsTable extends Migration
return; return;
} }
Schema::create('standards', function (Blueprint $table) { Schema::create('standards', function (Blueprint $table) {
$table->tinyIncrements('id'); $table->increments('id');
$table->string('name', 30)->default(''); $table->string('name', 30)->default('');
$table->unsignedTinyInteger('sort_index')->default(0); $table->unsignedTinyInteger('sort_index')->default(0);
}); });

View File

@@ -17,7 +17,7 @@ class CreateStylesheetsTable extends Migration
return; return;
} }
Schema::create('stylesheets', function (Blueprint $table) { Schema::create('stylesheets', function (Blueprint $table) {
$table->tinyIncrements('id'); $table->increments('id');
$table->string('uri')->default(''); $table->string('uri')->default('');
$table->string('name', 64)->default(''); $table->string('name', 64)->default('');
$table->text('addicode')->nullable(); $table->text('addicode')->nullable();

View File

@@ -17,7 +17,7 @@ class CreateTeamsTable extends Migration
return; return;
} }
Schema::create('teams', function (Blueprint $table) { Schema::create('teams', function (Blueprint $table) {
$table->tinyIncrements('id'); $table->increments('id');
$table->string('name', 30)->default(''); $table->string('name', 30)->default('');
$table->unsignedTinyInteger('sort_index')->default(0); $table->unsignedTinyInteger('sort_index')->default(0);
}); });

View File

@@ -17,7 +17,7 @@ class CreateUploadspeedTable extends Migration
return; return;
} }
Schema::create('uploadspeed', function (Blueprint $table) { Schema::create('uploadspeed', function (Blueprint $table) {
$table->tinyIncrements('id'); $table->increments('id');
$table->string('name', 50)->nullable(); $table->string('name', 50)->nullable();
}); });
} }

View File

@@ -934,23 +934,24 @@ function docleanup($forceAll = 0, $printProgress = false) {
} }
//delete duplicated snatched //delete duplicated snatched
$snatchRes = sql_query('select userid, torrentid, group_concat(id) as ids from snatched group by userid, torrentid having(count(*)) > 1'); //is it necessary ? duplicate snatch update by torrent_id + userid, all records key fields are the same
while ($snatchRow = mysql_fetch_assoc($snatchRes)) { // $snatchRes = sql_query('select userid, torrentid, group_concat(id) as ids from snatched group by userid, torrentid having(count(*)) > 1');
$torrentId = $snatchRow['torrentid']; // while ($snatchRow = mysql_fetch_assoc($snatchRes)) {
$userId = $snatchRow['userid']; // $torrentId = $snatchRow['torrentid'];
$idArr = explode(',', $snatchRes['ids']); // $userId = $snatchRow['userid'];
sort($idArr, SORT_NUMERIC); // $idArr = explode(',', $snatchRow['ids']);
$remainId = array_pop($idArr); // sort($idArr, SORT_NUMERIC);
$delIdStr = implode(',', $idArr); // $remainId = array_pop($idArr);
do_log("[DELETE_DUPLICATED_SNATCH], torrent: $torrentId, user: $userId"); // $delIdStr = implode(',', $idArr);
sql_query("delete from snatched where id in ($delIdStr)"); // do_log("[DELETE_DUPLICATED_SNATCH], torrent: $torrentId, user: $userId, snatchIdStr: $delIdStr");
sql_query("update claims set snatched_id = $remainId where torrent_id = $torrentId and uid = $userId"); // sql_query("delete from snatched where id in ($delIdStr)");
} // sql_query("update claims set snatched_id = $remainId where torrent_id = $torrentId and uid = $userId");
$log = "delete duplicated snatched"; // }
do_log($log); // $log = "delete duplicated snatched";
if ($printProgress) { // do_log($log);
printProgress($log); // if ($printProgress) {
} // printProgress($log);
// }
//Priority Class 5: cleanup every 15 days //Priority Class 5: cleanup every 15 days
$res = sql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime5'"); $res = sql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime5'");

View File

@@ -1,6 +1,6 @@
<?php <?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.0'); defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.0');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-01-11'); defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-01-16');
defined('IN_TRACKER') || define('IN_TRACKER', false); defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP"); defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org"); defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");

View File

@@ -40,9 +40,7 @@ $lang_getrss = array
'select_exact' => "准确", 'select_exact' => "准确",
'text_mode' => "", 'text_mode' => "",
'text_keyword_note' => "只订阅标题中包含此关键字的项目", 'text_keyword_note' => "只订阅标题中包含此关键字的项目",
'row_sort' => '排序', 'row_sticky' => '置顶',
'sort_sticky' => '置顶优先(默认)',
'sort_newest' => '最新优先',
); );
?> ?>

View File

@@ -40,7 +40,8 @@ $lang_getrss = array
'select_or' => "", 'select_or' => "",
'select_exact' => "准確", 'select_exact' => "准確",
'text_mode' => "", 'text_mode' => "",
'text_keyword_note' => "只訂閱標題中包含此關鍵字的項目" 'text_keyword_note' => "只訂閱標題中包含此關鍵字的項目",
'row_sticky' => '置頂',
); );
?> ?>

View File

@@ -39,7 +39,8 @@ $lang_getrss = array
'select_or' => "OR", 'select_or' => "OR",
'select_exact' => "Exact", 'select_exact' => "Exact",
'text_mode' => "matching mode ", 'text_mode' => "matching mode ",
'text_keyword_note' => "Ony subscribe to items with these keywords in titles." 'text_keyword_note' => "Ony subscribe to items with these keywords in titles.",
'row_sticky' => 'Sticky',
); );
?> ?>

View File

@@ -39,9 +39,10 @@ if ($showaudiocodec) $audiocodecs = searchbox_item_list("audiocodecs", $brsectio
} }
stdhead($lang_getrss['head_rss_feeds']); stdhead($lang_getrss['head_rss_feeds']);
$query = []; $query = [];
$allowed_showrows=array('10','50','100','200');
$stickyTypes = apply_filter('rss_sticky_types', ['first' => nexus_trans('torrent.pos_state_sticky'), 'second' => nexus_trans('torrent.pos_state_r_sticky')]);
$query[] = "passkey=" . $CURUSER['passkey']; $query[] = "passkey=" . $CURUSER['passkey'];
if ($_SERVER['REQUEST_METHOD'] == "POST") { if ($_SERVER['REQUEST_METHOD'] == "POST") {
$allowed_showrows=array('10','50','100','200');
$link = get_protocol_prefix(). $BASEURL ."/torrentrss.php"; $link = get_protocol_prefix(). $BASEURL ."/torrentrss.php";
if (isset($_POST['showrows']) && in_array($_POST['showrows'], $allowed_showrows, 1)) if (isset($_POST['showrows']) && in_array($_POST['showrows'], $allowed_showrows, 1))
$query[] = "rows=".(int)$_POST['showrows']; $query[] = "rows=".(int)$_POST['showrows'];
@@ -156,10 +157,8 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
$query[] = "search_mode=".$search_mode; $query[] = "search_mode=".$search_mode;
} }
} }
if (!empty($_POST['sort']) && in_array($_POST['sort'], ['newest', 'sticky'])) { if (!empty($_POST['sticky']) && is_array($_POST['sticky'])) {
$query[] = "sort=" . $_POST['sort']; $query[] = "sticky=" . implode(',', $_POST['sticky']);
} else {
$query[] = "sort=sticky";
} }
$inclbookmarked=intval($_POST['inclbookmarked'] ?? 0); $inclbookmarked=intval($_POST['inclbookmarked'] ?? 0);
if($inclbookmarked) if($inclbookmarked)
@@ -323,11 +322,14 @@ if (get_setting('main.spsct') == 'yes') {
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="rowhead"><?php echo $lang_getrss['row_sort']?> <td class="rowhead"><?php echo $lang_getrss['row_sticky']?>
</td> </td>
<td class="rowfollow" align="left"> <td class="rowfollow" align="left">
<label><input type="radio" name="sort" value="sticky" checked><?php echo $lang_getrss['sort_sticky']?></label> <?php
<label><input type="radio" name="sort" value="newest"><?php echo $lang_getrss['sort_newest']?></label> foreach ($stickyTypes as $key => $value) {
echo sprintf('<label><input type="checkbox" name="sticky[]" value="%s">%s</label>', $key, $value);
}
?>
</td> </td>
</tr> </tr>
<tr> <tr>
@@ -338,11 +340,11 @@ if (get_setting('main.spsct') == 'yes') {
</td> </td>
</tr> </tr>
<tr><td class="rowhead"><?php echo $lang_getrss['row_rows_per_page']?></td><td class="rowfollow" align="left"><select name="showrows"> <tr><td class="rowhead"><?php echo $lang_getrss['row_rows_per_page']?></td><td class="rowfollow" align="left"><select name="showrows">
<option value="10">10</option> <?php
<option value="20">20</option> foreach ($allowed_showrows as $showrow) {
<option value="30">30</option> echo sprintf('<option value="%s">%s</option>', $showrow, $showrow);
<option value="40">40</option> }
<option value="50">50</option> ?>
</select></td></tr> </select></td></tr>
<tr><td class="rowhead"><?php echo $lang_getrss['row_keyword']?></td> <tr><td class="rowhead"><?php echo $lang_getrss['row_keyword']?></td>
<td class="rowfollow" align="left"> <td class="rowfollow" align="left">

View File

@@ -6,7 +6,7 @@ if (!$passkey) {
} }
$cacheKey = "nexus_rss:$passkey:" . md5(http_build_query($_GET)); $cacheKey = "nexus_rss:$passkey:" . md5(http_build_query($_GET));
$cacheData = \Nexus\Database\NexusDB::cache_get($cacheKey); $cacheData = \Nexus\Database\NexusDB::cache_get($cacheKey);
if ($cacheData) { if ($cacheData && nexus_env('APP_ENV') != 'local') {
do_log("rss get from cache"); do_log("rss get from cache");
header ("Content-type: text/xml"); header ("Content-type: text/xml");
die($cacheData); die($cacheData);
@@ -75,15 +75,39 @@ if (isset($searchstr)){
$wherea[] = implode($ANDOR, $like_expression_array); $wherea[] = implode($ANDOR, $like_expression_array);
$where .= ($where ? " AND " : "") . implode(" AND ", $wherea); $where .= ($where ? " AND " : "") . implode(" AND ", $wherea);
} }
$hasSticky = false;
if (!empty($_GET['sticky'])) {
$stickyArr = explode(',', $_GET['sticky']);
$posStates = [];
if (in_array('first', $stickyArr)) {
$posStates[] = \App\Models\Torrent::POS_STATE_STICKY_FIRST;
}
if (in_array('second', $stickyArr)) {
$posStates[] = \App\Models\Torrent::POS_STATE_STICKY_SECOND;
}
$idArr = [];
if (!empty($posStates)) {
$idArr = \App\Models\Torrent::query()->whereIn('pos_state', $posStates)->pluck('id')->toArray();
}
$idArr = apply_filter("rss_sticky_promotion_torrent_ids", $idArr, $stickyArr);
if (!empty($idArr)) {
$hasSticky = true;
$where .= ($where ? " AND " : "") . "torrents.id in (" . implode(',', $idArr) . ")";
}
}
$limit = ""; $limit = "";
$startindex = intval($_GET['startindex'] ?? 0); if (!$hasSticky) {
if ($startindex) $startindex = intval($_GET['startindex'] ?? 0);
$limit .= $startindex.", "; if ($startindex) {
$showrows = intval($_GET['rows'] ?? 0); $limit .= $startindex.", ";
if($showrows < 1 || $showrows > 50) }
$showrows = 10; $showrows = intval($_GET['rows'] ?? 0);
$limit .= $showrows; if($showrows < 1 || $showrows > 200) {
$showrows = 10;
}
$limit .= $showrows;
}
//approval status //approval status
$approvalStatusNoneVisible = get_setting('torrent.approval_status_none_visible'); $approvalStatusNoneVisible = get_setting('torrent.approval_status_none_visible');
@@ -118,17 +142,10 @@ get_where("teams", "team", "tea");
get_where("audiocodecs", "audiocodec", "aud"); get_where("audiocodecs", "audiocodec", "aud");
if ($where) if ($where)
$where = "WHERE ".$where; $where = "WHERE ".$where;
if (!empty($_GET['sort']) && $_GET['sort'] == 'newest') { $sort = "id desc";
$sort = "id desc";
} else {
$sort = "pos_state desc, id desc";
}
//$query = "SELECT torrents.id, torrents.category, torrents.name, torrents.small_descr, torrents.descr, torrents.info_hash, torrents.size, torrents.added, torrents.anonymous, users.username AS username, categories.id AS cat_id, categories.name AS cat_name FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN users ON torrents.owner = users.id $where ORDER BY $sort LIMIT $limit"; //$query = "SELECT torrents.id, torrents.category, torrents.name, torrents.small_descr, torrents.descr, torrents.info_hash, torrents.size, torrents.added, torrents.anonymous, users.username AS username, categories.id AS cat_id, categories.name AS cat_name FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN users ON torrents.owner = users.id $where ORDER BY $sort LIMIT $limit";
$query = "SELECT torrents.id, torrents.category, torrents.name, torrents.small_descr, torrents.descr, torrents.info_hash, torrents.size, torrents.added, torrents.anonymous, torrents.owner, categories.name AS category_name FROM torrents LEFT JOIN categories ON category = categories.id $where ORDER BY $sort LIMIT $limit"; $query = "SELECT torrents.id, torrents.category, torrents.name, torrents.small_descr, torrents.descr, torrents.info_hash, torrents.size, torrents.added, torrents.anonymous, torrents.owner, categories.name AS category_name FROM torrents LEFT JOIN categories ON category = categories.id $where ORDER BY $sort" . ($limit ? " LIMIT $limit" : "");
$list = \Nexus\Database\NexusDB::select($query); $list = \Nexus\Database\NexusDB::select($query);
if ($inclbookmarked == 0) {
$list = apply_filter('torrent_list', $list, $startindex == 0 ? 0 : 1, null, $_GET['search'] ?? '');
}
//dd($list); //dd($list);
$torrentRep = new \App\Repositories\TorrentRepository(); $torrentRep = new \App\Repositories\TorrentRepository();