forked from bobdenotter/seo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtension.php
executable file
·88 lines (67 loc) · 2.51 KB
/
Extension.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace Bolt\Extension\BobdenOtter\Seo;
use Bolt\Translation\Translator as Trans,
Symfony\Component\Translation\Loader as TranslationLoader;
use Bolt\Application;
use Bolt\BaseExtension;
require_once('Seo.php');
require_once('src/SEO.php');
class Extension extends BaseExtension
{
private $version = "v0.9.12";
public function __construct(Application $app)
{
parent::__construct($app);
$this->app['config']->getFields()->addField(new SEOField());
}
public function initialize() {
$end = $this->app['config']->getWhichEnd();
if ($end =='backend') {
$this->app->before(array($this, 'before'));
$this->app['htmlsnippets'] = true;
$this->addCss('assets/seo.css');
// $this->addJavascript('assets/seo.js', true);
}
$this->app['twig.loader.filesystem']->addPath(__DIR__."/twig");
$currentUser = $this->app['users']->getCurrentUser();
$currentUserId = $currentUser['id'];
// Set the Permissions for the advanced field to the correct roles.
$this->config['allowed'] = array();
if (!empty($this->config['allow'])) {
foreach ($this->config['allow'] as $key => $field) {
$this->config["allowed"][$key] = false;
foreach ($this->config['allow'][$key] as $role) {
if ($this->app['users']->hasRole($currentUserId, $role)) {
$this->config["allowed"][$key] = true;
break;
}
}
}
}
$this->app['twig']->addGlobal('seoconfig', $this->config);
if ($end == 'frontend') {
$seo = new SEO($this->app, $this->config, $this->version);
$this->app['twig']->addGlobal('seo', $seo);
}
}
public function before()
{
$this->translationDir = __DIR__.'/locales/' . substr($this->app['locale'], 0, 2);
if (is_dir($this->translationDir))
{
$iterator = new \DirectoryIterator($this->translationDir);
foreach ($iterator as $fileInfo)
{
if ($fileInfo->isFile())
{
$this->app['translator']->addLoader('yml', new TranslationLoader\YamlFileLoader());
$this->app['translator']->addResource('yml', $fileInfo->getRealPath(), $this->app['locale']);
}
}
}
}
public function getName()
{
return "seo";
}
}