-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #859 from owlchester/refactor/remove-blade-macros
Remove blade macros
- Loading branch information
Showing
30 changed files
with
268 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace App\View\Components; | ||
|
||
use App\Models\Campaign; | ||
use App\User; | ||
use Carbon\Carbon; | ||
use Closure; | ||
use Illuminate\Contracts\View\View; | ||
use Illuminate\View\Component; | ||
|
||
class Ad extends Component | ||
{ | ||
public ?string $section; | ||
public ?Campaign $campaign; | ||
protected User $user; | ||
|
||
/** | ||
* Create a new component instance. | ||
*/ | ||
public function __construct( | ||
string $section = null, | ||
Campaign $campaign = null, | ||
) { | ||
$this->section = $section; | ||
$this->campaign = $campaign; | ||
} | ||
|
||
/** | ||
* Get the view / contents that represent the component. | ||
*/ | ||
public function render(): View|Closure|string | ||
{ | ||
if (auth()->check()) { | ||
$this->user = auth()->user(); | ||
} | ||
if (!$this->hasAd()) { | ||
return ''; | ||
} | ||
return view('components.ad'); | ||
} | ||
|
||
/** | ||
* Determine if ads should be displayed | ||
*/ | ||
protected function hasAd(): bool | ||
{ | ||
// If we don't have venatus enabled, then we don't have any ads to show | ||
if (!config('tracking.venatus.enabled')) { | ||
return false; | ||
} | ||
|
||
// If requesting a section that isn't set up, don't show | ||
if (!empty($this->section) && empty(config('tracking.venatus.' . $this->section))) { | ||
return false; | ||
} | ||
// Parameter to force ads to be displayed | ||
if (request()->has('_showads')) { | ||
return true; | ||
} | ||
if (isset($this->user)) { | ||
// Subscribed users don't have ads | ||
if ($this->user->isSubscriber()) { | ||
return false; | ||
} | ||
// User has been created less than 24 hours ago | ||
if ($this->user->created_at->diffInHours(Carbon::now()) < 24) { | ||
return false; | ||
} | ||
} | ||
|
||
// Premium campaigns don't have ads displayed to their members | ||
return !empty($this->campaign) && !$this->campaign->boosted(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace App\View\Components\Ads; | ||
|
||
use App\Facades\AdCache; | ||
use App\Models\Ad; | ||
use App\Models\Campaign; | ||
use App\User; | ||
use Carbon\Carbon; | ||
use Closure; | ||
use Illuminate\Contracts\View\View; | ||
use Illuminate\View\Component; | ||
|
||
class Native extends Component | ||
{ | ||
public int $section; | ||
public Campaign $campaign; | ||
public User $user; | ||
public Ad $ad; | ||
|
||
/** | ||
* Create a new component instance. | ||
*/ | ||
public function __construct( | ||
int $section, | ||
Campaign $campaign = null, | ||
) { | ||
$this->section = $section; | ||
if ($campaign) { | ||
$this->campaign = $campaign; | ||
} | ||
if (auth()->check()) { | ||
$this->user = auth()->user(); | ||
} | ||
} | ||
|
||
/** | ||
* Get the view / contents that represent the component. | ||
*/ | ||
public function render(): View|Closure|string | ||
{ | ||
if (!$this->noAds()) { | ||
return ''; | ||
} | ||
$this->ad = AdCache::get(); | ||
return view('components.ads.native'); | ||
} | ||
|
||
protected function noAds(): bool | ||
{ | ||
// No admin panel set up, no ads possible, since the admin project provides the tables | ||
if (!config('app.admin')) { | ||
return false; | ||
} | ||
// If we provided an ad test, override that | ||
if (request()->has('_adtest') && auth()->user()->hasRole('admin')) { | ||
return AdCache::test($this->section, request()->get('_adtest')); | ||
} | ||
// If the section has no ads, don't try and show anything | ||
if (!AdCache::has($this->section)) { | ||
return false; | ||
} | ||
// Force ads displayed | ||
if (request()->get('_boost') === '0') { | ||
return true; | ||
} | ||
|
||
if (isset($this->user)) { | ||
// Subscribed users don't have ads | ||
if ($this->user->isSubscriber()) { | ||
return false; | ||
} | ||
// User has been created less than 24 hours ago | ||
if ($this->user->created_at->diffInHours(Carbon::now()) < 24) { | ||
return false; | ||
} | ||
} | ||
|
||
// Premium campaigns don't either have ads displayed to their members | ||
return isset($this->campaign) && !$this->campaign->boosted(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.