[ Index ] |
|
Code source de Plume CMS 1.2.2 |
1 <?php 2 /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 3 /* 4 # ***** BEGIN LICENSE BLOCK ***** 5 # This file is part of Plume CMS, a website management application. 6 # Copyright (C) 2001-2005 Loic d'Anterroches and contributors. 7 # 8 # Plume CMS is free software; you can redistribute it and/or modify 9 # it under the terms of the GNU General Public License as published by 10 # the Free Software Foundation; either version 2 of the License, or 11 # (at your option) any later version. 12 # 13 # Plume CMS is distributed in the hope that it will be useful, 14 # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 # GNU General Public License for more details. 17 # 18 # You should have received a copy of the GNU General Public License 19 # along with this program; if not, write to the Free Software 20 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 # 22 # ***** END LICENSE BLOCK ***** */ 23 24 $m->l10n->loadPlugin($m->user->lang, 'smart404'); 25 $is_log = (!empty($_REQUEST['op']) && $_REQUEST['op']=='log'); 26 $env = (!empty($_GET['env'])) ? $_GET['env'] : 1; 27 $con =& pxDBConnect(); 28 29 /* ============================================================== * 30 * Functions needed for the lists * 31 * ============================================================== */ 32 require_once $_PX_config['manager_path'].'/extinc/class.lum.php'; 33 34 function line_red($data, $i) 35 { 36 global $_px_theme; 37 $delete = sprintf('<a href="tools.php?p=smart404&op=red&del=%s" title="'.__('Remove').'" onclick="return window.confirm(\''. __('Are you sure you want to delete this redirection?').'\');"><img src="themes/'.$_px_theme.'/images/delete.png" alt="'.__('Remove').'"/></a>', 38 urlencode($data['old'])); 39 if (strlen($data['new']) > 50) { 40 $data['new'] = '<span title="'.$data['new'].'">...' 41 .substr($data['new'],-47).'</span>'; 42 } 43 if (strlen($data['old']) > 50) { 44 $data['old'] = '<span title="'.$data['old'].'">...' 45 .substr($data['old'],-47).'</span>'; 46 } 47 return '<tr><td>'.$data['old'].'</td><td>'.$data['new'] 48 .'</td><td>'.$data['last'].'</td><td>'.$data['total'] 49 .'</td><td>'.$delete.'</td></tr>'."\n"; 50 } 51 52 function line_log_all($data, $i) 53 { 54 global $_px_ptheme; 55 $details = sprintf('<a href="tools.php?p=smart404&op=log&page=%s" title="'.__('View details').'"><img src="tools/smart404/themes/'.$_px_ptheme.'/details.png" alt="'.__('Details').'"/></a>', 56 urlencode($data['page'])); 57 if (strlen($data['page']) > 50) { 58 $data['page'] = '<span title="'.$data['page'].'">...' 59 .substr($data['page'],-47).'</span>'; 60 } 61 return '<tr><td>'.$data['page'].'</td><td>'.$data['date'] 62 .'</td><td>'.$data['total'].'</td><td>'.$details.'</td></tr>'."\n"; 63 } 64 65 function line_log_details($data, $i) 66 { 67 if (strlen($data['from']) > 40) { 68 $data['from'] = '<span title="'.$data['from'].'">' 69 .substr($data['from'],0,37).'...</span>'; 70 } elseif (strlen($data['from']) == 0) { 71 $data['from'] = '...'; 72 } 73 if (strlen($data['useragent']) > 40) { 74 $data['useragent'] = '<span title="'.$data['useragent'].'">' 75 .substr($data['useragent'],0,37).'...</span>'; 76 } 77 return '<tr><td>'.$data['date'].'</td><td>'.$data['from'] 78 .'</td><td>'.$data['useragent'].'</td></tr>'."\n"; 79 } 80 81 /* ================================== * 82 * Process block * 83 * ================================== */ 84 if ($is_log) { 85 $px_submenu->addItem( __('Redirections'),'tools.php?p=smart404','',false); 86 /* ======================================== 87 * Get the log of errors or purge the logs 88 * ========================================*/ 89 $is_page_view = false; 90 if (!empty($_REQUEST['purge'])) { 91 //the purge is simple to implement :) 92 $sql = 'DELETE FROM '.$con->pfx.'smart404logs 93 WHERE website_id=\''.$_SESSION['website_id'].'\''; 94 if (!$con->execute($sql)) { 95 $m->setError('MySQL : '.$con->error(), 500); 96 } else { 97 $msg = __('The error log of this website has been successfully purged.'); 98 header('Location: tools.php?p=smart404&op=red&msg='.urlencode($msg)); 99 exit; 100 } 101 } else { 102 //2 cases for the logs: 103 // - default = list all the errors grouped by error pages 104 // and with number of hits DESC for the order 105 // - page = list the details of a page (from, user agent) 106 // order by date DESC 107 $log_list = array(); 108 if (!empty($_REQUEST['page'])) { 109 $is_page_view = true; 110 $px_submenu->addItem(__('404 error log'), 111 'tools.php?p=smart404&op=log', 112 '', false); 113 $sql = 'SELECT * FROM '.$con->pfx.'smart404logs 114 WHERE website_id=\''.$_SESSION['website_id'].'\' AND 115 page LIKE \''.$con->escapeStr($_REQUEST['page']).'\' 116 ORDER BY date DESC'; 117 if (false !== ($rs = $con->select($sql))) { 118 $i = 0; 119 while (!$rs->EOF()) { 120 $log_list[$i]['date'] = date(__('Y/m/d&\nb\sp;H:i:s'), 121 date::unix($rs->f('date'))); 122 $log_list[$i]['from'] = $rs->f('fromurl'); 123 $log_list[$i]['useragent'] = $rs->f('useragent'); 124 $i++; 125 $rs->moveNext(); 126 } 127 } 128 } else { 129 $sql = 'SELECT *, COUNT(*) AS total, MAX(date) AS lastdate 130 FROM '.$con->pfx.'smart404logs 131 WHERE website_id=\''.$_SESSION['website_id'].'\' 132 GROUP BY page ORDER BY total DESC'; 133 if (false !== ($rs = $con->select($sql))) { 134 $i = 0; 135 while (!$rs->EOF()) { 136 $log_list[$i]['date'] = date(__('Y/m/d&\nb\sp;H:i:s'), 137 date::unix($rs->f('lastdate'))); 138 $log_list[$i]['page'] = $rs->f('page'); 139 $log_list[$i]['total'] = $rs->f('total'); 140 $i++; 141 $rs->moveNext(); 142 } 143 } 144 145 } 146 } 147 } else { 148 $px_submenu->addItem( __('404 error log'), 149 'tools.php?p=smart404&op=log', 150 '', false); 151 /* ======================================== 152 * Get the redirections or add/remove one 153 * ========================================*/ 154 if (empty($_GET['del'])) { 155 //get the redirections 156 $red_list = array(); 157 $sql = 'SELECT * FROM '.$con->pfx.'smart404 158 WHERE website_id=\''.$_SESSION['website_id'].'\' 159 ORDER BY lastroutingdate DESC'; 160 if (false !== ($rs = $con->select($sql))) { 161 $i = 0; 162 while (!$rs->EOF()) { 163 $red_list[$i]['old'] = $rs->f('oldpage'); 164 $red_list[$i]['new'] = $rs->f('newpage'); 165 $red_list[$i]['last'] = date(__('Y/m/d&\nb\sp;H:i:s'), 166 date::unix($rs->f('lastroutingdate'))); 167 $red_list[$i]['total'] = $rs->f('total'); 168 $i++; 169 $rs->moveNext(); 170 } 171 } 172 } 173 174 if (!empty($_GET['del'])) { 175 //Remove a redirection 176 $sql = 'DELETE FROM '.$con->pfx.'smart404 177 WHERE website_id=\''.$_SESSION['website_id'].'\' 178 AND oldpage LIKE \''.$con->escapeStr($_GET['del']).'\' LIMIT 1'; 179 if (!$con->execute($sql)) { 180 $m->setError('MySQL : '.$con->error(), 500); 181 } else { 182 $msg = __('The redirection has been deleted successfully.'); 183 header('Location: tools.php?p=smart404&op=red&msg='.urlencode($msg)); 184 exit; 185 } 186 } 187 188 if (!empty($_POST['save'])) { 189 //Add a redirection 190 $px_old = (!empty($_POST['s_old'])) ? trim($_POST['s_old']) : ''; 191 $px_new = (!empty($_POST['s_new'])) ? trim($_POST['s_new']) : ''; 192 //Quick check 193 $error = false; 194 if (!preg_match('#^/#', $px_old)) { 195 $m->setError(__('The old page must start with <strong>/</strong>.'), 400); 196 $error = true; 197 } 198 if (!preg_match('#^http://#', $px_new)) { 199 $m->setError(__('The new page must start with <strong>http://</strong>.'), 400); 200 $error = true; 201 } 202 if (!$error) { 203 $sql = 'INSERT INTO '.$con->pfx.'smart404 SET 204 website_id=\''.$_SESSION['website_id'].'\', 205 oldpage=\''.$con->escapeStr($px_old).'\', 206 newpage=\''.$con->escapeStr($px_new).'\', 207 lastroutingdate=\''.date::stamp().'\''; 208 if (!$con->execute($sql)) { 209 $m->setError('MySQL : '.$con->error(), 500); 210 } else { 211 $msg = __('The redirection has been added successfully.'); 212 header('Location: tools.php?p=smart404&op=red&msg='.urlencode($msg)); 213 exit; 214 } 215 } 216 } 217 218 } 219 220 /*============================================================================== 221 Display block 222 ==============================================================================*/ 223 ?> 224 <h1><?php echo __('Smart 404 Errors'); ?></h1> 225 226 <?php 227 if ($is_log): 228 /* ======================================== 229 * Display the log of errors 230 * ========================================*/ 231 ?> 232 <h2><?php echo __('Log of the pages not found'); ?></h2> 233 <?php 234 235 if ($is_page_view) { 236 echo '<p>'.sprintf(__('Detailled log for the page <em>%s</em>.'), htmlspecialchars($_REQUEST['page'])).'</p>'."\n"; 237 echo '<p>'.sprintf(__('<a href="%s">Create a redirection</a> to avoid this error.'), 'tools.php?p=smart404&old='.urlencode($_REQUEST['page']).'#create').'</p>'."\n"; 238 $objLum = new lum($env, 'line_log_details', $log_list, 0, 20); 239 $objLum->htmlHeader = '<table class="clean-table">'."\n".'<tr><th>'.__('Date').'</th><th>'.__('From').'</th><th>'.__('User Agent').'</th></tr>'."\n"; 240 } else { 241 echo '<p><a href="tools.php?p=smart404&op=log&purge=toilettes" '. 242 'onclick="return window.confirm(\''. __('Are you sure you want to purge all the logs?').'\')">'. __('Purge the logs.').'</a></p>'; 243 244 $objLum = new lum($env, 'line_log_all', $log_list, 0, 20); 245 $objLum->htmlHeader = '<table class="clean-table">'."\n".'<tr><th>'.__('Page').'</th><th>'.__('Date').'</th><th colspan="2">'.__('Count').'</th></tr>'."\n"; 246 } 247 $objLum->htmlLineStart = ''; 248 $objLum->htmlColStart = ''; 249 $objLum->htmlColEnd = ''; 250 $objLum->htmlLineEnd = ''; 251 $objLum->htmlFooter = '</table>'."\n"; 252 253 $objLum->htmlLinksStart = '<p class="small">'; 254 $objLum->htmlLinksEnd = '</p>'; 255 256 $objLum->htmlCurPgStart = '<strong>'; 257 $objLum->htmlCurPgEnd = '</strong>'; 258 259 $objLum->htmlPrev = __('« previous page'); 260 $objLum->htmlNext = __('» next page'); 261 $objLum->htmlPrevGrp = '...'; 262 $objLum->htmlNextGrp = '...'; 263 264 $objLum->htmlEmpty = '<p><strong>'. __('No errors.').'</strong></p>'; 265 $objLum->htmlLinksLib = __('page(s):'); 266 267 echo $objLum->drawLinks(); 268 echo $objLum->drawPage(); 269 echo $objLum->drawLinks(); 270 271 ?> 272 <?php else: 273 /*======================================== 274 Display the redirections 275 ========================================*/ 276 $px_old = (empty($px_old) && !empty($_GET['old'])) ? $_GET['old'] : '/'; 277 $px_new = (!empty($px_new)) ? $px_new : 'http://'; 278 279 ?> 280 <h2><?php echo __('Current redirections'); ?></h2> 281 282 <?php 283 284 $objLum = new lum($env, 'line_red', $red_list, 0, 20); 285 286 $objLum->htmlHeader = '<table class="clean-table">'."\n".'<tr><th>'.__('Old page').'</th><th>'.__('Redirection').'</th><th>'.__('Last').'</th><th colspan="2">'.__('Count').'</th></tr>'."\n"; 287 $objLum->htmlLineStart = ''; 288 $objLum->htmlColStart = ''; 289 $objLum->htmlColEnd = ''; 290 $objLum->htmlLineEnd = ''; 291 $objLum->htmlFooter = '</table>'."\n"; 292 293 $objLum->htmlLinksStart = '<p class="small">'; 294 $objLum->htmlLinksEnd = '</p>'; 295 296 $objLum->htmlCurPgStart = '<strong>'; 297 $objLum->htmlCurPgEnd = '</strong>'; 298 299 $objLum->htmlPrev = __('« previous page'); 300 $objLum->htmlNext = __('» next page'); 301 $objLum->htmlPrevGrp = '...'; 302 $objLum->htmlNextGrp = '...'; 303 304 $objLum->htmlEmpty = '<p><strong>'. __('No redirection for the moment.').'</strong></p>'; 305 $objLum->htmlLinksLib = __('page(s):'); 306 307 echo $objLum->drawLinks(); 308 echo $objLum->drawPage(); 309 echo $objLum->drawLinks(); 310 311 312 ?> 313 314 <h2 id="create"><?php echo __('Create a redirection'); ?></h2> 315 316 <form action="tools.php" method="post" id="formPost"> 317 <p class="field"><label class="nowrap" for="s_old" style="display:inline"><strong><?php echo __('Old page:'); ?></strong></label> 318 <?php echo form::textField('s_old', 50, 200, $px_old, '', ''); ?><br /> 319 <?php echo __('The old page starts with <strong>/</strong> like <strong>/folder/oldpage.html</strong>'); ?> 320 </p> 321 <p class="field"><label class="nowrap" for="s_new" style="display:inline"><strong><?php echo __('New page:'); ?></strong></label> 322 <?php echo form::textField('s_new', 50, 200, $px_new, '', ''); ?><br /> 323 <?php echo __('Provide the page where you want to send people looking for the old page.'); ?> 324 </p> 325 326 <p> 327 <?php echo form::hidden('p','smart404'); ?> 328 <?php echo form::hidden('op','red'); ?> 329 <input name="save" type="submit" class="submit" value="<?php echo __('Create the redirection'); ?>" accesskey="s" /> 330 </p> 331 </form> 332 333 334 <?php endif; ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 11:57:01 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |