-
Notifications
You must be signed in to change notification settings - Fork 2
/
plugin.php
43 lines (37 loc) · 1.06 KB
/
plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
class PulponairCustomMetaDescription extends KokenPlugin {
/**
* Constructor registers filter
*
*/
public function __construct() {
$this->require_setup = true;
$this->register_filter('site.output', 'render');
}
/**
* The actual render method. Search for the meta description tag and replace it as configured.
*
* @param string $content
* @return string mixed
*/
public function render($content) {
$type = Koken::$source['type'];
if (property_exists($this->data, $type) && ($configuration = $this->data->{$type}) ) {
$description = preg_replace_callback('/\{\{\s*([^\}]+)\s*\}\}/', array($this, 'kokenOutCallback'),
$configuration);
$content = preg_replace('/<meta.*name="description".+?>/',
'<meta name="description" content="' . $description . '" />',
$content);
}
return $content;
}
/**
* Koken::out callback
*
* @param array $matches
* @return array|bool|int|mixed|string|void
*/
public function kokenOutCallback($matches) {
return koken::out($matches[1]);
}
}