1 | <?php |
---|
2 | # ***** BEGIN LICENSE BLOCK ***** |
---|
3 | # |
---|
4 | # This file is part of Log 404 Errors, a plugin for Dotclear 2 |
---|
5 | # Copyright (C) 2009 Moe (http://gniark.net/) |
---|
6 | # |
---|
7 | # Log 404 Errors is free software; you can redistribute it and/or |
---|
8 | # modify it under the terms of the GNU General Public License v2.0 |
---|
9 | # as published by the Free Software Foundation. |
---|
10 | # |
---|
11 | # Log 404 Errors is distributed in the hope that it will be useful, |
---|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | # GNU General Public License for more details. |
---|
15 | # |
---|
16 | # You should have received a copy of the GNU General Public License |
---|
17 | # along with this program; if not, write to the Free Software Foundation, |
---|
18 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
19 | # |
---|
20 | # ***** END LICENSE BLOCK ***** |
---|
21 | |
---|
22 | if (!defined('DC_CONTEXT_ADMIN')) {return;} |
---|
23 | |
---|
24 | require_once(dirname(__FILE__).'/lib.log404Errors.php'); |
---|
25 | |
---|
26 | if (isset($_GET['tab']) && ($_GET['tab'] == 'errors')) |
---|
27 | { |
---|
28 | $tab = 'errors'; |
---|
29 | |
---|
30 | $counter = $core->con->select('SELECT COUNT(id) AS count '. |
---|
31 | 'FROM '.$core->prefix.'errors_log '. |
---|
32 | 'WHERE (blog_id = \''.$core->con->escape( |
---|
33 | $core->blog->id).'\') ')->f(0); |
---|
34 | } |
---|
35 | else |
---|
36 | { |
---|
37 | $tab = 'summary'; |
---|
38 | |
---|
39 | $counter = $core->con->select('SELECT COUNT(id) AS count '. |
---|
40 | 'FROM '.$core->prefix.'errors_log '. |
---|
41 | 'WHERE (blog_id = \''.$core->con->escape( |
---|
42 | $core->blog->id).'\') '. |
---|
43 | 'GROUP BY url ')->f(0); |
---|
44 | } |
---|
45 | |
---|
46 | $msg = (string)''; |
---|
47 | |
---|
48 | $settings =& $core->blog->settings; |
---|
49 | |
---|
50 | $settings->setNameSpace('log404errors'); |
---|
51 | |
---|
52 | # pages |
---|
53 | $page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; |
---|
54 | $nb_per_page = $settings->log404errors_nb_per_page; |
---|
55 | |
---|
56 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { |
---|
57 | if ($nb_per_page != $_GET['nb']) { |
---|
58 | $show_filters = true; |
---|
59 | } |
---|
60 | $nb_per_page = (integer) $_GET['nb']; |
---|
61 | } |
---|
62 | |
---|
63 | $params = array(); |
---|
64 | |
---|
65 | $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); |
---|
66 | |
---|
67 | $pager = new pager($page,$counter,$nb_per_page,10); |
---|
68 | $pager->base_url = $p_url. |
---|
69 | '&tab='.$tab. |
---|
70 | '&page=%s'; |
---|
71 | |
---|
72 | $links = '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; |
---|
73 | # /pages |
---|
74 | |
---|
75 | # actions |
---|
76 | if (!empty($_POST['saveconfig'])) |
---|
77 | { |
---|
78 | # Enable Log 404 Errors |
---|
79 | $settings->put('log404errors_active', |
---|
80 | (!empty($_POST['log404errors_active'])),'boolean', |
---|
81 | 'Enable Log 404 Errors'); |
---|
82 | |
---|
83 | $settings->put('log404errors_nb_per_page', |
---|
84 | (($_POST['log404errors_nb_per_page'] >= 1) |
---|
85 | ? $_POST['log404errors_nb_per_page'] : 30), |
---|
86 | 'integer','Errors per page'); |
---|
87 | |
---|
88 | http::redirect($p_url.'&saveconfig=1'); |
---|
89 | } |
---|
90 | elseif (isset($_POST['drop'])) |
---|
91 | { |
---|
92 | try |
---|
93 | { |
---|
94 | log404Errors::drop(); |
---|
95 | } |
---|
96 | catch (Exception $e) |
---|
97 | { |
---|
98 | $core->error->add($e->getMessage()); |
---|
99 | } |
---|
100 | $msg = __('Errors log has been deleted.'); |
---|
101 | } |
---|
102 | |
---|
103 | if (isset($_GET['saveconfig'])) |
---|
104 | { |
---|
105 | $msg = __('Configuration successfully updated.'); |
---|
106 | $tab = 'settings'; |
---|
107 | } |
---|
108 | |
---|
109 | ?> |
---|
110 | <html> |
---|
111 | <head> |
---|
112 | <title><?php echo __('404 Errors'); ?></title> |
---|
113 | <?php echo dcPage::jsPageTabs($tab); ?> |
---|
114 | <script type="text/javascript"> |
---|
115 | //<![CDATA[ |
---|
116 | <?php echo dcPage::jsVar('dotclear.msg.confirm_404Errors_drop', |
---|
117 | __('Are you sure you want to delete the 404 errors?')); ?> |
---|
118 | $(function() { |
---|
119 | $('input[name="drop"]').click(function() { |
---|
120 | return window.confirm(dotclear.msg.confirm_404Errors_drop); |
---|
121 | }); |
---|
122 | }); |
---|
123 | //]]> |
---|
124 | </script> |
---|
125 | </head> |
---|
126 | <body> |
---|
127 | |
---|
128 | <h2><?php echo(html::escapeHTML($core->blog->name).' › '.__('404 Errors')); ?></h2> |
---|
129 | |
---|
130 | <?php |
---|
131 | if (!empty($msg)) {echo '<p class="message">'.$msg.'</p>';} |
---|
132 | if (!$settings->log404errors_active) |
---|
133 | { |
---|
134 | echo('<p class="message">'.__('The 404 errors are not logged.').'</p>'); |
---|
135 | } |
---|
136 | ?> |
---|
137 | |
---|
138 | <?php if (isset($_GET['tab']) && ($_GET['tab'] == 'errors')) { ?> |
---|
139 | |
---|
140 | <p><a href="<?php echo($p_url); ?>&tab=summary" class="multi-part"> |
---|
141 | <?php echo(__('Summary')); ?></a></p> |
---|
142 | |
---|
143 | <div class="multi-part" id="errors" title="<?php echo __('Errors'); ?>"> |
---|
144 | <?php echo($links); ?> |
---|
145 | <table class="clear" summary="<?php echo(__('Errors 404')); ?>"> |
---|
146 | <thead> |
---|
147 | <tr> |
---|
148 | <th><?php echo(__('Id')); ?></th> |
---|
149 | <th><acronym title="Uniform Resource Locator">URL</acronym></th> |
---|
150 | <th><?php echo(__('Date')); ?></th> |
---|
151 | <th><?php echo(__('IP address')); ?></th> |
---|
152 | <th><?php echo(__('Referrer')); ?></th> |
---|
153 | <th><?php echo(__('User agent')); ?></th> |
---|
154 | </tr> |
---|
155 | </thead> |
---|
156 | <tbody> |
---|
157 | <?php |
---|
158 | unset($params['group']); |
---|
159 | log404Errors::show($params); |
---|
160 | ?> |
---|
161 | </tbody> |
---|
162 | </table> |
---|
163 | |
---|
164 | <?php echo($links); ?> |
---|
165 | |
---|
166 | <form method="post" action="<?php echo(http::getSelfURI()); ?>"> |
---|
167 | <p><?php echo $core->formNonce(); ?></p> |
---|
168 | <p><input type="submit" name="drop" value="<?php echo __('drop'); ?>" /></p> |
---|
169 | </form> |
---|
170 | </div> |
---|
171 | |
---|
172 | <?php } else { ?> |
---|
173 | |
---|
174 | <div class="multi-part" id="summary" title="<?php echo __('Summary'); ?>"> |
---|
175 | <?php echo($links); ?> |
---|
176 | <table class="clear" summary="<?php echo(__('404 Errors')); ?>"> |
---|
177 | <thead> |
---|
178 | <tr> |
---|
179 | <th><?php echo(__('Count')); ?></th> |
---|
180 | <th><acronym title="Uniform Resource Locator">URL</acronym></th> |
---|
181 | <th><?php echo(__('Date of last error')); ?></th> |
---|
182 | </tr> |
---|
183 | </thead> |
---|
184 | <tbody> |
---|
185 | <?php |
---|
186 | $params['group'] = true; |
---|
187 | log404Errors::show($params); |
---|
188 | ?> |
---|
189 | </tbody> |
---|
190 | </table> |
---|
191 | |
---|
192 | <?php echo($links); ?> |
---|
193 | |
---|
194 | <form method="post" action="<?php echo(http::getSelfURI()); ?>"> |
---|
195 | <p><?php echo $core->formNonce(); ?></p> |
---|
196 | <p><input type="submit" name="drop" value="<?php echo __('drop'); ?>" /></p> |
---|
197 | </form> |
---|
198 | </div> |
---|
199 | |
---|
200 | <p><a href="<?php echo($p_url); ?>&tab=errors" class="multi-part"> |
---|
201 | <?php echo(__('Errors')); ?></a></p> |
---|
202 | |
---|
203 | <?php } ?> |
---|
204 | |
---|
205 | <div class="multi-part" id="settings" title="<?php echo __('Settings'); ?>"> |
---|
206 | <form method="post" action="<?php echo http::getSelfURI(); ?>"> |
---|
207 | <fieldset> |
---|
208 | <legend><?php echo(__('Settings')); ?></legend> |
---|
209 | <p> |
---|
210 | <?php echo(form::checkbox('log404errors_active',1, |
---|
211 | $settings->log404errors_active)); ?> |
---|
212 | <label class="classic" for="log404errors_active"> |
---|
213 | <?php echo(__('Log 404 errors')); ?></label> |
---|
214 | </p> |
---|
215 | |
---|
216 | <p> |
---|
217 | <label class="classic" for="log404errors_nb_per_page"> |
---|
218 | <?php echo __('Errors per page:'); ?> |
---|
219 | </label> |
---|
220 | <?php echo form::field('log404errors_nb_per_page',7,7, |
---|
221 | $settings->log404errors_nb_per_page); ?> |
---|
222 | </p> |
---|
223 | |
---|
224 | <p><?php echo $core->formNonce(); ?></p> |
---|
225 | <p><input type="submit" name="saveconfig" value="<?php echo __('Save configuration'); ?>" /></p> |
---|
226 | </fieldset> |
---|
227 | </form> |
---|
228 | </div> |
---|
229 | |
---|
230 | </body> |
---|
231 | </html> |
---|