diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index e301611..e8252fc 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -329,9 +329,6 @@ class MainController extends AppController { public function find() { $criteria = $this->request->query('q'); - if ($criteria === null || strlen(trim($criteria)) == 0) { - return $this->redirect('/'); - } $this->loadModel('Blocks'); $this->loadModel('Claims'); @@ -354,7 +351,7 @@ class MainController extends AppController { // Claim ID $claim = $this->Claims->find()->select(['ClaimId'])->where(['ClaimId' => $criteria])->first(); if ($claim) { - return $this->redirect('/claim/' . $claim->ClaimId); + return $this->redirect('/claims/' . $claim->ClaimId); } } else if (strlen(trim($criteria)) === 64) { // block or tx hash // Try block hash first @@ -369,16 +366,16 @@ class MainController extends AppController { } } else { // finally, try exact claim name match - $claim = $this->Claims->find()->select(['ClaimId'])->where(['Name' => $criteria])->first(); - if ($claim) { - return $this->redirect('/claims/' . $claim->ClaimId); + $claims = $this->Claims->find()->distinct(['Claims.ClaimId'])->where(['Name' => $criteria])->order(['Claims.Created' => 'DESC'])->limit(10)->toArray(); + if (count($claims) == 1) { + return $this->redirect('/claims/' . $claims[0]->ClaimId); + } + else { + $this->set('claims', $claims); } } - - // Not found, redirect to index - return $this->redirect('/'); } - + public function blocks($height = null) { $this->loadModel('Blocks'); diff --git a/src/Model/Entity/Claim.php b/src/Model/Entity/Claim.php index dd12051..18a5734 100644 --- a/src/Model/Entity/Claim.php +++ b/src/Model/Entity/Claim.php @@ -18,6 +18,33 @@ class Claim extends Entity { $link = '/claims/' . $this->ClaimId; return $link; } + + function getContentTag() { + $ctTag = null; + if (substr($this->ContentType, 0, 5) === 'audio') { + $ctTag = 'audio'; + } else if (substr($this->ContentType, 0, 5) === 'video') { + $ctTag = 'video'; + } else if (substr($this->ContentType, 0, 5) === 'image') { + $ctTag = 'image'; + } + + if (!$ctTag && $this->ClaimType == 1) { + $ctTag = 'identity'; + } + return $ctTag; + } + + function getAutoThumbText() { + $autoThumbText = ''; + if ($this->ClaimType == 1) { + $autoThumbText = strtoupper(substr($this->Name, 1, min( strlen($this->Name), 3 ))); + } else { + $str = (strlen(trim($this->Title)) > 0) ? $this->Title : $this->Name; + $autoThumbText = strtoupper(substr($str, 0, min (strlen($str), 2 ))); + } + return $autoThumbText; + } } ?> diff --git a/src/Template/Main/claims.ctp b/src/Template/Main/claims.ctp index 0507716..0d4bfad 100644 --- a/src/Template/Main/claims.ctp +++ b/src/Template/Main/claims.ctp @@ -39,12 +39,7 @@ ClaimType == 1) { $autoThumbText = strtoupper(substr($claim->Name, 1, min( strlen($claim->Name), 10 ))); } else { - $str = str_replace(' ', '', (strlen(trim($claim->Title)) > 0) ? $claim->Title : $claim->Name); - $autoThumbText = strtoupper(mb_substr($str, 0, min( strlen($str), 10 ))); -} - +$autoThumbText = $claim->getAutoThumbText(); $cost = 'Free'; if (isset($claim->Price) && $claim->Price > 0) { $cost = $this->Amount->formatCurrency($claim->Price) . ' LBC'; @@ -156,7 +151,7 @@ if (strlen(trim($desc)) == 0) { $row++; } - $autoThumbText = ''; + $autoThumbText = $claim->getAutoThumbText(); $cost = ''; if (isset($claim->Price) && $claim->Price > 0) { $cost = $this->Amount->formatCurrency($claim->Price) . ' LBC'; @@ -165,24 +160,7 @@ if (strlen(trim($desc)) == 0) { } // content type - $ctTag = null; - if (substr($claim->ContentType, 0, 5) === 'audio') { - $ctTag = 'audio'; - } else if (substr($claim->ContentType, 0, 5) === 'video') { - $ctTag = 'video'; - } else if (substr($claim->ContentType, 0, 5) === 'image') { - $ctTag = 'image'; - } - - if (!$ctTag && $claim->ClaimType == 1) { - $ctTag = 'identity'; - } - - if ($claim->ClaimType == 1) { $autoThumbText = strtoupper(substr($claim->Name, 1, min( strlen($claim->Name), 10 ))); } else { - $str = str_replace(' ', '', (strlen(trim($claim->Title)) > 0) ? $claim->Title : $claim->Name); - $autoThumbText = strtoupper(mb_substr($str, 0, min( strlen($str), 10 ))); - } - + $ctTag = $claim->getContentTag(); ?>
0): ?> @@ -274,7 +252,7 @@ if (strlen(trim($desc)) == 0) { if ($idx % 3 == 0) { $row++; } - $autoThumbText = ''; + $autoThumbText = $claim->getAutoThumbText(); $cost = ''; if (isset($claim->Price) && $claim->Price > 0) { $cost = $this->Amount->formatCurrency($claim->Price) . ' LBC'; @@ -283,24 +261,7 @@ if (strlen(trim($desc)) == 0) { } // content type - $ctTag = null; - if (substr($claim->ContentType, 0, 5) === 'audio') { - $ctTag = 'audio'; - } else if (substr($claim->ContentType, 0, 5) === 'video') { - $ctTag = 'video'; - } else if (substr($claim->ContentType, 0, 5) === 'image') { - $ctTag = 'image'; - } - - if (!$ctTag && $claim->ClaimType == 1) { - $ctTag = 'identity'; - } - - if ($claim->ClaimType == 1) { $autoThumbText = strtoupper(substr($claim->Name, 1, min( strlen($claim->Name), 10 ))); } else { - $str = str_replace(' ', '', (strlen(trim($claim->Title)) > 0) ? $claim->Title : $claim->Name); - $autoThumbText = strtoupper(mb_substr($str, 0, min( strlen($str), 10 ))); - } - + $ctTag = $claim->getContentTag(); ?>
0): ?> diff --git a/src/Template/Main/find.ctp b/src/Template/Main/find.ctp new file mode 100644 index 0000000..4148e81 --- /dev/null +++ b/src/Template/Main/find.ctp @@ -0,0 +1,134 @@ +start('script'); ?> + +end(); ?> +element('header') ?> + +assign('title', 'Search Results') ?> + +
+

Search results

+
+ +
+ 0): ?> + getAutoThumbText(); + $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->Fee) . ' LBC'; + } + + // content type + $ctTag = $claim->getContentTag(); + ?> +
+ 0): ?> +
+ + +
+ +
+ + IsNSFW): ?> +
NSFW
+ +
+ +
+ IsNSFW && strlen(trim($claim->ThumbnailUrl)) > 0): ?> + + +
+ +
+ + +
+ + + +
No results were found.
+ +
+
+ +element('pagination') ?> diff --git a/src/Template/Main/index.ctp b/src/Template/Main/index.ctp index f862c5a..eb96c3f 100644 --- a/src/Template/Main/index.ctp +++ b/src/Template/Main/index.ctp @@ -185,7 +185,7 @@ Claims Explorer getAutoThumbText(); $link = $claim->Name; $rawLink = $claim->Name; if (isset($claim->Publisher->Name)) { @@ -196,23 +196,7 @@ $rawLink = 'lbry://' . $rawLink; // content type - $ctTag = null; - if (substr($claim->ContentType, 0, 5) === 'audio') { - $ctTag = 'audio'; - } else if (substr($claim->ContentType, 0, 5) === 'video') { - $ctTag = 'video'; - } else if (substr($claim->ContentType, 0, 5) === 'image') { - $ctTag = 'image'; - } - - if (!$ctTag && $claim->ClaimType == 1) { - $ctTag = 'identity'; - } - - if ($claim->ClaimType == 1) { $autoThumbText = strtoupper(substr($claim->Name, 1, min( strlen($claim->Name), 3 ))); } else { - $str = (strlen(trim($claim->Title)) > 0) ? $claim->Title : $claim->Name; - $autoThumbText = strtoupper(substr($str, 0, min (strlen($str), 2 ))); - } + $ctTag = $claim->getContentTag(); ?>
diff --git a/webroot/css/main.css b/webroot/css/main.css index 88c9ad7..c400838 100644 --- a/webroot/css/main.css +++ b/webroot/css/main.css @@ -88,6 +88,7 @@ border-radius: 0 8px 8px 0 } .claims-grid .claim-grid-item .link { font-size: 95%; font-weight: 300; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; line-height: 20px; height: 20px; margin-top: 6px } .claims-grid .claim-grid-item .label { font-size: 80%; color: #1e88e5 } +.claims-grid .no-results {font-style: italic; width: 100%; height: 300px; text-align: center; font-size: 90%; color: grey; } .claims-grid .claim-grid-item .value { font-weight: 300; word-break: break-word; word-wrap: break-word; font-size: 95%; line-height: 24px; height: 24px } .claims-grid .claim-grid-item .half-width { width: 155px; float: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 12px } .claims-grid .claim-grid-item .spacer { height: 16px }