diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index bdec053e..0a3e57c3 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -126,8 +126,7 @@ class Test extends Command // $r = $rep->getContinuousDays($attendance); // $r = $rep->getContinuousPoints(11); - $today = Carbon::today(); - $r = $today->endOfMonth(); + $r = parse_url('https://img9.doubanio.com/view/photo/l_ratio_poster/public/p2867903173.jpg', PHP_URL_SCHEME); dd($r); } diff --git a/app/Http/Resources/TorrentResource.php b/app/Http/Resources/TorrentResource.php index e0209e93..55ab38c9 100644 --- a/app/Http/Resources/TorrentResource.php +++ b/app/Http/Resources/TorrentResource.php @@ -49,9 +49,17 @@ class TorrentResource extends JsonResource 'thanks' => ThankResource::collection($this->whenLoaded('thanks')), 'reward_logs' => RewardResource::collection($this->whenLoaded('reward_logs')), ]; - $descriptionArr = format_description($this->descr); - $out['cover'] = get_image_from_description($descriptionArr, true); + if ($this->cover) { + $cover = $this->cover; + } else { + $descriptionArr = format_description($this->descr); + $cover = get_image_from_description($descriptionArr, true); + } + $out['cover'] = resize_image($cover, 100, 100); if ($request->routeIs('torrents.show')) { + if (!isset($descriptionArr)) { + $descriptionArr = format_description($this->descr); + } $baseInfo = [ ['label' => nexus_trans('torrent.show.size'), 'value' => mksize($this->size)], ]; diff --git a/app/Models/Torrent.php b/app/Models/Torrent.php index fc160991..9a722dc8 100644 --- a/app/Models/Torrent.php +++ b/app/Models/Torrent.php @@ -13,7 +13,7 @@ class Torrent extends NexusModel 'category', 'source', 'medium', 'codec', 'standard', 'processing', 'team', 'audiocodec', 'size', 'added', 'type', 'numfiles', 'owner', 'nfo', 'sp_state', 'promotion_time_type', 'promotion_until', 'anonymous', 'url', 'pos_state', 'cache_stamp', 'picktype', 'picktime', - 'last_reseed', 'pt_gen', 'technical_info', 'leechers', 'seeders', + 'last_reseed', 'pt_gen', 'technical_info', 'leechers', 'seeders', 'cover', ]; private static $globalPromotionState; @@ -31,7 +31,7 @@ class Torrent extends NexusModel public static $commentFields = [ 'id', 'name', 'added', 'visible', 'banned', 'owner', 'sp_state', 'pos_state', 'hr', 'picktype', 'picktime', - 'last_action', 'leechers', 'seeders', 'times_completed', 'views', 'size' + 'last_action', 'leechers', 'seeders', 'times_completed', 'views', 'size', 'cover' ]; public static $basicRelations = [ diff --git a/database/migrations/2022_05_03_155158_add_cover_to_torrents_table.php b/database/migrations/2022_05_03_155158_add_cover_to_torrents_table.php new file mode 100644 index 00000000..170c2589 --- /dev/null +++ b/database/migrations/2022_05_03_155158_add_cover_to_torrents_table.php @@ -0,0 +1,32 @@ +string('cover')->default('')->after('save_as'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('torrents', function (Blueprint $table) { + $table->dropColumn('cover'); + }); + } +}; diff --git a/include/functions.php b/include/functions.php index 702eab6b..6377964b 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1195,7 +1195,7 @@ function parse_imdb_id($url) if ($url != "" && preg_match("/[0-9]+/i", $url, $matches)) { return $matches[0]; } - return false; + return ''; } function build_imdb_url($imdb_id) @@ -5046,7 +5046,7 @@ 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")) + if ($showmovies['hot'] == "yes" || $showmovies['classic'] == "yes") { $imdb = new \Nexus\Imdb\Imdb(); $type = array('hot', 'classic'); @@ -5059,17 +5059,20 @@ function displayHotAndClassic() { $Cache->add_whole_row(); - $res = sql_query("SELECT sp_state, url, id, name, small_descr FROM torrents WHERE picktype = " . sqlesc($type_each) . " AND seeders > 0 AND url != '' ORDER BY id DESC LIMIT 30") or sqlerr(__FILE__, __LINE__); + $res = sql_query("SELECT sp_state, url, id, name, small_descr, cover FROM torrents WHERE picktype = " . sqlesc($type_each) . " AND seeders > 0 AND (url != '' OR cover != '') ORDER BY id DESC LIMIT 30") or sqlerr(__FILE__, __LINE__); if (mysql_num_rows($res) > 0) { $movies_list = ""; $count = 0; $allImdb = array(); + $width = 101; + $height = 140; 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 (!empty($array['cover'])) { + $thumbnail = "\"poster\""; + } elseif ($imdb_id = parse_imdb_id($array["url"])) { if (array_search($imdb_id, $allImdb) !== false) { //a torrent with the same IMDb url already exists continue; } @@ -5079,13 +5082,14 @@ function displayHotAndClassic() if (empty($photo_url)) { do_log("torrent: {$array['id']}, url: {$array['url']}, imdb_id: $imdb_id can not get photo", 'error'); } - $thumbnail = "\"poster\""; + $thumbnail = "\"poster\""; } catch (\Exception $exception) { do_log($exception->getMessage() . "\n[stacktrace]\n" . $exception->getTraceAsString(), 'error'); continue; } + } else { + continue; } - else continue; $thumbnail = "" . (addslashes($array['name'] . $pro_torrent)) . "
".(addslashes($array['small_descr'])) .""). "', 'trail', true, 'delay', 0,'lifetime',5000,'styleClass','niceTitle','maxWidth', 600);\">" . $thumbnail . "
"; $movies_list .= $thumbnail; $count++; @@ -5189,7 +5193,7 @@ function strip_all_tags($text) //去掉表情 static $emoji = null; if (is_null($emoji)) { - $emoji = config('emoji'); + $emoji = nexus_config('emoji'); } // $text = preg_replace("/\[em([1-9][0-9]*)\]/isU", "", $text); $text = preg_replace_callback("/\[em([1-9][0-9]*)\]/isU", function ($matches) use ($emoji) { @@ -5306,7 +5310,7 @@ function format_description(string $description) return $results; } -function get_image_from_description(array $descriptionArr, $first = false) +function get_image_from_description(array $descriptionArr, $first = false, $useDefault = true) { $imageType = ['attachment', 'image']; $images = []; @@ -5325,11 +5329,32 @@ function get_image_from_description(array $descriptionArr, $first = false) } } if ($first) { - return getSchemeAndHttpHost() . "/pic/imdb_pic/nophoto.gif"; + if ($useDefault) { + return getSchemeAndHttpHost() . "/pic/imdb_pic/nophoto.gif"; + } else { + return ''; + } } return $images; } +function resize_image($url, $with = null, $height = null, $fit = "cover") +{ + $scheme = parse_url($url, PHP_URL_SCHEME); + if ($scheme === false) { + return $url; + } + $url = "$scheme://images.weserv.nl/?url=$url"; + if ($with !== null) { + $url .= "&w=$with"; + } + if ($height !== null) { + $url .= "&h=$height"; + } + $url .= "&fit=$fit"; + return $url; +} + function get_share_ratio($uploaded, $downloaded) { if ($downloaded) { diff --git a/include/globalfunctions.php b/include/globalfunctions.php index 1c27b469..e573e1b2 100644 --- a/include/globalfunctions.php +++ b/include/globalfunctions.php @@ -250,12 +250,16 @@ function getLogFile() function nexus_config($key, $default = null) { + if (!IN_NEXUS) { + return config($key, $default); + } static $configs; if (is_null($configs)) { //get all configuration from config file // $files = glob(ROOT_PATH . 'config/*.php'); $files = [ ROOT_PATH . 'config/nexus.php', + ROOT_PATH . 'config/emoji.php', ]; foreach ($files as $file) { $basename = basename($file); diff --git a/nexus/Database/NexusDB.php b/nexus/Database/NexusDB.php index 055a5877..882c0a82 100644 --- a/nexus/Database/NexusDB.php +++ b/nexus/Database/NexusDB.php @@ -150,12 +150,12 @@ class NexusDB public static function insert($table, $data) { - if (!IN_NEXUS) { - return DB::table($table)->insertGetId($data); - } if (empty($table) || empty($data) || !is_array($data)) { throw new DatabaseException("require table and data(array)."); } + if (!IN_NEXUS) { + return DB::table($table)->insertGetId($data); + } $fields = array_map(function ($value) {return "`$value`";}, array_keys($data)); $values = array_map(function ($value) {return sqlesc($value);}, array_values($data)); $sql = sprintf("insert into `%s` (%s) values (%s)", $table, implode(', ', $fields), implode(', ', $values)); diff --git a/public/takeedit.php b/public/takeedit.php index 8fa23262..f6503d91 100644 --- a/public/takeedit.php +++ b/public/takeedit.php @@ -193,11 +193,19 @@ if(get_user_class()>=$torrentmanage_class && ($CURUSER['picker'] == 'yes' || get $doRecommend = true; } if ($doRecommend) { + do_log("[DEL_HOT_CLASSIC_RESOURCES]"); \Nexus\Database\NexusDB::cache_del("hot_resources"); \Nexus\Database\NexusDB::cache_del("classic_resources"); } } +/** + * get cover + * @since 1.7.8 + */ +$descriptionArr = format_description($descr); +$cover = get_image_from_description($descriptionArr, true, false); +$updateset[] = "cover = " . sqlesc($cover); sql_query("UPDATE torrents SET " . join(",", $updateset) . " WHERE id = $id") or sqlerr(__FILE__, __LINE__); diff --git a/public/takeupload.php b/public/takeupload.php index 93c834d4..c76a1142 100644 --- a/public/takeupload.php +++ b/public/takeupload.php @@ -302,15 +302,55 @@ if (!is_writable($torrentSavePath)) { bark("torrent save path: $torrentSavePath not writeable."); } -$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, technical_info) 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($_POST['pt_gen']) . ", " . sqlesc($_POST['technical_info'] ?? '') . ")"); -if (!$ret) { - if (mysql_errno() == 1062) - bark($lang_takeupload['std_torrent_existed']); - bark("mysql puked: ".mysql_error()); - //bark("mysql puked: ".preg_replace_callback('/./s', "hex_esc2", mysql_error())); -} -$id = mysql_insert_id(); +/** + * get cover + * @since 1.7.8 + */ +$descriptionArr = format_description($descr); +$cover = get_image_from_description($descriptionArr, true, false); +$insert = [ + 'filename' => $fname, + 'owner' => $CURUSER['id'], + 'visible' => 'yes', + 'anonymous' => $anonymous, + 'name' => $torrent, + 'size' => $totallen, + 'numfiles' => count($filelist), + 'type' => $type, + 'url' => $url, + 'small_descr' => $small_descr, + 'descr' => $descr, + 'ori_descr' => $descr, + 'category' => $catid, + 'source' => $sourceid, + 'medium' => $mediumid, + 'codec' => $codecid, + 'audiocodec' => $audiocodecid, + 'standard' => $standardid, + 'processing' => $processingid, + 'team' => $teamid, + 'save_as' => $dname, + 'sp_state' => $sp_state, + 'added' => $dateTimeStringNow, + 'last_action' => $dateTimeStringNow, + 'nfo' => $nfo, + 'info_hash' => $infohash, + 'pt_gen' => $_POST['pt_gen'] ?? '', + 'technical_info' => $_POST['technical_info'] ?? '', + 'cover' => $cover, +]; +$id = \Nexus\Database\NexusDB::insert('torrents', $insert); + +//$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, technical_info) 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($_POST['pt_gen']) . ", " . sqlesc($_POST['technical_info'] ?? '') . ")"); +//if (!$ret) { +// if (mysql_errno() == 1062) +// bark($lang_takeupload['std_torrent_existed']); +// bark("mysql puked: ".mysql_error()); +// //bark("mysql puked: ".preg_replace_callback('/./s', "hex_esc2", mysql_error())); +//} +//$id = mysql_insert_id(); + $torrentFilePath = "$torrentSavePath/$id.torrent"; $saveResult = \Rhilip\Bencode\Bencode::dump($torrentFilePath, $dict); if ($saveResult === false) {