diff --git a/CHANGELOG.md b/CHANGELOG.md index ee22434f0..6b1a4e57d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,6 +87,7 @@ - Updated Timeline.vue, move compose button. ([9cad8f77](https://github.com/pixelfed/pixelfed/commit/9cad8f77)) - Updated status embed, allow photo albums. Fixes ([#2374](https://github.com/pixelfed/pixelfed/issues/2374)). ([d11fac0d](https://github.com/pixelfed/pixelfed/commit/d11fac0d)) - Updated DiscoverController, fixes ([#2378](https://github.com/pixelfed/pixelfed/issues/2378)). ([8e7f4f9d](https://github.com/pixelfed/pixelfed/commit/8e7f4f9d)) +- Updated SearchController, update version. ([8d923d77](https://github.com/pixelfed/pixelfed/commit/8d923d77)) ## [v0.10.9 (2020-04-17)](https://github.com/pixelfed/pixelfed/compare/v0.10.8...v0.10.9) ### Added diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php index 3555bfe94..3f5accd35 100644 --- a/app/Http/Controllers/SearchController.php +++ b/app/Http/Controllers/SearchController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers; use Auth; use App\Hashtag; +use App\Place; use App\Profile; use App\Status; use Illuminate\Http\Request; @@ -34,7 +35,7 @@ class SearchController extends Controller $this->validate($request, [ 'q' => 'required|string|min:3|max:120', 'src' => 'required|string|in:metro', - 'v' => 'required|integer|in:1', + 'v' => 'required|integer|in:2', 'scope' => 'required|in:all,hashtag,profile,remote,webfinger' ]); @@ -47,6 +48,7 @@ class SearchController extends Controller $this->getHashtags(); $this->getPosts(); $this->getProfiles(); + // $this->getPlaces(); break; case 'hashtag': @@ -65,6 +67,10 @@ class SearchController extends Controller $this->remoteLookupSearch(); break; + case 'place': + $this->getPlaces(); + break; + default: break; } @@ -153,6 +159,41 @@ class SearchController extends Controller $this->tokens['hashtags'] = $tokens; } + protected function getPlaces() + { + $tag = $this->term; + // $key = $this->cacheKey . 'places:' . $this->hash; + // $ttl = now()->addHours(12); + // $tokens = Cache::remember($key, $ttl, function() use($tag) { + $htag = Str::contains($tag, ',') == true ? explode(',', $tag) : [$tag]; + $hashtags = Place::select('id', 'name', 'slug', 'country') + ->where('name', 'like', '%'.$htag[0].'%') + ->paginate(20); + $tags = []; + if($hashtags->count() > 0) { + $tags = $hashtags->map(function ($item, $key) { + return [ + 'count' => null, + 'url' => $item->url(), + 'type' => 'place', + 'value' => $item->name . ', ' . $item->country, + 'tokens' => '', + 'name' => null, + 'city' => $item->name, + 'country' => $item->country + ]; + }); + // return $tags; + } + // }); + $this->tokens['places'] = $tags; + $this->tokens['placesPagination'] = [ + 'total' => $hashtags->total(), + 'current_page' => $hashtags->currentPage(), + 'last_page' => $hashtags->lastPage() + ]; + } + protected function getProfiles() { $tag = $this->term;