1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Sitemaps, a plugin for DotClear2. |
---|
5 | # Copyright (c) 2006-2009 Pep and contributors. |
---|
6 | # Licensed under the GPL version 2.0 license. |
---|
7 | # See LICENSE file or |
---|
8 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
9 | # |
---|
10 | # -- END LICENSE BLOCK ------------------------------------ |
---|
11 | if (!defined('DC_CONTEXT_ADMIN')) { exit; } |
---|
12 | |
---|
13 | $periods = array( |
---|
14 | __('undefined') => 0, |
---|
15 | __('always') => 1, |
---|
16 | __('hourly') => 2, |
---|
17 | __('daily') => 3, |
---|
18 | __('weekly') => 4, |
---|
19 | __('monthly') => 5, |
---|
20 | __('never') => 6 |
---|
21 | ); |
---|
22 | |
---|
23 | $map_parts = new ArrayObject(array( |
---|
24 | __('Homepage') => 'home', |
---|
25 | __('Feeds') => 'feeds', |
---|
26 | __('Posts') => 'posts', |
---|
27 | __('Pages') => 'pages', |
---|
28 | __('Categories') => 'cats', |
---|
29 | __('Tags') => 'tags' |
---|
30 | )); |
---|
31 | |
---|
32 | # --BEHAVIOR-- sitemapsDefineParts |
---|
33 | $core->callBehavior('sitemapsDefineParts',$map_parts); |
---|
34 | |
---|
35 | $msg = ''; |
---|
36 | $default_tab = 'sitemaps_options'; |
---|
37 | $active = $core->blog->settings->sitemaps_active; |
---|
38 | |
---|
39 | foreach ($map_parts as $k => $v) { |
---|
40 | ${$v.'_url'} = $core->blog->settings->get('sitemaps_'.$v.'_url'); |
---|
41 | ${$v.'_pr'} = $core->blog->settings->get('sitemaps_'.$v.'_pr'); |
---|
42 | ${$v.'_fq'} = $core->blog->settings->get('sitemaps_'.$v.'_fq'); |
---|
43 | } |
---|
44 | |
---|
45 | $engines = @unserialize($core->blog->settings->sitemaps_engines); |
---|
46 | $default_pings = explode(',',$core->blog->settings->sitemaps_pings); |
---|
47 | |
---|
48 | // Save new configuration |
---|
49 | if (!empty($_POST['saveconfig'])) { |
---|
50 | try |
---|
51 | { |
---|
52 | $core->blog->settings->setNameSpace('sitemaps'); |
---|
53 | |
---|
54 | $active = (empty($_POST['active']))?false:true; |
---|
55 | $core->blog->settings->put('sitemaps_active',$active,'boolean'); |
---|
56 | |
---|
57 | foreach ($map_parts as $k => $v) { |
---|
58 | ${$v.'_url'} = (empty($_POST[$v.'_url']))?false:true; |
---|
59 | ${$v.'_pr'} = min(abs((float)$_POST[$v.'_pr']),1); |
---|
60 | ${$v.'_fq'} = min(abs(intval($_POST[$v.'_fq'])),6); |
---|
61 | |
---|
62 | $core->blog->settings->put('sitemaps_'.$v.'_url', ${$v.'_url'}, 'boolean'); |
---|
63 | $core->blog->settings->put('sitemaps_'.$v.'_pr' , ${$v.'_pr'}, 'double'); |
---|
64 | $core->blog->settings->put('sitemaps_'.$v.'_fq' , ${$v.'_fq'}, 'integer'); |
---|
65 | } |
---|
66 | $core->blog->triggerBlog(); |
---|
67 | http::redirect('plugin.php?p='.$p.'&conf=1'); |
---|
68 | exit; |
---|
69 | } |
---|
70 | catch (Exception $e) { |
---|
71 | $core->error->add($e->getMessage()); |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | // Save ping preferences |
---|
76 | elseif (!empty($_POST['saveprefs'])) |
---|
77 | { |
---|
78 | try { |
---|
79 | $new_prefs = ''; |
---|
80 | if (!empty($_POST['pings'])) { |
---|
81 | $new_prefs = implode(',',$_POST['pings']); |
---|
82 | } |
---|
83 | $core->blog->settings->setNamespace('sitemaps'); |
---|
84 | $core->blog->settings->put('sitemaps_pings',$new_prefs,'string'); |
---|
85 | http::redirect('plugin.php?p='.$p.'&prefs=1'); |
---|
86 | exit; |
---|
87 | } |
---|
88 | catch (Exception $e) { |
---|
89 | $default_tab = 'sitemaps_notifications'; |
---|
90 | $core->error->add($e->getMessage()); |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | // Send ping(s) |
---|
95 | elseif (!empty($_POST['ping'])) |
---|
96 | { |
---|
97 | $pings = empty($_POST['pings']) ? $default_pings : $_POST['pings']; |
---|
98 | $sitemap_url = $core->blog->url.$core->url->getBase('gsitemap'); |
---|
99 | foreach ($pings as $service) { |
---|
100 | try { |
---|
101 | if (!array_key_exists($service,$engines)) continue; |
---|
102 | if (false === netHttp::quickGet($engines[$service]['url'].'?sitemap='.urlencode($sitemap_url))) { |
---|
103 | throw new Exception(__('Response does not seem OK')); |
---|
104 | } |
---|
105 | $results[] = sprintf('%s : %s', __('success'), $engines[$service]['name']); |
---|
106 | } |
---|
107 | catch (Exception $e) { |
---|
108 | $results[] = sprintf('%s : %s : %s', __('Failure'), $engines[$service]['name'],$e->getMessage()); |
---|
109 | } |
---|
110 | } |
---|
111 | $msg = __('Ping(s) sent'); |
---|
112 | $msg .= '<br />'.implode("<br />\n",$results); |
---|
113 | } |
---|
114 | |
---|
115 | else { |
---|
116 | if (isset($_GET['prefs'])) { |
---|
117 | $msg = __('New preferences saved'); |
---|
118 | $default_tab = 'sitemaps_notifications'; |
---|
119 | } |
---|
120 | elseif (isset($_GET['conf'])) { |
---|
121 | $msg = __('Configuration successfully updated.'); |
---|
122 | $default_tab = 'sitemaps_options'; |
---|
123 | } |
---|
124 | } |
---|
125 | ?> |
---|
126 | <html> |
---|
127 | <head> |
---|
128 | <title><?php echo __('XML Sitemaps'); ?></title> |
---|
129 | <?php echo dcPage::jsPageTabs($default_tab); ?> |
---|
130 | </head> |
---|
131 | <body> |
---|
132 | <h2><?php echo html::escapeHTML($core->blog->name); ?> > <?php echo __('XML Sitemaps'); ?></h2> |
---|
133 | <?php if (!empty($msg)) echo '<p class="message">'.$msg.'</p>'; ?> |
---|
134 | <!-- Configuration panel --> |
---|
135 | <div class="multi-part" id="sitemaps_options" title="<?php echo __('Configuration'); ?>"> |
---|
136 | <form method="post" action="<?php echo http::getSelfURI(); ?>"> |
---|
137 | <fieldset> |
---|
138 | <legend><?php echo __('Plugin activation'); ?></legend> |
---|
139 | <p class="field"> |
---|
140 | <label class=" classic"><?php echo form::checkbox('active', 1, $active); ?> |
---|
141 | <?php echo __('Enable sitemaps');?> |
---|
142 | </label> |
---|
143 | </p> |
---|
144 | </fieldset> |
---|
145 | <fieldset> |
---|
146 | <legend><?php echo __('For your information'); ?></legend> |
---|
147 | <p> |
---|
148 | <?php echo __("This blog's Sitemap URL:"); ?> |
---|
149 | <strong><?php echo $core->blog->url.$core->url->getBase('gsitemap'); ?></strong> |
---|
150 | </p> |
---|
151 | </fieldset> |
---|
152 | <fieldset> |
---|
153 | <legend><?php echo __('Elements to integrate'); ?></legend> |
---|
154 | <table class="maximal"> |
---|
155 | <tbody> |
---|
156 | <?php foreach ($map_parts as $k => $v) : ?> |
---|
157 | <tr> |
---|
158 | <td> |
---|
159 | <label class=" classic"> |
---|
160 | <?php echo form::checkbox($v.'_url', 1, ${$v.'_url'});?> |
---|
161 | <?php echo $k;?> |
---|
162 | </label> |
---|
163 | </td> |
---|
164 | <td> |
---|
165 | <label class=" classic"><?php echo __('Priority'); ?> |
---|
166 | <?php echo form::field($v.'_pr', 4, 4, ${$v.'_pr'}); ?> |
---|
167 | </label> |
---|
168 | </td> |
---|
169 | <td> |
---|
170 | <label class=" classic"><?php echo __('Periodicity'); ?> |
---|
171 | <?php echo form::combo($v.'_fq', $periods, ${$v.'_fq'}); ?> |
---|
172 | </label> |
---|
173 | </td> |
---|
174 | </tr> |
---|
175 | <?php endforeach; ?> |
---|
176 | </tbody> |
---|
177 | </table> |
---|
178 | </fieldset> |
---|
179 | |
---|
180 | <p><input type="hidden" name="p" value="sitemaps" /> |
---|
181 | <?php echo $core->formNonce(); ?> |
---|
182 | <input type="submit" name="saveconfig" value="<?php echo __('Save configuration'); ?>" /> |
---|
183 | <?php if ($active) : ?> |
---|
184 | <input class="submit" type="submit" name="ping" value="<?php echo __('Ping search engines'); ?>" /> |
---|
185 | <?php endif; ?> |
---|
186 | </p> |
---|
187 | </form> |
---|
188 | </div> |
---|
189 | |
---|
190 | <!-- Notifications panel --> |
---|
191 | <div class="multi-part" id="sitemaps_notifications" title="<?php echo __('Search engines notification'); ?>"> |
---|
192 | <form method="post" action="<?php echo http::getSelfURI(); ?>"> |
---|
193 | <fieldset> |
---|
194 | <legend><?php echo __('Available search engines'); ?></legend> |
---|
195 | <table class="maximal"> |
---|
196 | <tbody> |
---|
197 | <?php foreach ($engines as $eng => $eng_infos) : ?> |
---|
198 | <tr> |
---|
199 | <td> |
---|
200 | <label class=" classic"> |
---|
201 | <?php echo form::checkbox('pings[]', $eng, in_array($eng,$default_pings));?> |
---|
202 | <?php echo $eng_infos['name'];?> |
---|
203 | </label> |
---|
204 | </td> |
---|
205 | </tr> |
---|
206 | <?php endforeach; ?> |
---|
207 | </tbody> |
---|
208 | </table> |
---|
209 | </fieldset> |
---|
210 | <p><input type="hidden" name="p" value="sitemaps" /> |
---|
211 | <?php echo $core->formNonce(); ?> |
---|
212 | <input type="submit" name="saveprefs" value="<?php echo __('Save preferences'); ?>" /> |
---|
213 | <?php if ($active) : ?> |
---|
214 | <input class="submit" type="submit" name="ping" value="<?php echo __('Ping search engines'); ?>" /> |
---|
215 | <?php endif; ?> |
---|
216 | </p> |
---|
217 | </form> |
---|
218 | </div> |
---|
219 | |
---|
220 | </body> |
---|
221 | </html> |
---|