mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-03 14:10:57 +08:00
unify torrent rating rendering
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Nexus\Imdb;
|
|||||||
|
|
||||||
use Imdb\Config;
|
use Imdb\Config;
|
||||||
use Imdb\Title;
|
use Imdb\Title;
|
||||||
|
use Nexus\PTGen\PTGen;
|
||||||
|
|
||||||
class Imdb
|
class Imdb
|
||||||
{
|
{
|
||||||
@@ -13,6 +14,8 @@ class Imdb
|
|||||||
|
|
||||||
private $pages = array('Title', 'Credits', 'ReleaseInfo', );
|
private $pages = array('Title', 'Credits', 'ReleaseInfo', );
|
||||||
|
|
||||||
|
private $ptGen;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$config = new Config();
|
$config = new Config();
|
||||||
@@ -265,25 +268,14 @@ class Imdb
|
|||||||
if (!is_numeric($rating)) {
|
if (!is_numeric($rating)) {
|
||||||
$rating = $defaultRating;
|
$rating = $defaultRating;
|
||||||
}
|
}
|
||||||
$site = 'imdb';
|
return $this->getPtGen()->buildRatingSpan([PTGen::SITE_IMDB => $rating]);
|
||||||
$result = '<td class="embedded" style="text-align: right; width: 40px;padding: 4px"><div style="display: flex;flex-direction: column">';
|
|
||||||
$result .= sprintf(
|
|
||||||
'<div style="display: flex;align-content: center;justify-content: space-between;padding: 2px 0"><img src="%s" alt="%s" title="%s" style="max-width: 16px;max-height: 16px"/><span>%s</span></div>',
|
|
||||||
'pic/imdb2.png', $site, $site, $rating
|
|
||||||
);
|
|
||||||
$result .= '</div></td>';
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderHotAndClassic()
|
public function getPtGen()
|
||||||
{
|
{
|
||||||
global $showextinfo, $showmovies;
|
if (empty($this->ptGen)) {
|
||||||
|
$this->ptGen = new PTGen();
|
||||||
$shouldDisplay = ($showextinfo['imdb'] == 'yes' || get_setting('main.enable_pt_gen_system')) && ($showmovies['hot'] == "yes" || $showmovies['classic'] == "yes");
|
|
||||||
if (!$shouldDisplay) {
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
|
return $this->ptGen;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,11 +40,7 @@ class PTGen
|
|||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$setting = get_setting('main');
|
$setting = get_setting('main');
|
||||||
if (empty($setting['pt_gen_api_point'])) {
|
$this->setApiPoint($setting['pt_gen_api_point'] ?? '');
|
||||||
do_log("empty PT-Gen api point", 'warning');
|
|
||||||
} else {
|
|
||||||
$this->setApiPoint($setting['pt_gen_api_point']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getApiPoint(): string
|
public function getApiPoint(): string
|
||||||
@@ -230,24 +226,51 @@ HTML;
|
|||||||
|
|
||||||
public function renderTorrentsPageAverageRating(array $ptGenData)
|
public function renderTorrentsPageAverageRating(array $ptGenData)
|
||||||
{
|
{
|
||||||
$result = '<td class="embedded" style="text-align: right; width: 40px;padding: 4px"><div style="display: flex;flex-direction: column">';
|
$siteIdAndRating = [];
|
||||||
$count = 1;
|
|
||||||
foreach (self::$validSites as $site => $info) {
|
foreach (self::$validSites as $site => $info) {
|
||||||
$rating = $ptGenData[$site]['data']["{$site}_rating_average"] ?? '';
|
$rating = $ptGenData[$site]['data']["{$site}_rating_average"] ?? '';
|
||||||
if (empty($rating)) {
|
if (empty($rating)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
$siteIdAndRating[$site] = $rating;
|
||||||
|
}
|
||||||
|
return $this->buildRatingSpan($siteIdAndRating);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildRatingSpan(array $siteIdAndRating)
|
||||||
|
{
|
||||||
|
$result = '<td class="embedded" style="text-align: right; width: 40px;padding: 4px"><div style="display: flex;flex-direction: column">';
|
||||||
|
$count = 1;
|
||||||
|
$ratingIcons = [];
|
||||||
|
foreach (self::$validSites as $site => $info) {
|
||||||
|
if (!isset($siteIdAndRating[$site])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$rating = $siteIdAndRating[$site];
|
||||||
|
if (empty($rating)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if ($count > 2) {
|
if ($count > 2) {
|
||||||
//only show the first two
|
//only show the first two
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$result .= sprintf(
|
$ratingIcons[] = $this->getRatingIcon($site, $rating);
|
||||||
'<div style="display: flex;align-content: center;justify-content: space-between;padding: 2px 0"><img src="%s" alt="%s" title="%s" style="max-width: 16px;max-height: 16px"/><span>%s</span></div>',
|
|
||||||
$info['rating_average_img'], $site, $site, $rating
|
|
||||||
);
|
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
$result .= '</div></td>';
|
if (empty($ratingIcons)) {
|
||||||
|
$ratingIcons[] = $this->getRatingIcon(self::SITE_IMDB, 'N/A');
|
||||||
|
$ratingIcons[] = $this->getRatingIcon(self::SITE_DOUBAN, 'N/A');
|
||||||
|
}
|
||||||
|
$result .= implode("", $ratingIcons) . '</div></td>';
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRatingIcon($siteId, $rating)
|
||||||
|
{
|
||||||
|
$result = sprintf(
|
||||||
|
'<div style="display: flex;align-content: center;justify-content: space-between;padding: 2px 0"><img src="%s" alt="%s" title="%s" style="max-width: 16px;max-height: 16px"/><span>%s</span></div>',
|
||||||
|
self::$validSites[$siteId]['rating_average_img'], $siteId, $siteId, $rating
|
||||||
|
);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user