Skip to content

Commit

Permalink
Merge pull request #256 from Kovah/dev
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
Kovah authored Apr 9, 2021
2 parents f98acbc + 7f76a86 commit 31dc29a
Show file tree
Hide file tree
Showing 48 changed files with 1,517 additions and 1,098 deletions.
93 changes: 93 additions & 0 deletions app/Http/Controllers/App/FeedController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace App\Http\Controllers\App;

use App\Http\Controllers\Controller;
use App\Models\Link;
use App\Models\LinkList;
use App\Models\Tag;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class FeedController extends Controller
{
public function links(Request $request): Response
{
$links = Link::latest()->with('user')->get();
$meta = [
'title' => 'LinkAce Links',
'link' => $request->fullUrl(),
'updated' => now()->toRfc3339String(),
'id' => $request->fullUrl(),
];

return new Response(view('actions.feed.links', [
'meta' => $meta,
'links' => $links,
]), 200, ['Content-Type' => 'application/xml']);
}

public function lists(Request $request): Response
{
$lists = LinkList::latest()->with('user')->get();
$meta = [
'title' => 'LinkAce Lists',
'link' => $request->fullUrl(),
'updated' => now()->toRfc3339String(),
'id' => $request->fullUrl(),
];

return new Response(view('actions.feed.lists', [
'meta' => $meta,
'lists' => $lists,
]), 200, ['Content-Type' => 'application/xml']);
}

public function listLinks(Request $request, LinkList $list): Response
{
$links = $list->links()->with('user')->latest()->get();
$meta = [
'title' => $list->name,
'link' => $request->fullUrl(),
'updated' => now()->toRfc3339String(),
'id' => $request->fullUrl(),
];

return new Response(view('actions.feed.links', [
'meta' => $meta,
'links' => $links,
]), 200, ['Content-Type' => 'application/xml']);
}

public function tags(Request $request): Response
{
$tags = Tag::latest()->with('user')->get();
$meta = [
'title' => 'LinkAce Links',
'link' => $request->fullUrl(),
'updated' => now()->toRfc3339String(),
'id' => $request->fullUrl(),
];

return new Response(view('actions.feed.tags', [
'meta' => $meta,
'tags' => $tags,
]), 200, ['Content-Type' => 'application/xml']);
}

public function tagLinks(Request $request, Tag $tag): Response
{
$links = $tag->links()->with('user')->latest()->get();
$meta = [
'title' => $tag->name,
'link' => $request->fullUrl(),
'updated' => now()->toRfc3339String(),
'id' => $request->fullUrl(),
];

return new Response(view('actions.feed.links', [
'meta' => $meta,
'links' => $links,
]), 200, ['Content-Type' => 'application/xml']);
}
}
4 changes: 4 additions & 0 deletions app/Http/Controllers/App/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public function getSearch(): View
'search_description' => true,
'private_only' => false,
'broken_only' => false,
'empty_tags' => false,
'empty_lists' => false,
'only_lists' => '',
'only_tags' => '',
'order_by' => $this->orderByOptions[0],
Expand Down Expand Up @@ -55,6 +57,8 @@ public function doSearch(SearchRequest $request): View
'broken_only' => $this->searchBrokenOnly,
'only_lists' => $this->searchLists,
'only_tags' => $this->searchTags,
'empty_tags' => $this->emptyTags,
'empty_lists' => $this->emptyLists,
'order_by' => $this->searchOrderBy,
]);
}
Expand Down
95 changes: 95 additions & 0 deletions app/Http/Controllers/Guest/FeedController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

namespace App\Http\Controllers\Guest;

use App\Http\Controllers\Controller;
use App\Models\Link;
use App\Models\LinkList;
use App\Models\Tag;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class FeedController extends Controller
{
public function links(Request $request): Response
{
$links = Link::publicOnly()->latest()->with('user')->get();
$meta = [
'title' => 'LinkAce Links',
'link' => $request->fullUrl(),
'updated' => now()->toRfc3339String(),
'id' => $request->fullUrl(),
];

return new Response(view('actions.feed.links', [
'meta' => $meta,
'links' => $links,
]), 200, ['Content-Type' => 'application/xml']);
}

public function lists(Request $request): Response
{
$lists = LinkList::publicOnly()->latest()->with('user')->get();
$meta = [
'title' => 'LinkAce Lists',
'link' => $request->fullUrl(),
'updated' => now()->toRfc3339String(),
'id' => $request->fullUrl(),
];

return new Response(view('actions.feed.lists', [
'meta' => $meta,
'lists' => $lists,
]), 200, ['Content-Type' => 'application/xml']);
}

public function listLinks(Request $request, $listID): Response
{
$list = LinkList::publicOnly()->findOrFail($listID);
$links = $list->links()->publicOnly()->latest()->with('user')->get();
$meta = [
'title' => $list->name,
'link' => $request->fullUrl(),
'updated' => now()->toRfc3339String(),
'id' => $request->fullUrl(),
];

return new Response(view('actions.feed.links', [
'meta' => $meta,
'links' => $links,
]), 200, ['Content-Type' => 'application/xml']);
}

public function tags(Request $request): Response
{
$tags = Tag::publicOnly()->latest()->with('user')->get();
$meta = [
'title' => 'LinkAce Links',
'link' => $request->fullUrl(),
'updated' => now()->toRfc3339String(),
'id' => $request->fullUrl(),
];

return new Response(view('actions.feed.tags', [
'meta' => $meta,
'tags' => $tags,
]), 200, ['Content-Type' => 'application/xml']);
}

public function tagLinks(Request $request, $tagID): Response
{
$tag = Tag::publicOnly()->findOrFail($tagID);
$links = $tag->links()->publicOnly()->latest()->with('user')->get();
$meta = [
'title' => $tag->name,
'link' => $request->fullUrl(),
'updated' => now()->toRfc3339String(),
'id' => $request->fullUrl(),
];

return new Response(view('actions.feed.links', [
'meta' => $meta,
'links' => $links,
]), 200, ['Content-Type' => 'application/xml']);
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Guest/LinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class LinkController extends Controller
*/
public function index(Request $request): View
{
$links = Link::privateOnly(false)
$links = Link::publicOnly()
->with('tags')
->orderBy(
$request->input('orderBy', 'created_at'),
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Guest/ListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ListController extends Controller
*/
public function index(Request $request): View
{
$lists = LinkList::isPrivate(false)
$lists = LinkList::publicOnly()
->withCount('links')
->orderBy(
$request->input('orderBy', 'name'),
Expand All @@ -41,10 +41,10 @@ public function index(Request $request): View
*/
public function show(Request $request, $listID): View
{
$list = LinkList::isPrivate(false)->findOrFail($listID);
$list = LinkList::publicOnly()->findOrFail($listID);

$links = $list->links()
->privateOnly(false)
->publicOnly()
->orderBy(
$request->input('orderBy', 'title'),
$request->input('orderDir', 'asc')
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Guest/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TagController extends Controller
*/
public function index(Request $request): View
{
$tags = Tag::isPrivate(false)
$tags = Tag::publicOnly()
->withCount('links')
->orderBy(
$request->input('orderBy', 'name'),
Expand All @@ -42,10 +42,10 @@ public function index(Request $request): View
*/
public function show(Request $request, $tagID): View
{
$tag = Tag::isPrivate(false)->findOrFail($tagID);
$tag = Tag::publicOnly()->findOrFail($tagID);

$links = $tag->links()
->privateOnly(false)
->privateOnly()
->orderBy(
$request->input('orderBy', 'title'),
$request->input('orderDir', 'ASC')
Expand Down
14 changes: 14 additions & 0 deletions app/Http/Controllers/Models/LinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,18 @@ public function updateCheckToggle(LinkToggleCheckRequest $request, Link $link):

return redirect()->route('links.show', [$link->id]);
}

/**
* Mark the link as working manually.
*
* @param Link $link
* @return RedirectResponse
*/
public function markWorking(Link $link): RedirectResponse
{
$link->status = Link::STATUS_OK;
$link->save();

return redirect()->route('links.show', [$link->id]);
}
}
30 changes: 19 additions & 11 deletions app/Http/Controllers/Traits/SearchesLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ trait SearchesLinks
protected $searchBrokenOnly;
protected $searchLists;
protected $searchTags;
protected $emptyLists;
protected $emptyTags;
protected $searchOrderBy;

/** @var array */
Expand Down Expand Up @@ -42,17 +44,19 @@ protected function buildDatabaseQuery(SearchRequest $request)
// Search for the URL
if ($this->searchQuery = $request->input('query', false)) {
$query = '%' . escapeSearchQuery($this->searchQuery) . '%';
$search->where('url', 'like', $query);
$search->where(function ($search) use ($request, $query) {
$search->where('url', 'like', $query);

// Also search for the title if applicable
if ($this->searchTitle = $request->input('search_title', false)) {
$search->orWhere('title', 'like', $query);
}
// Also search for the title if applicable
if ($this->searchTitle = $request->input('search_title', false)) {
$search->orWhere('title', 'like', $query);
}

// Also search for the title if applicable
if ($this->searchDescription = $request->input('search_description', false)) {
$search->orWhere('description', 'like', $query);
}
// Also search for the title if applicable
if ($this->searchDescription = $request->input('search_description', false)) {
$search->orWhere('description', 'like', $query);
}
});
}

// Show private only if applicable
Expand All @@ -66,15 +70,19 @@ protected function buildDatabaseQuery(SearchRequest $request)
}

// Show by specific list only if applicable
if ($this->searchLists = $request->input('only_lists', false)) {
if ($this->emptyLists = $request->input('empty_lists', false)) {
$search->doesntHave('lists');
} elseif ($this->searchLists = $request->input('only_lists', false)) {
$search->whereHas('lists', function ($query) use ($request) {
$field = $request->isJson() ? 'id' : 'name';
$query->whereIn($field, explode(',', $this->searchLists));
});
}

// Show by specific tag only if applicable
if ($this->searchTags = $request->input('only_tags', false)) {
if ($this->emptyTags = $request->input('empty_tags', false)) {
$search->doesntHave('tags');
} elseif ($this->searchTags = $request->input('only_tags', false)) {
$search->whereHas('tags', function ($query) use ($request) {
$field = $request->isJson() ? 'id' : 'name';
$query->whereIn($field, explode(',', $this->searchTags));
Expand Down
Loading

0 comments on commit 31dc29a

Please sign in to comment.