1
|
|
|
<?php namespace Arcanedev\SeoHelper\Entities\OpenGraph; |
2
|
|
|
|
3
|
|
|
use Arcanedev\SeoHelper\Contracts\Entities\OpenGraph as OpenGraphContract; |
4
|
|
|
use Arcanedev\Support\Traits\Configurable; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class Graph |
8
|
|
|
* |
9
|
|
|
* @package Arcanedev\SeoHelper\Entities\OpenGraph |
10
|
|
|
* @author ARCANEDEV <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class Graph implements OpenGraphContract |
13
|
|
|
{ |
14
|
|
|
/* ------------------------------------------------------------------------------------------------ |
15
|
|
|
| Traits |
16
|
|
|
| ------------------------------------------------------------------------------------------------ |
17
|
|
|
*/ |
18
|
|
|
use Configurable; |
19
|
|
|
|
20
|
|
|
/* ------------------------------------------------------------------------------------------------ |
21
|
|
|
| Properties |
22
|
|
|
| ------------------------------------------------------------------------------------------------ |
23
|
|
|
*/ |
24
|
|
|
/** |
25
|
|
|
* The Open Graph meta collection. |
26
|
|
|
* |
27
|
|
|
* @var \Arcanedev\SeoHelper\Contracts\Entities\MetaCollection |
28
|
|
|
*/ |
29
|
|
|
protected $metas; |
30
|
|
|
|
31
|
|
|
/* ------------------------------------------------------------------------------------------------ |
32
|
|
|
| Constructor |
33
|
|
|
| ------------------------------------------------------------------------------------------------ |
34
|
|
|
*/ |
35
|
|
|
/** |
36
|
|
|
* Make Graph instance. |
37
|
|
|
* |
38
|
|
|
* @param array $configs |
39
|
|
|
*/ |
40
|
320 |
|
public function __construct(array $configs = []) |
41
|
|
|
{ |
42
|
320 |
|
$this->setConfigs($configs); |
43
|
320 |
|
$this->metas = new MetaCollection; |
44
|
|
|
|
45
|
320 |
|
$this->init(); |
46
|
320 |
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Start the engine. |
50
|
|
|
*/ |
51
|
320 |
|
private function init() |
52
|
|
|
{ |
53
|
320 |
|
$this->setPrefix($this->getConfig('prefix', 'og:')); |
54
|
320 |
|
$this->setType($this->getConfig('type', '')); |
55
|
320 |
|
$this->setTitle($this->getConfig('title', '')); |
56
|
320 |
|
$this->setDescription($this->getConfig('description', '')); |
57
|
320 |
|
$this->setSiteName($this->getConfig('site-name', '')); |
58
|
320 |
|
$this->addProperties($this->getConfig('properties', [])); |
59
|
320 |
|
} |
60
|
|
|
|
61
|
|
|
/* ------------------------------------------------------------------------------------------------ |
62
|
|
|
| Properties |
63
|
|
|
| ------------------------------------------------------------------------------------------------ |
64
|
|
|
*/ |
65
|
|
|
/** |
66
|
|
|
* Set the open graph prefix. |
67
|
|
|
* |
68
|
|
|
* @param string $prefix |
69
|
|
|
* |
70
|
|
|
* @return \Arcanedev\SeoHelper\Entities\OpenGraph\Graph |
71
|
|
|
*/ |
72
|
320 |
|
public function setPrefix($prefix) |
73
|
|
|
{ |
74
|
320 |
|
$this->metas->setPrefix($prefix); |
75
|
|
|
|
76
|
320 |
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Set type property. |
81
|
|
|
* |
82
|
|
|
* @param string $type |
83
|
|
|
* |
84
|
|
|
* @return \Arcanedev\SeoHelper\Entities\OpenGraph\Graph |
85
|
|
|
*/ |
86
|
320 |
|
public function setType($type) |
87
|
|
|
{ |
88
|
320 |
|
return $this->addProperty('type', $type); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Set title property. |
93
|
|
|
* |
94
|
|
|
* @param string $title |
95
|
|
|
* |
96
|
|
|
* @return \Arcanedev\SeoHelper\Entities\OpenGraph\Graph |
97
|
|
|
*/ |
98
|
320 |
|
public function setTitle($title) |
99
|
|
|
{ |
100
|
320 |
|
return $this->addProperty('title', $title); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Set description property. |
105
|
|
|
* |
106
|
|
|
* @param string $description |
107
|
|
|
* |
108
|
|
|
* @return \Arcanedev\SeoHelper\Entities\OpenGraph\Graph |
109
|
|
|
*/ |
110
|
320 |
|
public function setDescription($description) |
111
|
|
|
{ |
112
|
320 |
|
return $this->addProperty('description', $description); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Set url property. |
117
|
|
|
* |
118
|
|
|
* @param string $url |
119
|
|
|
* |
120
|
|
|
* @return \Arcanedev\SeoHelper\Entities\OpenGraph\Graph |
121
|
|
|
*/ |
122
|
16 |
|
public function setUrl($url) |
123
|
|
|
{ |
124
|
16 |
|
return $this->addProperty('url', $url); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Set image property. |
129
|
|
|
* |
130
|
|
|
* @param string $image |
131
|
|
|
* |
132
|
|
|
* @return \Arcanedev\SeoHelper\Entities\OpenGraph\Graph |
133
|
|
|
*/ |
134
|
16 |
|
public function setImage($image) |
135
|
|
|
{ |
136
|
16 |
|
return $this->addProperty('image', $image); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Set site name property. |
141
|
|
|
* |
142
|
|
|
* @param string $siteName |
143
|
|
|
* |
144
|
|
|
* @return \Arcanedev\SeoHelper\Entities\OpenGraph\Graph |
145
|
|
|
*/ |
146
|
320 |
|
public function setSiteName($siteName) |
147
|
|
|
{ |
148
|
320 |
|
return $this->addProperty('site_name', $siteName); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Add many open graph properties. |
153
|
|
|
* |
154
|
|
|
* @param array $properties |
155
|
|
|
* |
156
|
|
|
* @return \Arcanedev\SeoHelper\Entities\OpenGraph\Graph |
157
|
|
|
*/ |
158
|
320 |
|
public function addProperties(array $properties) |
159
|
|
|
{ |
160
|
320 |
|
$this->metas->addMany($properties); |
161
|
|
|
|
162
|
320 |
|
return $this; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Add an open graph property. |
167
|
|
|
* |
168
|
|
|
* @param string $property |
169
|
|
|
* @param string $content |
170
|
|
|
* |
171
|
|
|
* @return \Arcanedev\SeoHelper\Entities\OpenGraph\Graph |
172
|
|
|
*/ |
173
|
320 |
|
public function addProperty($property, $content) |
174
|
|
|
{ |
175
|
320 |
|
$this->metas->add($property, $content); |
176
|
|
|
|
177
|
320 |
|
return $this; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/* ------------------------------------------------------------------------------------------------ |
181
|
|
|
| Main Functions |
182
|
|
|
| ------------------------------------------------------------------------------------------------ |
183
|
|
|
*/ |
184
|
|
|
/** |
185
|
|
|
* Render the tag. |
186
|
|
|
* |
187
|
|
|
* @return string |
188
|
|
|
*/ |
189
|
240 |
|
public function render() |
190
|
|
|
{ |
191
|
240 |
|
return $this->metas->render(); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Render the tag. |
196
|
|
|
* |
197
|
|
|
* @return string |
198
|
|
|
*/ |
199
|
64 |
|
public function __toString() |
200
|
|
|
{ |
201
|
64 |
|
return $this->render(); |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
|