1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AdDirector\GPT; |
4
|
|
|
|
5
|
|
|
use AdDirector\Core\AdManager; |
6
|
|
|
use AdDirector\Core\HasVendorScripts; |
7
|
|
|
use AdDirector\RenderMinifier; |
8
|
|
|
use Illuminate\Support\Facades\View; |
9
|
|
|
|
10
|
|
|
class AdGPT extends AdManager |
11
|
|
|
{ |
12
|
|
|
use HasVendorScripts, HasGlobalSizes; |
13
|
|
|
|
14
|
|
|
protected array $locations = []; |
15
|
|
|
|
16
|
|
|
protected ?Presenter $presenter = null; |
17
|
|
|
|
18
|
4 |
|
public function configurationScript(bool $minify = true): string |
19
|
|
|
{ |
20
|
4 |
|
$view = View::make('ad-director::gpt.configuration-scripts', [ |
21
|
4 |
|
'adPresenter' => $this->presenter(), |
22
|
4 |
|
])->render(); |
23
|
|
|
|
24
|
4 |
|
return $minify ? RenderMinifier::minify($view) : $view; |
25
|
|
|
} |
26
|
|
|
|
27
|
4 |
|
public function displayScript(bool $minify = true): string |
28
|
|
|
{ |
29
|
4 |
|
$view = View::make('ad-director::gpt.display-scripts', [ |
30
|
4 |
|
'adPresenter' => $this->presenter(), |
31
|
4 |
|
])->render(); |
32
|
|
|
|
33
|
4 |
|
return $minify ? RenderMinifier::minify($view) : $view; |
34
|
|
|
} |
35
|
|
|
|
36
|
5 |
|
public function adLocation(string $name, bool $minify = true): string |
37
|
|
|
{ |
38
|
5 |
|
$view = $this->presenter()->adLocation($name); |
39
|
|
|
|
40
|
5 |
|
return $minify ? RenderMinifier::minify($view) : $view; |
41
|
|
|
} |
42
|
|
|
|
43
|
5 |
|
protected function presenter(bool $rebuild = false): Presenter |
44
|
|
|
{ |
45
|
5 |
|
if ($rebuild || !$this->presenter) { |
46
|
5 |
|
$this->presenter = new Presenter($this); |
47
|
|
|
} |
48
|
|
|
|
49
|
5 |
|
return $this->presenter; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param \AdDirector\GPT\Slot $slot |
54
|
|
|
* @param string|null $name If name is null than ad unit will be used. |
55
|
|
|
* |
56
|
|
|
* @return static |
57
|
|
|
*/ |
58
|
4 |
|
public function addLocation(Slot $slot, ?string $name = null): static |
59
|
|
|
{ |
60
|
4 |
|
if (is_null($name)) { |
61
|
1 |
|
$name = $slot->adUnitPath(); |
62
|
|
|
} |
63
|
|
|
|
64
|
4 |
|
$this->locations[$name] = $slot; |
65
|
|
|
|
66
|
4 |
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
5 |
|
public function locations(): array |
70
|
|
|
{ |
71
|
5 |
|
return $this->locations; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|