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(); ?>