forked from initbiz/seostorm-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.php
141 lines (125 loc) · 4.09 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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
namespace Initbiz\SeoStorm;
use Event;
use Cms\Twig\Extension;
use Cms\Classes\Controller;
use System\Classes\PluginBase;
use Initbiz\SeoStorm\Models\Htaccess;
use Initbiz\SeoStorm\Models\Settings;
use Twig\Extension\StringLoaderExtension;
/**
* Initbiz Plugin Information File
*/
class Plugin extends PluginBase
{
public function registerComponents()
{
return [
'Initbiz\SeoStorm\Components\Seo' => 'seo',
];
}
public function register()
{
}
public function boot()
{
Event::subscribe(\Initbiz\SeoStorm\EventHandlers\BackendHandler::class);
Event::subscribe(\Initbiz\SeoStorm\EventHandlers\StormedHandler::class);
Event::subscribe(\Initbiz\SeoStorm\EventHandlers\RainlabPagesHandler::class);
Event::subscribe(\Initbiz\SeoStorm\EventHandlers\RainlabTranslateHandler::class);
// Load Twig extensions
/**
* @see \Modules\System\ServiceProvider to method registerTwigParser for more info
*/
$twig = app()->get('twig.environment');
if (!$twig->hasExtension(StringLoaderExtension::class)) {
$stringLoader = new StringLoaderExtension();
$twig->addExtension($stringLoader);
}
if (!$twig->hasExtension(Extension::class)) {
$controller = Controller::getController() ?? new Controller();
$octoberExtensions = new Extension($controller);
$twig->addExtension($octoberExtensions);
}
}
public function registerSettings()
{
return [
'settings' => [
'label' => 'initbiz.seostorm::lang.form.settings.label',
'description' => 'initbiz.seostorm::lang.form.settings.description',
'icon' => 'icon-search',
'category' => 'initbiz.seostorm::lang.form.settings.category_label',
'class' => Settings::class,
'order' => 100,
'permissions' => ['initbiz.manage_seo'],
],
'htaccess' => [
'label' => 'initbiz.seostorm::lang.form.htaccess.label',
'description' => 'initbiz.seostorm::lang.form.htaccess.description',
'icon' => 'icon-file-text-o',
'category' => 'initbiz.seostorm::lang.form.settings.category_label',
'class' => Htaccess::class,
'order' => 200,
'permissions' => ['initbiz.manage_seo'],
]
];
}
public function registerMarkupTags()
{
return [
'functions' => [
'template_from_string' => [$this, 'templateFromString'],
]
];
}
/**
* Extend twig to parse twig from twig with StringLoaderExtension
*
* @param string $template
* @return string
*/
public function templateFromString($template)
{
$twig = app()->get('twig.environment');
return twig_template_from_string($twig, $template);
}
/**
* Register models that are stormed by default
*
* @return array
*/
public function registerStormedModels()
{
$modelDefs = [
'Rainlab\Blog\Models\Post' => [
'placement' => 'secondaryTabs',
'excludeFields' => [
'model_class',
'model_scope',
'model_params',
'lastmod',
'use_updated_at',
'changefreq',
'priority',
'enabled_in_sitemap',
],
],
];
if (env('APP_ENV') === 'testing') {
$modelDefs['\Initbiz\SeoStorm\Tests\Classes\FakeStormedModel'] = [
'placement' => 'tabs',
'excludeFields' => [
'changefreq',
],
];
}
return $modelDefs;
}
public function registerFormWidgets()
{
return [
'\Initbiz\SeoStorm\FormWidgets\Migrate' => 'seo_migrate'
];
}
}