From c2111dcfd875e21715db200304cdc73d56a5b797 Mon Sep 17 00:00:00 2001 From: marcdeb1 Date: Sun, 28 Oct 2018 18:08:45 +0100 Subject: [PATCH 1/4] Added search page results --- src/Controller/MainController.php | 19 ++-- src/Template/Main/find.ctp | 150 ++++++++++++++++++++++++++++++ webroot/css/main.css | 1 + 3 files changed, 159 insertions(+), 11 deletions(-) create mode 100644 src/Template/Main/find.ctp diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index e301611..59197f4 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])->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/Template/Main/find.ctp b/src/Template/Main/find.ctp new file mode 100644 index 0000000..bf0f22f --- /dev/null +++ b/src/Template/Main/find.ctp @@ -0,0 +1,150 @@ +start('script'); ?> + +end(); ?> +element('header') ?> + +assign('title', 'Search Results') ?> + +
+

Search results

+
+ +
+ 0): ?> + 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 = 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 ))); + } + + ?> +
+ 0): ?> +
+ + +
+ +
+ + IsNSFW): ?> +
NSFW
+ +
+ +
+ IsNSFW && strlen(trim($claim->ThumbnailUrl)) > 0): ?> + + +
+ +
+ + +
+ + + +
No results were found.
+ +
+
+ +element('pagination') ?> 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 } -- 2.45.3 From 7e802fd37aa217bc55ac9e59a97cf80e5f18249f Mon Sep 17 00:00:00 2001 From: marcdeb1 Date: Sun, 28 Oct 2018 18:10:42 +0100 Subject: [PATCH 2/4] Minor bug fix --- src/Template/Main/find.ctp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Template/Main/find.ctp b/src/Template/Main/find.ctp index bf0f22f..831bf23 100644 --- a/src/Template/Main/find.ctp +++ b/src/Template/Main/find.ctp @@ -114,8 +114,9 @@
Created
- - +
+ Created->format('U'))->diffForHumans(); ?> +
ClaimType == 2): ?> -- 2.45.3 From 378c76e77629d1461c698e0901b730165b893fd2 Mon Sep 17 00:00:00 2001 From: marcdeb1 Date: Sun, 28 Oct 2018 18:18:58 +0100 Subject: [PATCH 3/4] Added getContentTag and getAutoThumbText to Claims model --- src/Model/Entity/Claim.php | 27 ++++++++++++++++++++ src/Template/Main/claims.ctp | 49 ++++-------------------------------- src/Template/Main/find.ctp | 21 ++-------------- src/Template/Main/index.ctp | 20 ++------------- 4 files changed, 36 insertions(+), 81 deletions(-) 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 index 831bf23..4148e81 100644 --- a/src/Template/Main/find.ctp +++ b/src/Template/Main/find.ctp @@ -54,7 +54,7 @@ if ($idx % 3 == 0) { $row++; } - $autoThumbText = ''; + $autoThumbText = $claim->getAutoThumbText(); $cost = ''; if (isset($claim->Price) && $claim->Price > 0) { $cost = $this->Amount->formatCurrency($claim->Price) . ' LBC'; @@ -63,24 +63,7 @@ } // 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/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(); ?>
-- 2.45.3 From 1b0fdeae37e552888260aa498873ceef4d8fa1f9 Mon Sep 17 00:00:00 2001 From: marcdeb1 Date: Mon, 29 Oct 2018 11:19:28 +0100 Subject: [PATCH 4/4] Order in search results --- src/Controller/MainController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index 59197f4..e8252fc 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -366,7 +366,7 @@ class MainController extends AppController { } } else { // finally, try exact claim name match - $claims = $this->Claims->find()->distinct(['Claims.ClaimId'])->where(['Name' => $criteria])->limit(10)->toArray(); + $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); } -- 2.45.3