change top rating from hosts to pages

This commit is contained in:
ghost 2023-07-27 15:09:58 +03:00
parent 2e2501b437
commit a4b4ea324b
2 changed files with 45 additions and 29 deletions

View File

@ -84,29 +84,45 @@ class MySQL {
return $query->fetchAll(); return $query->fetchAll();
} }
public function getTopHosts() { public function getTopHostPages() {
$query = $this->_db->query("SELECT `hostPage`.`hostPageId`, $query = $this->_db->query(" SELECT
`hostPage`.`uri`,
`host`.`hostId`,
`host`.`scheme`,
`host`.`name`,
`host`.`port`,
(SELECT COUNT(*) FROM `hostPageToHostPage`
WHERE `hostPageToHostPage`.`hostPageIdTarget` = `hostPage`.`hostPageId`
AND (SELECT `hostPageSource`.`hostId` FROM `hostPage` AS `hostPageSource`
WHERE `hostPageSource`.`hostPageId` = `hostPageToHostPage`.`hostPageIdSource`) <> `hostPage`.`hostId`) AS `rank`
FROM `hostPage` `hostPageTarget`.`hostId`,
JOIN `host` ON (`host`.`hostId` = `hostPage`.`hostId`) `hostPageTarget`.`hostPageId`,
`hostPageTarget`.`uri`,
WHERE `host`.`status` = '1' `hostTarget`.`scheme`,
AND `hostPage`.`uri` = '/' `hostTarget`.`name`,
AND `hostPage`.`httpCode` = 200 `hostTarget`.`port`,
AND `hostPage`.`timeBanned` IS NULL
AND `hostPage`.`mime` IS NOT NULL
ORDER BY `rank` DESC"); (
SELECT COUNT(*)
FROM `hostPageToHostPage`
JOIN `hostPage` AS `hostPageSource` ON (`hostPageSource`.`hostPageId` = `hostPageToHostPage`.`hostPageIdSource`)
WHERE `hostPageToHostPage`.`hostPageIdTarget` = `hostPageTarget`.`hostPageId`
AND `hostPageSource`.`hostId` <> `hostPageTarget`.`hostId`
) AS `rank`
FROM `hostPage` AS `hostPageTarget`
JOIN `host` AS `hostTarget` ON (`hostTarget`.`hostId` = `hostPageTarget`.`hostId`)
WHERE `hostTarget`.`status` = '1'
AND `hostPageTarget`.`httpCode` = 200
AND `hostPageTarget`.`timeBanned` IS NULL
AND `hostPageTarget`.`mime` IS NOT NULL
GROUP BY `hostPageTarget`.`hostPageId`
HAVING `rank` > 0
ORDER BY `rank` DESC
");
return $query->fetchAll(); return $query->fetchAll();
} }

View File

@ -229,20 +229,20 @@ $placeholder = Filter::plural($totalPages, [sprintf(_('Over %s page or enter the
</form> </form>
</header> </header>
<main> <main>
<?php if ($results = $db->getTopHosts()) { ?> <?php if ($topHostPages = $db->getTopHostPages()) { ?>
<table> <table>
<tr> <tr>
<th><?php echo _('#') ?></th> <th><?php echo _('#') ?></th>
<th><?php echo _('Host') ?></th> <th><?php echo _('Address') ?></th>
<th><?php echo _('Pages') ?></th> <th><?php echo _('Pages') ?></th>
<th><?php echo _('PR') ?></th> <th><?php echo _('PR') ?></th>
<th><?php echo _('Actions') ?></th> <th><?php echo _('Actions') ?></th>
</tr> </tr>
<?php foreach ($results as $i => $result) { ?> <?php foreach ($topHostPages as $i => $topHostPage) { ?>
<tr> <tr>
<td><?php echo $i + 1 ?></td> <td><?php echo $i + 1 ?></td>
<td> <td>
<?php if ($hostPageDescription = $db->getLastPageDescription($result->hostPageId)) { ?> <?php if ($hostPageDescription = $db->getLastPageDescription($topHostPage->hostPageId)) { ?>
<?php if (!empty($hostPageDescription->title)) { ?> <?php if (!empty($hostPageDescription->title)) { ?>
<?php $title = htmlentities($hostPageDescription->title) ?> <?php $title = htmlentities($hostPageDescription->title) ?>
<?php } else if (!empty($hostPageDescription->description)) { ?> <?php } else if (!empty($hostPageDescription->description)) { ?>
@ -253,18 +253,18 @@ $placeholder = Filter::plural($totalPages, [sprintf(_('Over %s page or enter the
<?php $title = false ?> <?php $title = false ?>
<?php } ?> <?php } ?>
<?php } ?> <?php } ?>
<a href="<?php echo $result->scheme . '://' . $result->name . ($result->port ? ':' . $result->port : false) ?>"title="<?php echo trim($title) ?>"> <a href="<?php echo $topHostPage->scheme . '://' . $topHostPage->name . ($topHostPage->port ? ':' . $topHostPage->port : false) . $topHostPage->uri ?>"title="<?php echo trim($title) ?>">
<img src="<?php echo WEBSITE_DOMAIN; ?>/file.php?type=identicon&query=<?php echo urlencode($result->name) ?>" alt="identicon" width="16" height="16" class="icon" /> <img src="<?php echo WEBSITE_DOMAIN; ?>/file.php?type=identicon&query=<?php echo urlencode($topHostPage->name) ?>" alt="identicon" width="16" height="16" class="icon" />
<?php echo htmlentities(urldecode($result->scheme . '://' . $result->name . ($result->port ? ':' . $result->port : false))) ?> <?php echo htmlentities(urldecode($topHostPage->scheme . '://' . $topHostPage->name . ($topHostPage->port ? ':' . $topHostPage->port : false))) ?>
</a> </a>
</td> </td>
<td> <td>
<?php $totalHostPages = $db->getTotalHostPages($result->hostId) ?> <?php $totalHostPages = $db->getTotalHostPages($topHostPage->hostId) ?>
<?php echo $totalHostPages . ($totalHostPages >= CRAWL_HOST_DEFAULT_PAGES_LIMIT ? '+' : false) ?> <?php echo $totalHostPages . ($totalHostPages >= CRAWL_HOST_DEFAULT_PAGES_LIMIT ? '+' : false) ?>
</td> </td>
<td><?php echo $result->rank ?></td> <td><?php echo $topHostPage->rank ?></td>
<td> <td>
<a href="<?php echo WEBSITE_DOMAIN; ?>/explore.php?hp=<?php echo $result->hostPageId ?>"> <a href="<?php echo WEBSITE_DOMAIN; ?>/explore.php?hp=<?php echo $topHostPage->hostPageId ?>">
<?php echo _('explore'); ?> <?php echo _('explore'); ?>
</a> </a>
</td> </td>