-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPlugin.php
163 lines (143 loc) · 4.61 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
/**
* Author : Denis-Florin Rendler
* Date : 21/09/15
* Copyright (c) 2015 Denis-Florin Rendler <[email protected]>
*/
namespace KoderHut\RssFeedster;
use Route,
Url;
use Cms\Classes\Controller;
use System\Classes\PluginBase,
System\Classes\PluginManager;
use KoderHut\RssFeedster\Classes\Feedster,
KoderHut\RssFeedster\Classes\DataSource\PostsSource,
KoderHut\RssFeedster\Classes\View\XmlRenderer,
KoderHut\RssFeedster\Models\Settings,
KoderHut\RssFeedster\Classes\Support\Adapters\BlogPostXmlAdapter,
KoderHut\RssFeedster\Classes\Contracts\IAdapter;
/**
* RssFeed Plugin Information File
*/
class Plugin
extends PluginBase
{
/**
* Namespace const
*/
const KODERHUT_RSSFEEDSTER_NS = 'KoderHut\RssFeedster';
/**
* Define the plug-in dependencies
*
* @var array Plugin dependencies
*/
public $require = ['RainLab.Blog'];
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'koderhut.rssfeedster::lang.plugin.name',
'description' => 'koderhut.rssfeedster::lang.plugin.description',
'author' => 'Denis-Florin Rendler (KoderHut)',
'icon' => 'icon-rss',
'homepage' => 'https://github.com/rendler-denis/rssfeedster',
];
}
/**
* Set up the route for the RSS builder
*/
public function boot()
{
$rssUrl = Settings::get('feed_url');
Route::get($rssUrl, 'KoderHut\RssFeedster\Controllers\Rss@buildRssFeed');
$this->app->bind('KoderHut\RssFeedster\Feed', function($app)
{
return new Feedster();
});
}
/**
* Register our data source and renderer
*/
public function register()
{
/**
* Set up the data source for the feed
*/
$this->app->bind('KoderHut\RssFeedster\DataSource', function($app)
{
$config['page'] = Settings::get('post_page');
$config['comments_anchor'] = Settings::get('comments_anchor');
$config['controller'] = new Controller();
return new PostsSource($config);
});
/**
* Set up the adapter interface between the XML renderer and
* the blog posts data
*/
$this->app->bind(IAdapter::DI_NAMESPACE, function () {
return new BlogPostXmlAdapter();
});
/**
* Set up the feed renderer
*/
$this->app->bind('KoderHut\RssFeedster\Renderer', function($app)
{
$config = [
'description' => Settings::get('feed_description'),
'title' => Settings::get('feed_title'),
'category' => Settings::get('feed_category'),
'copyright' => Settings::get('feed_copyright'),
'language' => Settings::get('feed_language'),
'link' => Url::action('KoderHut\RssFeedster\Controllers\Rss@buildRssFeed'),
];
$pluginPath = PluginManager::instance()->getPluginPath(Plugin::KODERHUT_RSSFEEDSTER_NS);
$xmlTemplate = $pluginPath . DIRECTORY_SEPARATOR . 'resources'
. DIRECTORY_SEPARATOR . 'feed-template.xml';
return
new XmlRenderer(
$config,
file_get_contents($xmlTemplate),
$this->app->make(IAdapter::DI_NAMESPACE)
);
});
return;
}
/**
* Register the plug-in settings
*
* @return array
*/
public function registerSettings()
{
return [
'settings' => [
'label' => 'koderhut.rssfeedster::lang.plugin.name',
'description' => 'koderhut.rssfeedster::lang.settings.base.description',
'icon' => 'icon-rss',
'class' => 'KoderHut\RssFeedster\Models\Settings',
'order' => 500,
'keywords' => 'rss feed',
'category' => 'KoderHut',
'permissions' => ['koderhut.rssfeedster.access_config'],
]
];
}
/**
* Register plug-in permissions
*
* @return array
*/
public function registerPermissions()
{
return [
'koderhut.rssfeedster.access_config' => [
'label' => 'koderhut.rssfeedster::lang.messages.permissions.access_config_label',
'tab' => 'koderhut.rssfeedster::lang.plugin.name'
],
];
}
}