Browse Source

delete getFoundHostPage method, update API version

main
ghost 1 year ago
parent
commit
02612d098b
  1. 2
      config/app.php.txt
  2. 35
      library/mysql.php
  3. 4
      library/sphinxql.php
  4. 13
      public/api.php
  5. 134
      public/explore.php
  6. 44
      public/search.php

2
config/app.php.txt

@ -396,7 +396,7 @@ define('CRAWL_MANIFEST', true); @@ -396,7 +396,7 @@ define('CRAWL_MANIFEST', true);
* Manifest API version compatibility
*
*/
define('CRAWL_MANIFEST_API_VERSION', 0.10);
define('CRAWL_MANIFEST_API_VERSION', 0.11);
/*
* Set default auto-crawl status for new manifest added

35
library/mysql.php

@ -295,41 +295,6 @@ class MySQL { @@ -295,41 +295,6 @@ class MySQL {
return $query->fetch();
}
public function getFoundHostPage(int $hostPageId) {
$query = $this->_db->prepare("SELECT `hostPage`.`hostPageId`,
`hostPage`.`uri`,
`hostPage`.`timeAdded`,
`hostPage`.`timeUpdated`,
`hostPage`.`mime`,
`hostPage`.`size`,
`host`.`scheme`,
`host`.`name`,
`host`.`port`,
IF (`host`.`port` IS NOT NULL,
CONCAT(`host`.`scheme`, '://', `host`.`name`, ':', `host`.`port`),
CONCAT(`host`.`scheme`, '://', `host`.`name`)
) AS `hostURL`,
IF (`host`.`port` IS NOT NULL,
CONCAT(`host`.`scheme`, '://', `host`.`name`, ':', `host`.`port`, `hostPage`.`uri`),
CONCAT(`host`.`scheme`, '://', `host`.`name`, `hostPage`.`uri`)
) AS `hostPageURL`
FROM `hostPage`
JOIN `host` ON (`host`.`hostId` = `hostPage`.`hostId`)
WHERE `hostPage`.`hostPageId` = ?
LIMIT 1");
$query->execute([$hostPageId]);
return $query->fetch();
}
public function addHostPage(int $hostId,
int $crc32uri,
string $uri,

4
library/sphinxql.php

@ -22,13 +22,13 @@ class SphinxQL { @@ -22,13 +22,13 @@ class SphinxQL {
public function searchHostPages(string $keyword, string $mime, int $start, int $limit, int $maxMatches) {
$query = $this->_sphinx->prepare("SELECT *, WEIGHT() + `rank` * IF (`rank` > 0, 1000, 1) AS `priority`
$query = $this->_sphinx->prepare("SELECT *, WEIGHT() + `rank` * IF (`rank` > 0, 1000, 1) AS `weight`
FROM `hostPage`
WHERE MATCH(?) AND `mime` = ?
ORDER BY `priority` DESC, WEIGHT() DESC
ORDER BY `weight` DESC, WEIGHT() DESC
LIMIT " . (int) ($start >= $maxMatches ? ($maxMatches > 0 ? $maxMatches - 1 : 0) : $start) . "," . (int) $limit . "

13
public/api.php

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
<?php
// Current version
define('API_VERSION', 0.10);
define('API_VERSION', 0.11);
// Load system dependencies
require_once(__DIR__ . '/../config/app.php');
@ -44,11 +44,16 @@ if (API_ENABLED) { @@ -44,11 +44,16 @@ if (API_ENABLED) {
foreach ($sphinxResults as $i => $sphinxResult) {
if ($hostPage = $db->getFoundHostPage($sphinxResult->id)) {
if ($hostPage = $db->getHostPage($sphinxResult->id)) {
$dbResults[$i] = $hostPage;
if ($host = $db->getHost($hostPage->hostId)) {
$dbResults[$i]->weight = $sphinxResult->weight;
$dbResults[$i] = $hostPage;
$dbResults[$i]->url = $host->url . $hostPage->uri;
$dbResults[$i]->weight = $sphinxResult->weight;
}
}
}

134
public/explore.php

@ -203,81 +203,83 @@ $placeholder = Filter::plural($totalPages, [sprintf(_('Over %s page or enter the @@ -203,81 +203,83 @@ $placeholder = Filter::plural($totalPages, [sprintf(_('Over %s page or enter the
</form>
</header>
<main>
<?php if ($hostPage = $db->getFoundHostPage($hp)) { ?>
<div>
<?php if ($hostPageDescription = $db->getLastPageDescription($hp)) { ?>
<?php if (!empty($hostPageDescription->title)) { ?>
<h2><?php echo htmlentities($hostPageDescription->title) ?></h2>
<?php if ($hostPage = $db->getHostPage($hp)) { ?>
<?php if ($host = $db->getHost($hostPage->hostId)) { ?>
<div>
<?php if ($hostPageDescription = $db->getLastPageDescription($hp)) { ?>
<?php if (!empty($hostPageDescription->title)) { ?>
<h2><?php echo htmlentities($hostPageDescription->title) ?></h2>
<?php } ?>
<?php if (!empty($hostPageDescription->description)) { ?>
<span><?php echo htmlentities($hostPageDescription->description) ?></span>
<?php } ?>
<?php if (!empty($hostPageDescription->keywords)) { ?>
<span><?php echo htmlentities($hostPageDescription->keywords) ?></span>
<?php } ?>
<?php } ?>
<?php if (!empty($hostPageDescription->description)) { ?>
<span><?php echo htmlentities($hostPageDescription->description) ?></span>
<a href="<?php echo urldecode($host->url . $hostPage->uri) ?>">
<img src="<?php echo WEBSITE_DOMAIN; ?>/file.php?type=identicon&query=<?php echo urlencode($host->name) ?>" alt="identicon" width="16" height="16" class="icon" />
<?php echo htmlentities(urldecode($host->url . $hostPage->uri)) ?>
</a>
</div>
<div>
<?php if (!empty($hostPage->mime)) { ?>
<p><?php echo _('MIME') ?></p>
<p><?php echo $hostPage->mime ?></p>
<?php } ?>
<?php if (!empty($hostPageDescription->keywords)) { ?>
<span><?php echo htmlentities($hostPageDescription->keywords) ?></span>
<?php if (!empty($hostPage->size)) { ?>
<p><?php echo _('Size') ?></p>
<p><?php echo $hostPage->size ?></p>
<?php } ?>
<?php } ?>
<a href="<?php echo $hostPage->hostPageURL ?>">
<img src="<?php echo WEBSITE_DOMAIN; ?>/file.php?type=identicon&query=<?php echo urlencode($hostPage->name) ?>" alt="identicon" width="16" height="16" class="icon" />
<?php echo htmlentities(urldecode($hostPage->hostURL) . urldecode($hostPage->uri)) ?>
</a>
</div>
<div>
<?php if (!empty($hostPage->mime)) { ?>
<p><?php echo _('MIME') ?></p>
<p><?php echo $hostPage->mime ?></p>
<?php } ?>
<?php if (!empty($hostPage->size)) { ?>
<p><?php echo _('Size') ?></p>
<p><?php echo $hostPage->size ?></p>
<?php } ?>
<?php if (!empty($hostPage->timeAdded)) { ?>
<p><?php echo _('Time added') ?></p>
<p><?php echo date('c', $hostPage->timeAdded) ?></p>
<?php } ?>
<?php if (!empty($hostPage->timeUpdated)) { ?>
<p><?php echo _('Time updated') ?></p>
<p><?php echo date('c', $hostPage->timeUpdated) ?></p>
<?php } ?>
<?php $totalHostPageSnaps = $db->getTotalHostPageSnaps($hp); ?>
<p>
<?php echo $totalHostPageSnaps ? Filter::plural($totalHostPageSnaps, [sprintf(_('%s snap'), $totalHostPageSnaps),
sprintf(_('%s snaps'), $totalHostPageSnaps),
sprintf(_('%s snaps'), $totalHostPageSnaps)]) : false ?>
</p>
<?php if ($totalHostPageSnaps) { ?>
<?php foreach ($db->getHostPageSnaps($hp) as $hostPageSnap) { ?>
<p>
<a href="<?php echo WEBSITE_DOMAIN . '/file.php?type=snap&hps=' . $hostPageSnap->hostPageSnapId ?>">
<?php echo date('c', $hostPageSnap->timeAdded) ?>
</a>
</p>
<?php if (!empty($hostPage->timeAdded)) { ?>
<p><?php echo _('Time added') ?></p>
<p><?php echo date('c', $hostPage->timeAdded) ?></p>
<?php } ?>
<?php } ?>
<?php $totalHostPageIdSources = $db->getTotalHostPagesToHostPageByHostPageIdTarget($hp); ?>
<p>
<?php echo $totalHostPageIdSources ? Filter::plural($totalHostPageIdSources, [sprintf(_('%s referrer'), $totalHostPageIdSources),
sprintf(_('%s referrers'), $totalHostPageIdSources),
sprintf(_('%s referrers'), $totalHostPageIdSources)]) : false ?>
</p>
<?php if ($totalHostPageIdSources) { ?>
<?php foreach ($db->getHostPagesToHostPageByHostPageIdTarget($hp) as $hostPageIdSource) { ?>
<?php if ($hostPage = $db->getFoundHostPage($hostPageIdSource->hostPageIdSource)) { ?>
<?php $hostPageDescription = $db->getLastPageDescription($hostPageIdSource->hostPageIdSource); ?>
<?php if (!empty($hostPage->timeUpdated)) { ?>
<p><?php echo _('Time updated') ?></p>
<p><?php echo date('c', $hostPage->timeUpdated) ?></p>
<?php } ?>
<?php $totalHostPageSnaps = $db->getTotalHostPageSnaps($hp); ?>
<p>
<?php echo $totalHostPageSnaps ? Filter::plural($totalHostPageSnaps, [sprintf(_('%s snap'), $totalHostPageSnaps),
sprintf(_('%s snaps'), $totalHostPageSnaps),
sprintf(_('%s snaps'), $totalHostPageSnaps)]) : false ?>
</p>
<?php if ($totalHostPageSnaps) { ?>
<?php foreach ($db->getHostPageSnaps($hp) as $hostPageSnap) { ?>
<p>
<a href="<?php echo $hostPage->hostPageURL ?>"
title="<?php echo (!empty($hostPageDescription->title) ? $hostPageDescription->title : (!empty($hostPageDescription->description) ? $hostPageDescription->description : false)) ?>">
<img src="<?php echo WEBSITE_DOMAIN; ?>/file.php?type=identicon&query=<?php echo urlencode($hostPage->name) ?>" alt="identicon" width="16" height="16" class="icon" />
<?php echo htmlentities(urldecode($hostPage->hostURL) . (mb_strlen(urldecode($hostPage->uri)) > 32 ? '...' . mb_substr(urldecode($hostPage->uri), -32) : urldecode($hostPage->uri))) ?>
</a>
|
<a href="<?php echo WEBSITE_DOMAIN; ?>/explore.php?hp=<?php echo $hostPage->hostPageId ?>">
<?php echo _('explore'); ?>
<a href="<?php echo WEBSITE_DOMAIN . '/file.php?type=snap&hps=' . $hostPageSnap->hostPageSnapId ?>">
<?php echo date('c', $hostPageSnap->timeAdded) ?>
</a>
</p>
<?php } ?>
<?php } ?>
<?php } ?>
</div>
<?php $totalHostPageIdSources = $db->getTotalHostPagesToHostPageByHostPageIdTarget($hp); ?>
<p>
<?php echo $totalHostPageIdSources ? Filter::plural($totalHostPageIdSources, [sprintf(_('%s referrer'), $totalHostPageIdSources),
sprintf(_('%s referrers'), $totalHostPageIdSources),
sprintf(_('%s referrers'), $totalHostPageIdSources)]) : false ?>
</p>
<?php if ($totalHostPageIdSources) { ?>
<?php foreach ($db->getHostPagesToHostPageByHostPageIdTarget($hp) as $hostPageIdSource) { ?>
<?php if ($hostPage = $db->getHostPage($hostPageIdSource->hostPageIdSource)) { ?>
<?php if ($host = $db->getHost($hostPage->hostId)) { ?>
<p>
<a href="<?php echo urldecode($host->url . $hostPage->uri) ?>">
<img src="<?php echo WEBSITE_DOMAIN; ?>/file.php?type=identicon&query=<?php echo urlencode($host->name) ?>" alt="identicon" width="16" height="16" class="icon" />
<?php echo htmlentities(urldecode($host->url) . (mb_strlen(urldecode($hostPage->uri)) > 28 ? '...' . mb_substr(urldecode($hostPage->uri), -28) : urldecode($hostPage->uri))) ?>
</a>
|
<a href="<?php echo WEBSITE_DOMAIN; ?>/explore.php?hp=<?php echo $hostPage->hostPageId ?>">
<?php echo _('explore'); ?>
</a>
</p>
<?php } ?>
<?php } ?>
<?php } ?>
<?php } ?>
</div>
<?php } ?>
<?php } else { ?>
<div style="text-align:center">
<span><?php echo _('Not found') ?></span>

44
public/search.php

@ -318,28 +318,30 @@ if (filter_var($q, FILTER_VALIDATE_URL) && preg_match(CRAWL_URL_REGEXP, $q)) { @@ -318,28 +318,30 @@ if (filter_var($q, FILTER_VALIDATE_URL) && preg_match(CRAWL_URL_REGEXP, $q)) {
<?php } ?>
</div>
<?php foreach ($results as $result) { ?>
<?php if ($hostPage = $db->getFoundHostPage($result->id)) { ?>
<div>
<?php if ($hostPageDescription = $db->getLastPageDescription($result->id)) { ?>
<?php if (!empty($hostPageDescription->title)) { ?>
<h2><?php echo $hostPageDescription->title ?></h2>
<?php if ($hostPage = $db->getHostPage($result->id)) { ?>
<?php if ($host = $db->getHost($hostPage->hostId)) { ?>
<div>
<?php if ($hostPageDescription = $db->getLastPageDescription($result->id)) { ?>
<?php if (!empty($hostPageDescription->title)) { ?>
<h2><?php echo $hostPageDescription->title ?></h2>
<?php } ?>
<?php if (!empty($hostPageDescription->description)) { ?>
<span><?php echo $hostPageDescription->description ?></span>
<?php } ?>
<?php if (!empty($hostPageDescription->keywords)) { ?>
<span><?php echo $hostPageDescription->keywords ?></span>
<?php } ?>
<?php } ?>
<?php if (!empty($hostPageDescription->description)) { ?>
<span><?php echo $hostPageDescription->description ?></span>
<?php } ?>
<?php if (!empty($hostPageDescription->keywords)) { ?>
<span><?php echo $hostPageDescription->keywords ?></span>
<?php } ?>
<?php } ?>
<a href="<?php echo $hostPage->hostPageURL ?>">
<img src="<?php echo WEBSITE_DOMAIN; ?>/file.php?type=identicon&query=<?php echo urlencode($hostPage->name) ?>" alt="identicon" width="16" height="16" class="icon" />
<?php echo htmlentities(urldecode($hostPage->hostURL) . (mb_strlen(urldecode($hostPage->uri)) > 28 ? '...' . mb_substr(urldecode($hostPage->uri), -28) : urldecode($hostPage->uri))) ?>
</a>
|
<a href="<?php echo WEBSITE_DOMAIN; ?>/explore.php?hp=<?php echo $result->id ?>">
<?php echo _('explore'); ?>
</a>
</div>
<a href="<?php echo urldecode($host->url . $hostPage->uri) ?>">
<img src="<?php echo WEBSITE_DOMAIN; ?>/file.php?type=identicon&query=<?php echo urlencode($host->name) ?>" alt="identicon" width="16" height="16" class="icon" />
<?php echo htmlentities(urldecode($host->url) . (mb_strlen(urldecode($hostPage->uri)) > 28 ? '...' . mb_substr(urldecode($hostPage->uri), -28) : urldecode($hostPage->uri))) ?>
</a>
|
<a href="<?php echo WEBSITE_DOMAIN; ?>/explore.php?hp=<?php echo $result->id ?>">
<?php echo _('explore'); ?>
</a>
</div>
<?php } ?>
<?php } ?>
<?php } ?>
<?php if ($p * WEBSITE_PAGINATION_SEARCH_PAGE_RESULTS_LIMIT <= $resultsTotal) { ?>

Loading…
Cancel
Save