forked from craftplugins/sitemap
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSitemapPlugin.php
127 lines (112 loc) · 3.39 KB
/
SitemapPlugin.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
<?php
namespace Craft;
class SitemapPlugin extends BasePlugin
{
/**
* {@inheritdoc} IPlugin::init()
*/
public function init()
{
if (craft()->request->isCpRequest()) {
craft()->templates->includeCssResource('sitemap/settings.css');
}
}
/**
* {@inheritdoc} IPlugin::getName()
*/
public function getName()
{
return 'Sitemap';
}
/**
* {@inheritdoc} IPlugin::getVersion()
*/
public function getVersion()
{
return '1.2.3';
}
/**
* {@inheritdoc} IPlugin::getDeveloper()
*/
public function getDeveloper()
{
return 'Joshua Baker';
}
/**
* {@inheritdoc} IPlugin::getDeveloperUrl()
*/
public function getDeveloperUrl()
{
return 'http://joshuabaker.com/';
}
/**
* {@inheritdoc} BaseSavableComponentType::defineSettings()
*/
protected function defineSettings()
{
return array(
'sections' => array(),
'addAlternateUrls' => array(AttributeType::Bool, 'default' => true),
'currentLocaleOnly' => array(AttributeType::Bool, 'default' => false),
);
}
/**
* {@inheritdoc} BaseSavableComponentType::getSettingsHtml()
*/
public function getSettingsHtml()
{
return craft()->templates->render('sitemap/_settings', array(
'sections' => craft()->sitemap->sectionsWithUrls,
'settings' => $this->settings,
));
}
/**
* {@inheritdoc} BaseSavableComponentType::prepSettings()
*/
public function prepSettings($input)
{
// early exit if $input is already a complete settings array
// like in a Schematic import
if (!array_key_exists('enabled', $input) && isset($input['sections']) && is_array($input['sections'])) {
return $input;
}
// We’re rewriting every time
$settings = $this->defineSettings();
// Loop through valid sections
foreach (craft()->sitemap->sectionsWithUrls as $section) {
// Check if the section is enabled
if (array_key_exists('enabled', $input) && $input['enabled'][$section->id]) {
// If it is, save the changefreq and priority values into settings
$settings['sections'][$section->id] = array(
'changefreq' => $input['changefreq'][$section->id],
'priority' => $input['priority'][$section->id],
'includeiffield' => $input['includeiffield'][$section->id],
);
}
}
$settings['currentLocaleOnly'] = isset($input['currentLocaleOnly']) && $input['currentLocaleOnly'] == '1';
$settings['addAlternateUrls'] = isset($input['addAlternateUrls']) && $input['addAlternateUrls'] == '1';
// Return the parsed settings ready for the database
return $settings;
}
/**
* Registers the /sitemap.xml route.
*
* @return array
*/
public function registerSiteRoutes()
{
return array(
'sitemap.xml' => array(
'action' => 'sitemap/sitemap/output',
),
);
}
/**
* {@inheritdoc} IPlugin::getReleaseFeedUrl()
*/
public function getReleaseFeedUrl()
{
return 'https://raw.githubusercontent.com/groe/craft-sitemap/master/changelog.json';
}
}