Browse Source

keep magnet star history by add value field, update for distribution and reaction features

main
ghost 1 year ago
parent
commit
32884e1733
  1. BIN
      database/yggtracker.mwb
  2. 34
      src/library/database.php
  3. 17
      src/public/action.php
  4. 12
      src/public/index.php
  5. 2
      src/public/magnet.php

BIN
database/yggtracker.mwb

Binary file not shown.

34
src/library/database.php

@ -1344,28 +1344,17 @@ class Database { @@ -1344,28 +1344,17 @@ class Database {
}
// Magnet star
public function addMagnetStar(int $magnetId, int $userId, int $timeAdded) : int {
public function addMagnetStar(int $magnetId, int $userId, bool $value, int $timeAdded) : int {
$this->_debug->query->insert->total++;
$query = $this->_db->prepare('INSERT INTO `magnetStar` SET `magnetId` = ?, `userId` = ?, `timeAdded` = ?');
$query = $this->_db->prepare('INSERT INTO `magnetStar` SET `magnetId` = ?, `userId` = ?, `value` = ?, `timeAdded` = ?');
$query->execute([$magnetId, $userId, $timeAdded]);
$query->execute([$magnetId, $userId, (int) $value, $timeAdded]);
return $this->_db->lastInsertId();
}
public function deleteMagnetStarByUserId(int $magnetId, int $userId) : int {
$this->_debug->query->delete->total++;
$query = $this->_db->prepare('DELETE FROM `magnetStar` WHERE `magnetId` = ? AND `userId` = ?');
$query->execute([$magnetId, $userId]);
return $query->rowCount();
}
public function findMagnetStarsTotalByMagnetId(int $magnetId) : int {
$this->_debug->query->select->total++;
@ -1388,26 +1377,15 @@ class Database { @@ -1388,26 +1377,15 @@ class Database {
return $query->fetch()->result;
}
public function findMagnetStarsTotal(int $magnetId, int $userId) : int {
public function findLastMagnetStarValue(int $magnetId, int $userId) : bool {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT COUNT(*) AS `result` FROM `magnetStar` WHERE `magnetId` = ? AND `userId` = ?');
$query = $this->_db->prepare('SELECT * FROM `magnetStar` WHERE `magnetId` = ? AND `userId` = ? ORDER BY `magnetStarId` DESC');
$query->execute([$magnetId, $userId]);
return $query->fetch()->result;
}
public function findMagnetStarByUserId(int $magnetId, int $userId) : int {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT * FROM `magnetStar` WHERE `magnetId` = ? AND `userId` = ?');
$query->execute([$magnetId, $userId]);
return $query->fetch();
return $query->rowCount() ? (bool) $query->fetch()->value : false;
}
// Magnet download

17
src/public/action.php

@ -420,16 +420,13 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) @@ -420,16 +420,13 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false)
// Request valid
else
{
// Star exists, trigger delete
if ($db->findMagnetStarsTotal($magnet->magnetId, $userId))
{
$db->deleteMagnetStarByUserId($magnet->magnetId, $userId);
}
else
{
// Star not exists, trigger add
$db->addMagnetStar($magnet->magnetId, $userId, time());
}
// Save value
$db->addMagnetStar(
$magnet->magnetId,
$userId,
!$db->findLastMagnetStarValue($magnet->magnetId, $userId),
time()
);
// Redirect to edit page
header(

12
src/public/index.php

@ -144,7 +144,7 @@ else @@ -144,7 +144,7 @@ else
'star' => (object)
[
'total' => $db->findMagnetStarsTotalByMagnetId($magnet->magnetId),
'status' => $db->findMagnetStarsTotal($magnet->magnetId, $userId),
'status' => $db->findLastMagnetStarValue($magnet->magnetId, $userId),
],
'access' => (object)
[
@ -253,14 +253,6 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?> @@ -253,14 +253,6 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?>
<path fill-rule="evenodd" d="M1 13.5A1.5 1.5 0 0 0 2.5 15h11a1.5 1.5 0 0 0 1.5-1.5v-6a.5.5 0 0 0-1 0v6a.5.5 0 0 1-.5.5h-11a.5.5 0 0 1-.5-.5v-11a.5.5 0 0 1 .5-.5H9a.5.5 0 0 0 0-1H2.5A1.5 1.5 0 0 0 1 2.5v11z"/>
</svg>
</a>
<?php } else { ?>
<!-- TODO
<a class="text-color-pink margin-l-12" rel="nofollow" href="<?php echo WEBSITE_URL ?>/action.php?target=magnet&toggle=report&magnetId=<?php echo $magnet->magnetId ?>&callback=<?php echo base64_encode(sprintf('%s/index.php?query=%s#magnet-%s', WEBSITE_URL, urlencode($request->query), $magnet->magnetId)) ?>" title="<?php echo _('Report') ?>">
<svg class="text-color-pink" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-flag" viewBox="0 0 16 16">
<path d="M14.778.085A.5.5 0 0 1 15 .5V8a.5.5 0 0 1-.314.464L14.5 8l.186.464-.003.001-.006.003-.023.009a12.435 12.435 0 0 1-.397.15c-.264.095-.631.223-1.047.35-.816.252-1.879.523-2.71.523-.847 0-1.548-.28-2.158-.525l-.028-.01C7.68 8.71 7.14 8.5 6.5 8.5c-.7 0-1.638.23-2.437.477A19.626 19.626 0 0 0 3 9.342V15.5a.5.5 0 0 1-1 0V.5a.5.5 0 0 1 1 0v.282c.226-.079.496-.17.79-.26C4.606.272 5.67 0 6.5 0c.84 0 1.524.277 2.121.519l.043.018C9.286.788 9.828 1 10.5 1c.7 0 1.638-.23 2.437-.477a19.587 19.587 0 0 0 1.349-.476l.019-.007.004-.002h.001M14 1.221c-.22.078-.48.167-.766.255-.81.252-1.872.523-2.734.523-.886 0-1.592-.286-2.203-.534l-.008-.003C7.662 1.21 7.139 1 6.5 1c-.669 0-1.606.229-2.415.478A21.294 21.294 0 0 0 3 1.845v6.433c.22-.078.48-.167.766-.255C4.576 7.77 5.638 7.5 6.5 7.5c.847 0 1.548.28 2.158.525l.028.01C9.32 8.29 9.86 8.5 10.5 8.5c.668 0 1.606-.229 2.415-.478A21.317 21.317 0 0 0 14 7.655V1.222z"/>
</svg>
</a>
-->
<?php } ?>
</div>
<?php if ($magnet->metaDescription) { ?>
@ -319,7 +311,7 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?> @@ -319,7 +311,7 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?>
</span>
<?php } ?>
<span class="float-right margin-l-12">
<a rel="nofollow" href="<?php echo WEBSITE_URL ?>/action.php?target=magnet&toggle=star&magnetId=<?php echo $magnet->magnetId ?>&callback=<?php echo base64_encode(sprintf('%s/index.php?query=%s#magnet-%s', WEBSITE_URL, urlencode($request->query), $magnet->magnetId)) ?>" title="<?php echo _('Star') ?>">
<a rel="nofollow" href="<?php echo WEBSITE_URL ?>/action.php?target=magnet&toggle=star&magnetId=<?php echo $magnet->magnetId ?>&callback=<?php echo base64_encode(sprintf('%s/magnet.php?magnetId=%s', WEBSITE_URL, $magnet->magnetId)) ?>" title="<?php echo _('Star') ?>">
<?php if ($magnet->star->status) { ?>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-star-fill" viewBox="0 0 16 16">
<path d="M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.282.95l-3.522 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z"/>

2
src/public/magnet.php

@ -132,7 +132,7 @@ else @@ -132,7 +132,7 @@ else
'star' => (object)
[
'total' => $db->findMagnetStarsTotalByMagnetId($magnet->magnetId),
'status' => $db->findMagnetStarsTotal($magnet->magnetId, $userId),
'status' => $db->findLastMagnetStarValue($magnet->magnetId, $userId),
],
'access' => (object)
[

Loading…
Cancel
Save