|
1
|
|
|
<?php namespace Arcanedev\SeoHelper; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanedev\SeoHelper\Contracts\Entities\OpenGraphInterface; |
|
4
|
|
|
use Arcanedev\Support\Traits\Configurable; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Class SeoOpenGraph |
|
8
|
|
|
* |
|
9
|
|
|
* @package Arcanedev\SeoHelper |
|
10
|
|
|
* @author ARCANEDEV <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
class SeoOpenGraph implements Contracts\SeoOpenGraph |
|
13
|
|
|
{ |
|
14
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
15
|
|
|
| Traits |
|
16
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
17
|
|
|
*/ |
|
18
|
|
|
use Configurable; |
|
19
|
|
|
|
|
20
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
21
|
|
|
| Properties |
|
22
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
23
|
|
|
*/ |
|
24
|
|
|
/** |
|
25
|
|
|
* Enable or Disable the OpenGraph. |
|
26
|
|
|
* |
|
27
|
|
|
* @var bool |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $enabled; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* The Open Graph instance. |
|
33
|
|
|
* |
|
34
|
|
|
* @var OpenGraphInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $openGraph; |
|
37
|
|
|
|
|
38
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
39
|
|
|
| Constructor |
|
40
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
41
|
|
|
*/ |
|
42
|
|
|
/** |
|
43
|
|
|
* Make SeoOpenGraph instance. |
|
44
|
|
|
* |
|
45
|
|
|
* @param array $configs |
|
46
|
|
|
*/ |
|
47
|
87 |
|
public function __construct(array $configs) |
|
48
|
|
|
{ |
|
49
|
87 |
|
$this->setConfigs($configs); |
|
50
|
|
|
|
|
51
|
87 |
|
$this->setEnabled($this->getConfig('open-graph.enabled', false)); |
|
52
|
87 |
|
$this->setOpenGraph( |
|
53
|
87 |
|
new Entities\OpenGraph\Graph($this->getConfig('open-graph', [])) |
|
54
|
87 |
|
); |
|
55
|
87 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
58
|
|
|
| Getters & Setters |
|
59
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
60
|
|
|
*/ |
|
61
|
|
|
/** |
|
62
|
|
|
* Set the enabled status for the OpenGraph. |
|
63
|
|
|
* |
|
64
|
|
|
* @param bool $enabled |
|
65
|
|
|
* |
|
66
|
|
|
* @return self |
|
67
|
|
|
*/ |
|
68
|
87 |
|
private function setEnabled($enabled) |
|
69
|
|
|
{ |
|
70
|
87 |
|
$this->enabled = $enabled; |
|
71
|
|
|
|
|
72
|
87 |
|
return $this; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Set the Open Graph instance. |
|
77
|
|
|
* |
|
78
|
|
|
* @param OpenGraphInterface $openGraph |
|
79
|
|
|
* |
|
80
|
|
|
* @return self |
|
81
|
|
|
*/ |
|
82
|
87 |
|
public function setOpenGraph(OpenGraphInterface $openGraph) |
|
83
|
|
|
{ |
|
84
|
87 |
|
$this->openGraph = $openGraph; |
|
85
|
|
|
|
|
86
|
87 |
|
return $this; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Set the open graph prefix. |
|
91
|
|
|
* |
|
92
|
|
|
* @param string $prefix |
|
93
|
|
|
* |
|
94
|
|
|
* @return self |
|
95
|
|
|
*/ |
|
96
|
3 |
|
public function setPrefix($prefix) |
|
97
|
|
|
{ |
|
98
|
3 |
|
$this->openGraph->setPrefix($prefix); |
|
99
|
|
|
|
|
100
|
3 |
|
return $this; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Set type property. |
|
105
|
|
|
* |
|
106
|
|
|
* @param string $type |
|
107
|
|
|
* |
|
108
|
|
|
* @return self |
|
109
|
|
|
*/ |
|
110
|
3 |
|
public function setType($type) |
|
111
|
|
|
{ |
|
112
|
3 |
|
$this->openGraph->setType($type); |
|
113
|
|
|
|
|
114
|
3 |
|
return $this; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Set title property. |
|
119
|
|
|
* |
|
120
|
|
|
* @param string $title |
|
121
|
|
|
* |
|
122
|
|
|
* @return self |
|
123
|
|
|
*/ |
|
124
|
9 |
|
public function setTitle($title) |
|
125
|
|
|
{ |
|
126
|
9 |
|
$this->openGraph->setTitle($title); |
|
127
|
|
|
|
|
128
|
9 |
|
return $this; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Set description property. |
|
133
|
|
|
* |
|
134
|
|
|
* @param string $description |
|
135
|
|
|
* |
|
136
|
|
|
* @return self |
|
137
|
|
|
*/ |
|
138
|
9 |
|
public function setDescription($description) |
|
139
|
|
|
{ |
|
140
|
9 |
|
$this->openGraph->setDescription($description); |
|
141
|
|
|
|
|
142
|
9 |
|
return $this; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Set url property. |
|
147
|
|
|
* |
|
148
|
|
|
* @param string $url |
|
149
|
|
|
* |
|
150
|
|
|
* @return self |
|
151
|
|
|
*/ |
|
152
|
3 |
|
public function setUrl($url) |
|
153
|
|
|
{ |
|
154
|
3 |
|
$this->openGraph->setUrl($url); |
|
155
|
|
|
|
|
156
|
3 |
|
return $this; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Set image property. |
|
161
|
|
|
* |
|
162
|
|
|
* @param string $image |
|
163
|
|
|
* |
|
164
|
|
|
* @return self |
|
165
|
|
|
*/ |
|
166
|
3 |
|
public function setImage($image) |
|
167
|
|
|
{ |
|
168
|
3 |
|
$this->openGraph->setImage($image); |
|
169
|
|
|
|
|
170
|
3 |
|
return $this; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Set site name property. |
|
175
|
|
|
* |
|
176
|
|
|
* @param string $siteName |
|
177
|
|
|
* |
|
178
|
|
|
* @return self |
|
179
|
|
|
*/ |
|
180
|
9 |
|
public function setSiteName($siteName) |
|
181
|
|
|
{ |
|
182
|
9 |
|
$this->openGraph->setSiteName($siteName); |
|
183
|
|
|
|
|
184
|
9 |
|
return $this; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Add many open graph properties. |
|
189
|
|
|
* |
|
190
|
|
|
* @param array $properties |
|
191
|
|
|
* |
|
192
|
|
|
* @return self |
|
193
|
|
|
*/ |
|
194
|
3 |
|
public function addProperties(array $properties) |
|
195
|
|
|
{ |
|
196
|
3 |
|
$this->openGraph->addProperties($properties); |
|
197
|
|
|
|
|
198
|
3 |
|
return $this; |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* Add an open graph property. |
|
203
|
|
|
* |
|
204
|
|
|
* @param string $property |
|
205
|
|
|
* @param string $content |
|
206
|
|
|
* |
|
207
|
|
|
* @return self |
|
208
|
|
|
*/ |
|
209
|
3 |
|
public function addProperty($property, $content) |
|
210
|
|
|
{ |
|
211
|
3 |
|
$this->openGraph->addProperty($property, $content); |
|
212
|
|
|
|
|
213
|
3 |
|
return $this; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
217
|
|
|
| Main Functions |
|
218
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
219
|
|
|
*/ |
|
220
|
|
|
/** |
|
221
|
|
|
* Render the tag. |
|
222
|
|
|
* |
|
223
|
|
|
* @return string |
|
224
|
|
|
*/ |
|
225
|
60 |
|
public function render() |
|
226
|
|
|
{ |
|
227
|
60 |
|
if ($this->isEnabled()) { |
|
228
|
60 |
|
return $this->openGraph->render(); |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
6 |
|
return ''; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* Render the tag. |
|
236
|
|
|
* |
|
237
|
|
|
* @return string |
|
238
|
|
|
*/ |
|
239
|
30 |
|
public function __toString() |
|
240
|
|
|
{ |
|
241
|
30 |
|
return $this->render(); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* Enable the OpenGraph. |
|
246
|
|
|
* |
|
247
|
|
|
* @return self |
|
248
|
|
|
*/ |
|
249
|
6 |
|
public function enable() |
|
250
|
|
|
{ |
|
251
|
6 |
|
return $this->setEnabled(true); |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
/** |
|
255
|
|
|
* Disable the OpenGraph. |
|
256
|
|
|
* |
|
257
|
|
|
* @return self |
|
258
|
|
|
*/ |
|
259
|
6 |
|
public function disable() |
|
260
|
|
|
{ |
|
261
|
6 |
|
return $this->setEnabled(false); |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
265
|
|
|
| Check Function |
|
266
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
267
|
|
|
*/ |
|
268
|
|
|
/** |
|
269
|
|
|
* Check if the OpenGraph is enabled. |
|
270
|
|
|
* |
|
271
|
|
|
* @return bool |
|
272
|
|
|
*/ |
|
273
|
60 |
|
public function isEnabled() |
|
274
|
|
|
{ |
|
275
|
60 |
|
return $this->enabled; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* Check if the OpenGraph is disabled. |
|
280
|
|
|
* |
|
281
|
|
|
* @return bool |
|
282
|
|
|
*/ |
|
283
|
6 |
|
public function isDisabled() |
|
284
|
|
|
{ |
|
285
|
6 |
|
return ! $this->isEnabled(); |
|
286
|
|
|
} |
|
287
|
|
|
} |
|
288
|
|
|
|