|
1
|
|
|
<?php namespace Arcanedev\SeoHelper; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanedev\SeoHelper\Contracts\SeoHelper as SeoHelperContract; |
|
4
|
|
|
use Arcanedev\SeoHelper\Contracts\SeoMeta as SeoMetaContract; |
|
5
|
|
|
use Arcanedev\SeoHelper\Contracts\SeoOpenGraph as SeoOpenGraphContract; |
|
6
|
|
|
use Arcanedev\SeoHelper\Contracts\SeoTwitter as SeoTwitterContract; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class SeoHelper |
|
10
|
|
|
* |
|
11
|
|
|
* @package Arcanedev\SeoHelper |
|
12
|
|
|
* @author ARCANEDEV <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
class SeoHelper implements SeoHelperContract |
|
15
|
|
|
{ |
|
16
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
17
|
|
|
| Properties |
|
18
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
19
|
|
|
*/ |
|
20
|
|
|
/** |
|
21
|
|
|
* The SeoMeta instance. |
|
22
|
|
|
* |
|
23
|
|
|
* @var \Arcanedev\SeoHelper\Contracts\SeoMeta |
|
24
|
|
|
*/ |
|
25
|
|
|
private $seoMeta; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* The SeoOpenGraph instance. |
|
29
|
|
|
* |
|
30
|
|
|
* @var \Arcanedev\SeoHelper\Contracts\SeoOpenGraph |
|
31
|
|
|
*/ |
|
32
|
|
|
private $seoOpenGraph; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* The SeoTwitter instance. |
|
36
|
|
|
* |
|
37
|
|
|
* @var \Arcanedev\SeoHelper\Contracts\SeoTwitter |
|
38
|
|
|
*/ |
|
39
|
|
|
private $seoTwitter; |
|
40
|
|
|
|
|
41
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
42
|
|
|
| Constructor |
|
43
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
44
|
|
|
*/ |
|
45
|
|
|
/** |
|
46
|
|
|
* Make SeoHelper instance. |
|
47
|
|
|
* |
|
48
|
|
|
* @param \Arcanedev\SeoHelper\Contracts\SeoMeta $seoMeta |
|
49
|
|
|
* @param \Arcanedev\SeoHelper\Contracts\SeoOpenGraph $seoOpenGraph |
|
50
|
|
|
* @param \Arcanedev\SeoHelper\Contracts\SeoTwitter $seoTwitter |
|
51
|
|
|
*/ |
|
52
|
171 |
|
public function __construct( |
|
53
|
|
|
SeoMetaContract $seoMeta, |
|
54
|
|
|
SeoOpenGraphContract $seoOpenGraph, |
|
55
|
|
|
SeoTwitterContract $seoTwitter |
|
56
|
|
|
) { |
|
57
|
171 |
|
$this->setSeoMeta($seoMeta); |
|
58
|
171 |
|
$this->setSeoOpenGraph($seoOpenGraph); |
|
59
|
171 |
|
$this->setSeoTwitter($seoTwitter); |
|
60
|
171 |
|
} |
|
61
|
|
|
|
|
62
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
63
|
|
|
| Getters & Setters |
|
64
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
65
|
|
|
*/ |
|
66
|
|
|
/** |
|
67
|
|
|
* Get SeoMeta instance. |
|
68
|
|
|
* |
|
69
|
|
|
* @return \Arcanedev\SeoHelper\Contracts\SeoMeta |
|
70
|
|
|
*/ |
|
71
|
117 |
|
public function meta() |
|
72
|
|
|
{ |
|
73
|
117 |
|
return $this->seoMeta; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Set SeoMeta instance. |
|
78
|
|
|
* |
|
79
|
|
|
* @param \Arcanedev\SeoHelper\Contracts\SeoMeta $seoMeta |
|
80
|
|
|
* |
|
81
|
|
|
* @return \Arcanedev\SeoHelper\SeoHelper |
|
82
|
|
|
*/ |
|
83
|
171 |
|
public function setSeoMeta(SeoMetaContract $seoMeta) |
|
84
|
|
|
{ |
|
85
|
171 |
|
$this->seoMeta = $seoMeta; |
|
86
|
|
|
|
|
87
|
171 |
|
return $this; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Get SeoOpenGraph instance. |
|
92
|
|
|
* |
|
93
|
|
|
* @return \Arcanedev\SeoHelper\Contracts\SeoOpenGraph |
|
94
|
|
|
*/ |
|
95
|
117 |
|
public function openGraph() |
|
96
|
|
|
{ |
|
97
|
117 |
|
return $this->seoOpenGraph; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Get SeoOpenGraph instance (alias). |
|
102
|
|
|
* |
|
103
|
|
|
* @see openGraph() |
|
104
|
|
|
* |
|
105
|
|
|
* @return \Arcanedev\SeoHelper\Contracts\SeoOpenGraph |
|
106
|
|
|
*/ |
|
107
|
9 |
|
public function og() |
|
108
|
|
|
{ |
|
109
|
9 |
|
return $this->openGraph(); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Get SeoOpenGraph instance. |
|
114
|
|
|
* |
|
115
|
|
|
* @param \Arcanedev\SeoHelper\Contracts\SeoOpenGraph $seoOpenGraph |
|
116
|
|
|
* |
|
117
|
|
|
* @return \Arcanedev\SeoHelper\SeoHelper |
|
118
|
|
|
*/ |
|
119
|
171 |
|
public function setSeoOpenGraph(SeoOpenGraphContract $seoOpenGraph) |
|
120
|
|
|
{ |
|
121
|
171 |
|
$this->seoOpenGraph = $seoOpenGraph; |
|
122
|
|
|
|
|
123
|
171 |
|
return $this; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Get SeoTwitter instance. |
|
128
|
|
|
* |
|
129
|
|
|
* @return \Arcanedev\SeoHelper\Contracts\SeoTwitter |
|
130
|
|
|
*/ |
|
131
|
108 |
|
public function twitter() |
|
132
|
|
|
{ |
|
133
|
108 |
|
return $this->seoTwitter; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Set SeoTwitter instance. |
|
138
|
|
|
* |
|
139
|
|
|
* @param \Arcanedev\SeoHelper\Contracts\SeoTwitter $seoTwitter |
|
140
|
|
|
* |
|
141
|
|
|
* @return \Arcanedev\SeoHelper\SeoHelper |
|
142
|
|
|
*/ |
|
143
|
171 |
|
public function setSeoTwitter(SeoTwitterContract $seoTwitter) |
|
144
|
|
|
{ |
|
145
|
171 |
|
$this->seoTwitter = $seoTwitter; |
|
146
|
|
|
|
|
147
|
171 |
|
return $this; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Set title. |
|
152
|
|
|
* |
|
153
|
|
|
* @param string $title |
|
154
|
|
|
* @param string|null $siteName |
|
155
|
|
|
* @param string|null $separator |
|
156
|
|
|
* |
|
157
|
|
|
* @return \Arcanedev\SeoHelper\SeoHelper |
|
158
|
|
|
*/ |
|
159
|
27 |
|
public function setTitle($title, $siteName = null, $separator = null) |
|
160
|
|
|
{ |
|
161
|
27 |
|
$this->meta()->setTitle($title, null, $separator); |
|
162
|
27 |
|
$this->openGraph()->setTitle($title); |
|
163
|
27 |
|
$this->twitter()->setTitle($title); |
|
164
|
|
|
|
|
165
|
27 |
|
return $this->setSiteName($siteName); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Set the site name. |
|
170
|
|
|
* |
|
171
|
|
|
* @param string $siteName |
|
172
|
|
|
* |
|
173
|
|
|
* @return self |
|
174
|
|
|
*/ |
|
175
|
27 |
|
public function setSiteName($siteName) |
|
176
|
|
|
{ |
|
177
|
27 |
|
$this->meta()->setSiteName($siteName); |
|
178
|
27 |
|
$this->openGraph()->setSiteName($siteName); |
|
179
|
|
|
|
|
180
|
27 |
|
return $this; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Set description. |
|
185
|
|
|
* |
|
186
|
|
|
* @param string $description |
|
187
|
|
|
* |
|
188
|
|
|
* @return \Arcanedev\SeoHelper\Contracts\SeoHelper |
|
189
|
|
|
*/ |
|
190
|
18 |
|
public function setDescription($description) |
|
191
|
|
|
{ |
|
192
|
18 |
|
$this->meta()->setDescription($description); |
|
193
|
18 |
|
$this->openGraph()->setDescription($description); |
|
194
|
18 |
|
$this->twitter()->setDescription($description); |
|
195
|
|
|
|
|
196
|
18 |
|
return $this; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* Set keywords. |
|
201
|
|
|
* |
|
202
|
|
|
* @param array|string $keywords |
|
203
|
|
|
* |
|
204
|
|
|
* @return \Arcanedev\SeoHelper\SeoHelper |
|
205
|
|
|
*/ |
|
206
|
18 |
|
public function setKeywords($keywords) |
|
207
|
|
|
{ |
|
208
|
18 |
|
$this->meta()->setKeywords($keywords); |
|
209
|
|
|
|
|
210
|
18 |
|
return $this; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
214
|
|
|
| Main Functions |
|
215
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
216
|
|
|
*/ |
|
217
|
|
|
/** |
|
218
|
|
|
* Render all seo tags. |
|
219
|
|
|
* |
|
220
|
|
|
* @return string |
|
221
|
|
|
*/ |
|
222
|
99 |
|
public function render() |
|
223
|
|
|
{ |
|
224
|
99 |
|
return implode(PHP_EOL, array_filter([ |
|
225
|
99 |
|
$this->meta()->render(), |
|
226
|
99 |
|
$this->openGraph()->render(), |
|
227
|
99 |
|
$this->twitter()->render(), |
|
228
|
33 |
|
])); |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* Render all seo tags with HtmlString object. |
|
233
|
|
|
* |
|
234
|
|
|
* @return \Illuminate\Support\HtmlString |
|
235
|
|
|
*/ |
|
236
|
9 |
|
public function renderHtml() |
|
237
|
|
|
{ |
|
238
|
9 |
|
return new \Illuminate\Support\HtmlString( |
|
239
|
9 |
|
$this->render() |
|
240
|
3 |
|
); |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
/** |
|
244
|
|
|
* Render the tag. |
|
245
|
|
|
* |
|
246
|
|
|
* @return string |
|
247
|
|
|
*/ |
|
248
|
63 |
|
public function __toString() |
|
249
|
|
|
{ |
|
250
|
63 |
|
return $this->render(); |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* Enable the OpenGraph. |
|
255
|
|
|
* |
|
256
|
|
|
* @return \Arcanedev\SeoHelper\SeoHelper |
|
257
|
|
|
*/ |
|
258
|
9 |
|
public function enableOpenGraph() |
|
259
|
|
|
{ |
|
260
|
9 |
|
$this->openGraph()->enable(); |
|
261
|
|
|
|
|
262
|
9 |
|
return $this; |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
/** |
|
266
|
|
|
* Disable the OpenGraph. |
|
267
|
|
|
* |
|
268
|
|
|
* @return \Arcanedev\SeoHelper\SeoHelper |
|
269
|
|
|
*/ |
|
270
|
9 |
|
public function disableOpenGraph() |
|
271
|
|
|
{ |
|
272
|
9 |
|
$this->openGraph()->disable(); |
|
273
|
|
|
|
|
274
|
9 |
|
return $this; |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
/** |
|
278
|
|
|
* Enable the Twitter Card. |
|
279
|
|
|
* |
|
280
|
|
|
* @return \Arcanedev\SeoHelper\SeoHelper |
|
281
|
|
|
*/ |
|
282
|
9 |
|
public function enableTwitter() |
|
283
|
|
|
{ |
|
284
|
9 |
|
$this->twitter()->enable(); |
|
285
|
|
|
|
|
286
|
9 |
|
return $this; |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
/** |
|
290
|
|
|
* Disable the Twitter Card. |
|
291
|
|
|
* |
|
292
|
|
|
* @return \Arcanedev\SeoHelper\SeoHelper |
|
293
|
|
|
*/ |
|
294
|
9 |
|
public function disableTwitter() |
|
295
|
|
|
{ |
|
296
|
9 |
|
$this->twitter()->disable(); |
|
297
|
|
|
|
|
298
|
9 |
|
return $this; |
|
299
|
|
|
} |
|
300
|
|
|
} |
|
301
|
|
|
|