1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SeoHelper\Renderer; |
4
|
|
|
|
5
|
|
|
class DefaultRenderer extends AbstractRenderer |
6
|
|
|
{ |
7
|
|
|
protected $types = [ |
8
|
|
|
'default' => '<meta name="{$key}" content="{$value}">', |
9
|
|
|
'title' => '<title>{$value}</title>', |
10
|
|
|
'canonical' => '<link rel="canonical" href="{$value}">', |
11
|
|
|
'next' => '<link rel="next" href="{$value}">', |
12
|
|
|
'prev' => '<link rel="prev" href="{$value}">', |
13
|
|
|
]; |
14
|
|
|
|
15
|
27 |
|
protected function getPattern($type) |
16
|
|
|
{ |
17
|
27 |
|
return parent::getPattern($type) ?: $this->types['default']; |
18
|
|
|
} |
19
|
|
|
|
20
|
9 |
|
protected function initPreprocessors() |
21
|
|
|
{ |
22
|
18 |
|
$this->setPreprocessor('title', function ($value) { |
23
|
9 |
|
return strip_tags(implode(' | ', array_reverse($value))); |
24
|
27 |
|
}); |
25
|
18 |
|
$this->setPreprocessor('description', function ($value) { |
26
|
9 |
|
return htmlspecialchars(strip_tags(implode(' ', $value))); |
27
|
27 |
|
}); |
28
|
18 |
|
$this->setPreprocessor('keywords', function ($value) { |
29
|
3 |
|
return htmlspecialchars(strip_tags(implode(', ', array_unique($value)))); |
30
|
27 |
|
}); |
31
|
18 |
|
$this->setPreprocessor('canonical', function ($value) { |
32
|
3 |
|
return htmlspecialchars(strip_tags(implode($value))); |
33
|
27 |
|
}); |
34
|
18 |
|
$this->setPreprocessor('next', function ($value) { |
35
|
3 |
|
return htmlspecialchars(strip_tags(implode($value))); |
36
|
27 |
|
}); |
37
|
27 |
|
$this->setPreprocessor('prev', function ($value) { |
38
|
3 |
|
return htmlspecialchars(strip_tags(implode($value))); |
39
|
27 |
|
}); |
40
|
9 |
|
} |
41
|
|
|
} |
42
|
|
|
|