added price tags

This commit is contained in:
Akinwale Ariwodola 2017-06-16 06:46:06 +01:00
parent 6472a7ca49
commit 5cd9b3ec0a
5 changed files with 114 additions and 16 deletions

View file

@ -192,6 +192,8 @@ CREATE TABLE `Claims`
`Language` VARCHAR(20) CHARACTER SET latin1 COLLATE latin1_general_ci,
`ThumbnailUrl` TEXT,
`Title` TEXT,
`Fee` DECIMAL(18,8) DEFAULT 0 NOT NULL,
`FeeCurrency` CHAR(3),
`Created` DATETIME NOT NULL,
`Modified` DATETIME NOT NULL,
@ -217,3 +219,6 @@ CREATE TABLE ClaimStreams
PRIMARY KEY `PK_ClaimStream` (`Id`),
FOREIGN KEY `PK_ClaimStreamClaim` (`Id`) REFERENCES `Claims` (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;
ALTER TABLE Claims ADD COLUMN Fee DECIMAL(18,8) DEFAULT 0 NOT NULL AFTER Title;
ALTER TABLE Claims ADD COLUMN FeeCurrency CHAR(3) AFTER Fee;

View file

@ -111,9 +111,19 @@ class MainController extends AppController {
$this->loadModel('Claims');
$this->loadModel('Transactions');
$canConvert = false;
$priceInfo = json_decode($this->redis->get(self::lbcPriceKey));
if (isset($priceInfo->price)) {
$canConvert = true;
}
if (!$id) {
$claims = $this->Claims->find()->contain(['Stream', 'Publisher' => ['fields' => ['Name']]])->order(['Claims.Created' => 'DESC'])->limit(96)->toArray();
for ($i = 0; $i < count($claims); $i++) {
if ($canConvert && $claims[$i]->Fee > 0 && $claims[$i]->FeeCurrency == 'USD') {
$claims[$i]->Price = $claims[$i]->Fee * $priceInfo->price;
}
if (isset($claims[$i]->Stream)) {
$json = json_decode($claims[$i]->Stream->Stream);
if (isset($json->metadata->license)) {
@ -131,6 +141,10 @@ class MainController extends AppController {
return $this->redirect('/');
}
if ($canConvert && $claim->Fee > 0 && $claim->FeeCurrency == 'USD') {
$claim->Price = $claim->Fee * $priceInfo->price;
}
if (isset($claim->Stream)) {
$json = json_decode($claim->Stream->Stream);
if (isset($json->metadata->license)) {
@ -146,8 +160,12 @@ class MainController extends AppController {
// find more claims for the publisher
$moreClaims = $this->Claims->find()->contain(['Stream', 'Publisher' => ['fields' => ['Name']]])->
where(['Claims.ClaimType' => 2, 'Claims.Id <>' => $claim->Id, 'Claims.PublisherId' => isset($claim->Publisher) ? $claim->Publisher->ClaimId : $claim->ClaimId])->
limit(9)->order(['RAND()' => 'DESC'])->toArray();
limit(9)->order(['Claims.Fee' => 'DESC'])->toArray();
for ($i = 0; $i < count($moreClaims); $i++) {
if ($canConvert && $moreClaims[$i]->Fee > 0 && $moreClaims[$i]->FeeCurrency == 'USD') {
$moreClaims[$i]->Price = $moreClaims[$i]->Fee * $priceInfo->price;
}
if (isset($moreClaims[$i]->Stream)) {
$json = json_decode($moreClaims[$i]->Stream->Stream);
if (isset($json->metadata->license)) {

View file

@ -48,6 +48,30 @@ class BlockShell extends Shell {
return $string;
}
public function updateclaimfees() {
self::lock('claimfees');
$conn = ConnectionManager::get('default');
try {
$stmt = $conn->execute('SELECT CS.Id, CS.Stream FROM ClaimStreams CS JOIN Claims C ON C.Id = CS.Id WHERE C.Fee = 0 AND C.Id <= 11462 ORDER BY Id ASC');
$claims = $stmt->fetchAll(\PDO::FETCH_OBJ);
foreach ($claims as $claim) {
$stream = json_decode($claim->Stream);
if (isset($stream->metadata->fee) && $stream->metadata->fee->amount > 0) {
$fee = $stream->metadata->fee->amount;
$currency = $stream->metadata->fee->currency;
$conn->execute('UPDATE Claims SET Fee = ?, FeeCurrency = ? WHERE Id = ?', [$fee, $currency, $claim->Id]);
echo "Updated fee for claim ID: $claim->Id. Fee: $fee, Currency: $currency\n";
}
}
} catch (\Exception $e) {
print_r($e);
}
self::unlock('claimfees');
}
public function buildclaimindex() {
self::lock('buildindex');
@ -58,11 +82,13 @@ class BlockShell extends Shell {
$redis_key = 'claim.oid';
$last_claim_oid = $redis->exists($redis_key) ? $redis->get($redis_key) : 0;
try {
$stmt = $conn->execute('SELECT COUNT(Id) AS RecordCount FROM Outputs WHERE Id > ? AND TransactionId <= 1776540', [$last_claim_oid]);
$stmt = $conn->execute('SELECT COUNT(Id) AS RecordCount FROM Outputs WHERE Id > ?', [$last_claim_oid]);
$count = min(500000, $stmt->fetch(\PDO::FETCH_OBJ)->RecordCount);
$idx = 0;
$stmt = $conn->execute('SELECT O.Id, O.TransactionId, O.Vout, O.ScriptPubKeyAsm, T.Hash, IFNULL(T.TransactionTime, T.CreatedTime) AS TxTime FROM Outputs O JOIN Transactions T ON T.Id = O.TransactionId WHERE O.Id > ? AND O.TransactionId <= 1776540 ORDER BY O.Id ASC LIMIT 500000', [$last_claim_oid]);
$stmt = $conn->execute('SELECT O.Id, O.TransactionId, O.Vout, O.ScriptPubKeyAsm, T.Hash, IFNULL(T.TransactionTime, T.CreatedTime) AS TxTime FROM Outputs O ' .
'JOIN Transactions T ON T.Id = O.TransactionId WHERE O.Id > ? ORDER BY O.Id ASC LIMIT 500000',
[$last_claim_oid]);
while ($out = $stmt->fetch(\PDO::FETCH_OBJ)) {
$idx++;
$idx_str = str_pad($idx, strlen($count), '0', STR_PAD_LEFT);
@ -71,6 +97,14 @@ class BlockShell extends Shell {
$vout = $out->Vout;
if (strpos($out->ScriptPubKeyAsm, 'OP_CLAIM_NAME') !== false) {
// check if the claim already exists in the claims table
$stmt2 = $conn->execute('SELECT Id FROM Claims WHERE TransactionHash = ? AND Vout = ?', [$out->Hash, $out->Vout]);
$exist_claim = $stmt2->fetch(\PDO::FETCH_OBJ);
if ($exist_claim) {
echo "[$idx_str/$count] claim already exists for [$out->Hash:$vout]. Skipping.\n";
continue;
}
$asm_parts = explode(' ', $out->ScriptPubKeyAsm, 4);
$name_hex = $asm_parts[1];
$claim_name = @pack('H*', $name_hex);
@ -123,6 +157,8 @@ class BlockShell extends Shell {
'Author' => isset($claim->stream->metadata->author) ? $claim->stream->metadata->author : null,
'ThumbnailUrl' => isset($claim->stream->metadata->thumbnail) ? $claim->stream->metadata->thumbnail : null,
'IsNSFW' => isset($claim->stream->metadata->nsfw) ? $claim->stream->metadata->nsfw : 0,
'Fee' => isset($claim->stream->metadata->fee) ? $claim->stream->metadata->fee->amount : 0,
'FeeCurrency' => isset($claim->stream->metadata->fee) ? $claim->stream->metadata->fee->currency : 0,
'Created' => $tx_dt->format('Y-m-d H:i:s'),
'Modified' => $tx_dt->format('Y-m-d H:i:s')
];
@ -245,6 +281,8 @@ class BlockShell extends Shell {
'Author' => isset($claim->stream->metadata->author) ? $claim->stream->metadata->author : null,
'ThumbnailUrl' => isset($claim->stream->metadata->thumbnail) ? $claim->stream->metadata->thumbnail : null,
'IsNSFW' => isset($claim->stream->metadata->nsfw) ? $claim->stream->metadata->nsfw : 0,
'Fee' => isset($claim->stream->metadata->fee) ? $claim->stream->metadata->fee->amount : 0,
'FeeCurrency' => isset($claim->stream->metadata->fee) ? $claim->stream->metadata->fee->currency : 0,
'Created' => $tx_dt->format('Y-m-d H:i:s'),
'Modified' => $tx_dt->format('Y-m-d H:i:s')
];

View file

@ -50,6 +50,13 @@ if ($claim->ClaimType == 1) { $autoThumbText = strtoupper(substr($claim->Name, 1
$autoThumbText = strtoupper(substr($str, 0, min( strlen($str), 10 )));
}
$cost = 'Free';
if (isset($claim->Price) && $claim->Price > 0) {
$cost = $this->Amount->formatCurrency($claim->Price) . ' LBC';
} else if (isset($claim->Fee) && strtolower($claim->FeeCurrency) === 'lbc') {
$cost = $this->Amount->formatCurrency($claim->Price) . ' LBC';
}
$desc = $claim->Description;
if (strlen(trim($desc)) == 0) {
$desc = '<em>No description available.</em>';
@ -96,8 +103,13 @@ if (strlen(trim($desc)) == 0) {
<div class="value"><a href="/tx/<?php echo $claim->TransactionHash ?>#output-<?php echo $claim->Vout ?>"><?php echo $claim->TransactionHash ?></a></div>
<?php if ($claim->ClaimType == 2): ?>
<div class="label">NSFW</div>
<div class="value"><?php echo $claim->IsNSFW ? 'Yes' : 'No' ?></div>
<div class="label half-width">Fee</div>
<div class="label half-width">NSFW</div>
<div class="value half-width"><?php echo $cost ?></div>
<div class="value half-width"><?php echo $claim->IsNSFW ? 'Yes' : 'No' ?></div>
<div class="clear"></div>
<?php endif; ?>
</div>
</div>
@ -141,7 +153,9 @@ if (strlen(trim($desc)) == 0) {
<h4><?php echo isset($claim->Publisher) ? 'More from the publisher' : 'Published by this identity' ?></h4>
<div class="claims-grid">
<?php $idx = 1; $row = 1; $rowCount = ceil(count($moreClaims) / 3); foreach ($moreClaims as $claim):
<?php $idx = 1; $row = 1; $rowCount = ceil(count($moreClaims) / 3);
foreach ($moreClaims as $claim):
$last_row = ($row == $rowCount);
if ($idx % 3 == 0) {
$row++;
@ -153,6 +167,12 @@ if (strlen(trim($desc)) == 0) {
$link = $claim->Publisher->Name . '/' . $link;
}
$link = 'lbry://' . $link;
$cost = '';
if (isset($claim->Price) && $claim->Price > 0) {
$cost = $this->Amount->formatCurrency($claim->Price) . ' LBC';
} else if (isset($claim->Fee) && strtolower($claim->FeeCurrency) === 'lbc') {
$cost = $this->Amount->formatCurrency($claim->Price) . ' LBC';
}
// content type
$ctTag = null;
@ -175,11 +195,15 @@ if (strlen(trim($desc)) == 0) {
?>
<div data-id="<?php echo $claim->ClaimId ?>" class="claim-grid-item<?php if ($idx % 3 == 0): ?> last-item<?php endif; ?><?php if ($last_row): ?> last-row<?php endif; ?>">
<div class="tags">
<?php if ($ctTag): ?>
<div class="content-type"><?php echo strtoupper($ctTag) ?></div>
<?php if (strlen(trim($cost)) > 0): ?>
<div class="price-tag"><?php echo $cost ?></div>
<?php endif; ?>
<?php if ($claim->IsNSFW): ?>
<div class="tags">
<?php if ($ctTag): ?>
<div class="content-type"><?php echo strtoupper($ctTag) ?></div>
<?php endif; ?>
<?php if ($claim->IsNSFW): ?>
<div class="nsfw">NSFW</div>
<?php endif; ?>
</div>
@ -259,6 +283,13 @@ if (strlen(trim($desc)) == 0) {
}
$link = 'lbry://' . $link;
$cost = '';
if (isset($claim->Price) && $claim->Price > 0) {
$cost = $this->Amount->formatCurrency($claim->Price) . ' LBC';
} else if (isset($claim->Fee) && strtolower($claim->FeeCurrency) === 'lbc') {
$cost = $this->Amount->formatCurrency($claim->Price) . ' LBC';
}
// content type
$ctTag = null;
if (substr($claim->ContentType, 0, 5) === 'audio') {
@ -280,11 +311,15 @@ if (strlen(trim($desc)) == 0) {
?>
<div data-id="<?php echo $claim->ClaimId ?>" class="claim-grid-item<?php if ($idx % 3 == 0): ?> last-item<?php endif; ?><?php if ($last_row): ?> last-row<?php endif; ?>">
<div class="tags">
<?php if ($ctTag): ?>
<div class="content-type"><?php echo strtoupper($ctTag) ?></div>
<?php if (strlen(trim($cost)) > 0): ?>
<div class="price-tag"><?php echo $cost ?></div>
<?php endif; ?>
<?php if ($claim->IsNSFW): ?>
<div class="tags">
<?php if ($ctTag): ?>
<div class="content-type"><?php echo strtoupper($ctTag) ?></div>
<?php endif; ?>
<?php if ($claim->IsNSFW): ?>
<div class="nsfw">NSFW</div>
<?php endif; ?>
</div>

View file

@ -18,7 +18,7 @@ border-radius: 0 6px 8px 0 }
.home-container-cell > .main > .title { font-family: 'adelle-sans', sans-serif; font-weight: bold; font-size: 280%; margin: 24px auto 24px auto; width: 600px; text-align: center; color: #333; cursor: default }
.home-container-cell .search-input { display: block; margin: 0 auto; padding: 8px; text-align: center; border: 3px solid #ddd; border-radius: 16px; width: 720px; font-size: 115%; font-weight: 300 }
.home-container-cell .ctls { width: 600px; text-align: center; margin: 24px auto; position: relative }
.home-container-cell .ctls { width: 720px; text-align: center; margin: 24px auto; position: relative }
.home-container-cell .ctls .btn-search { font-size: 115%; display: inline-block; padding: 12px 48px; background: #1e88e5; color: #fff; border-radius: 8px; border: none; font-weight: 300; cursor: pointer }
.home-container-cell .ctls .btn-search:hover { background: #1976d2 }
.home-container-cell .ctls a { font-size: 115%; display: inline-block; font-weight: 300; position: absolute; right: 0; padding-top: 12px }
@ -87,6 +87,7 @@ border-radius: 0 6px 8px 0 }
.claims-grid .claim-grid-item:hover { background: #fbfbfb }
.claims-grid .claim-grid-item.last-item { margin-right: 0 }
.claims-grid .claim-grid-item.last-row { margin-bottom: 0 }
.claims-grid .claim-grid-item .price-tag { font-size: 65%; position: absolute; left: 0; top: 0; z-index: 505; background: #155b4a; color: #fff; text-align: center; padding: 4px 12px }
.claims-grid .claim-grid-item .tags { font-size: 65%; position: absolute; right: 0; top: 0; z-index: 505 }
.claims-grid .claim-grid-item .thumbnail { width: 100%; height: 200px; background: #f0f0f0; display: block; position: relative; overflow: hidden;}
.claims-grid .claim-grid-item .thumbnail img { width: 100%; position: absolute; left: 0; top: 0; border-bottom: 1px solid #eee }
@ -118,6 +119,7 @@ border-radius: 0 6px 8px 0 }
.claims-body .claim-info .content .label { font-size: 90%; color: #1e88e5 }
.claims-body .claim-info .content .value { font-weight: 300; margin-bottom: 24px; word-break: break-word; word-wrap: break-word }
.claims-body .claim-info .content .value:last-child { margin-bottom: 0 }
.claims-body .claim-info .content .half-width { width: 50%; float: left }
.claims-body .claim-info .thumbnail.purple { background: #ab47bc }
.claims-body .claim-info .thumbnail.orange { background: #e91e63 }
.claims-body .claim-info .thumbnail.blue { background: #42a5f5 }