Textpattern | PHP Cross Reference | Content Management Systems |
Description: Visitor logs panel.
1 <?php 2 3 /* 4 * Textpattern Content Management System 5 * http://textpattern.com 6 * 7 * Copyright (C) 2005 Dean Allen 8 * Copyright (C) 2016 The Textpattern Development Team 9 * 10 * This file is part of Textpattern. 11 * 12 * Textpattern is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU General Public License 14 * as published by the Free Software Foundation, version 2. 15 * 16 * Textpattern is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with Textpattern. If not, see <http://www.gnu.org/licenses/>. 23 */ 24 25 /** 26 * Visitor logs panel. 27 * 28 * @package Admin\Log 29 */ 30 31 use Textpattern\Search\Filter; 32 33 if (!defined('txpinterface')) { 34 die('txpinterface is undefined.'); 35 } 36 37 if ($event == 'log') { 38 if (get_pref('logging') === 'none' || !intval(get_pref('expire_logs_after'))) { 39 require_privs(); 40 } 41 42 require_privs('log'); 43 44 $available_steps = array( 45 'log_list' => false, 46 'log_change_pageby' => true, 47 'log_multi_edit' => true, 48 ); 49 50 if ($step && bouncer($step, $available_steps)) { 51 $step(); 52 } else { 53 log_list(); 54 } 55 } 56 57 /** 58 * The main panel listing all log hits. 59 * 60 * @param string|array $message The activity message 61 */ 62 63 function log_list($message = '') 64 { 65 global $event, $log_list_pageby, $expire_logs_after; 66 67 pagetop(gTxt('tab_logs'), $message); 68 69 extract(gpsa(array( 70 'page', 71 'sort', 72 'dir', 73 'crit', 74 'search_method', 75 ))); 76 77 if ($sort === '') { 78 $sort = get_pref('log_sort_column', 'time'); 79 } else { 80 if (!in_array($sort, array('ip', 'host', 'page', 'refer', 'method', 'status'))) { 81 $sort = 'time'; 82 } 83 84 set_pref('log_sort_column', $sort, 'log', 2, '', 0, PREF_PRIVATE); 85 } 86 87 if ($dir === '') { 88 $dir = get_pref('log_sort_dir', 'desc'); 89 } else { 90 $dir = ($dir == 'asc') ? "asc" : "desc"; 91 set_pref('log_sort_dir', $dir, 'log', 2, '', 0, PREF_PRIVATE); 92 } 93 94 $expire_logs_after = assert_int($expire_logs_after); 95 96 safe_delete('txp_log', "time < DATE_SUB(NOW(), INTERVAL $expire_logs_after DAY)"); 97 98 switch ($sort) { 99 case 'ip': 100 $sort_sql = "ip $dir"; 101 break; 102 case 'host': 103 $sort_sql = "host $dir"; 104 break; 105 case 'page': 106 $sort_sql = "page $dir"; 107 break; 108 case 'refer': 109 $sort_sql = "refer $dir"; 110 break; 111 case 'method': 112 $sort_sql = "method $dir"; 113 break; 114 case 'status': 115 $sort_sql = "status $dir"; 116 break; 117 default: 118 $sort = 'time'; 119 $sort_sql = "time $dir"; 120 break; 121 } 122 123 $switch_dir = ($dir == 'desc') ? 'asc' : 'desc'; 124 125 $search = new Filter($event, 126 array( 127 'ip' => array( 128 'column' => 'txp_log.ip', 129 'label' => gTxt('IP'), 130 ), 131 'host' => array( 132 'column' => 'txp_log.host', 133 'label' => gTxt('host'), 134 ), 135 'page' => array( 136 'column' => 'txp_log.page', 137 'label' => gTxt('page'), 138 ), 139 'refer' => array( 140 'column' => 'txp_log.refer', 141 'label' => gTxt('referrer'), 142 ), 143 'method' => array( 144 'column' => 'txp_log.method', 145 'label' => gTxt('method'), 146 ), 147 'status' => array( 148 'column' => 'txp_log.status', 149 'label' => gTxt('status'), 150 'type' => 'integer', 151 ), 152 ) 153 ); 154 155 list($criteria, $crit, $search_method) = $search->getFilter(array( 156 'status' => array('can_list' => true), 157 )); 158 159 $search_render_options = array( 160 'placeholder' => 'search_logs', 161 ); 162 163 $total = safe_count('txp_log', "$criteria"); 164 165 echo n.'<div class="txp-layout">'. 166 n.tag( 167 hed(gTxt('tab_logs'), 1, array('class' => 'txp-heading')), 168 'div', array('class' => 'txp-layout-4col-alt') 169 ); 170 171 $searchBlock = 172 n.tag( 173 $search->renderForm('log_list', $search_render_options), 174 'div', array( 175 'class' => 'txp-layout-4col-3span', 176 'id' => $event.'_control', 177 ) 178 ); 179 180 $contentBlockStart = n.tag_start('div', array( 181 'class' => 'txp-layout-1col', 182 'id' => $event.'_container', 183 )); 184 185 if ($total < 1) { 186 if ($criteria != 1) { 187 echo $searchBlock. 188 $contentBlockStart. 189 graf( 190 span(null, array('class' => 'ui-icon ui-icon-info')).' '. 191 gTxt('no_results_found'), 192 array('class' => 'alert-block information') 193 ); 194 } else { 195 echo $contentBlockStart. 196 graf( 197 span(null, array('class' => 'ui-icon ui-icon-info')).' '. 198 gTxt('no_refers_recorded'), 199 array('class' => 'alert-block information') 200 ); 201 } 202 203 echo n.tag_end('div'). // End of .txp-layout-1col. 204 n.'</div>'; // End of .txp-layout. 205 206 return; 207 } 208 209 $limit = max($log_list_pageby, 15); 210 211 list($page, $offset, $numPages) = pager($total, $limit, $page); 212 213 echo $searchBlock.$contentBlockStart; 214 215 $rs = safe_rows_start( 216 "*, UNIX_TIMESTAMP(time) AS uTime", 217 'txp_log', 218 "$criteria ORDER BY $sort_sql LIMIT $offset, $limit" 219 ); 220 221 if ($rs) { 222 echo n.tag( 223 toggle_box('log_detail'), 'div', array('class' => 'txp-list-options')). 224 n.tag_start('form', array( 225 'class' => 'multi_edit_form', 226 'id' => 'log_form', 227 'name' => 'longform', 228 'method' => 'post', 229 'action' => 'index.php', 230 )). 231 n.tag_start('div', array('class' => 'txp-listtables')). 232 n.tag_start('table', array('class' => 'txp-list')). 233 n.tag_start('thead'). 234 tr( 235 hCell( 236 fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), 237 '', ' class="txp-list-col-multi-edit" scope="col" title="'.gTxt('toggle_all_selected').'"' 238 ). 239 column_head( 240 'time', 'time', 'log', true, $switch_dir, $crit, $search_method, 241 (('time' == $sort) ? "$dir " : '').'txp-list-col-time' 242 ). 243 column_head( 244 'IP', 'ip', 'log', true, $switch_dir, $crit, $search_method, 245 (('ip' == $sort) ? "$dir " : '').'txp-list-col-ip' 246 ). 247 column_head( 248 'host', 'host', 'log', true, $switch_dir, $crit, $search_method, 249 (('host' == $sort) ? "$dir " : '').'txp-list-col-host log_detail' 250 ). 251 column_head( 252 'page', 'page', 'log', true, $switch_dir, $crit, $search_method, 253 (('page' == $sort) ? "$dir " : '').'txp-list-col-page' 254 ). 255 column_head( 256 'referrer', 'refer', 'log', true, $switch_dir, $crit, $search_method, 257 (('refer' == $sort) ? "$dir " : '').'txp-list-col-refer' 258 ). 259 column_head( 260 'method', 'method', 'log', true, $switch_dir, $crit, $search_method, 261 (('method' == $sort) ? "$dir " : '').'txp-list-col-method log_detail' 262 ). 263 column_head( 264 'status', 'status', 'log', true, $switch_dir, $crit, $search_method, 265 (('status' == $sort) ? "$dir " : '').'txp-list-col-status log_detail' 266 ) 267 ). 268 n.tag_end('thead'). 269 n.tag_start('tbody'); 270 271 while ($a = nextRow($rs)) { 272 extract($a, EXTR_PREFIX_ALL, 'log'); 273 274 if ($log_refer) { 275 $log_refer = href(txpspecialchars(soft_wrap(preg_replace('#^http://#', '', $log_refer), 30)), txpspecialchars($log_refer), ' target="_blank"'); 276 } 277 278 if ($log_page) { 279 $log_anchor = preg_replace('/\/$/', '', $log_page); 280 $log_anchor = soft_wrap(substr($log_anchor, 1), 30); 281 282 $log_page = href(txpspecialchars($log_anchor), txpspecialchars($log_page), ' target="_blank"'); 283 284 if ($log_method == 'POST') { 285 $log_page = strong($log_page); 286 } 287 } 288 289 echo tr( 290 td( 291 fInput('checkbox', 'selected[]', $log_id), '', 'txp-list-col-multi-edit' 292 ). 293 hCell( 294 gTime($log_uTime), '', ' class="txp-list-col-time" scope="row"' 295 ). 296 td( 297 href(txpspecialchars($log_ip), 'https://whois.domaintools.com/'.rawurlencode($log_ip), array( 298 'rel' => 'external', 299 'target' => '_blank', 300 )), '', 'txp-list-col-ip' 301 ). 302 td( 303 txpspecialchars($log_host), '', 'txp-list-col-host log_detail' 304 ). 305 td( 306 $log_page, '', 'txp-list-col-page' 307 ). 308 td( 309 $log_refer, '', 'txp-list-col-refer' 310 ). 311 td( 312 txpspecialchars($log_method), '', 'txp-list-col-method log_detail' 313 ). 314 td( 315 $log_status, '', 'txp-list-col-status log_detail' 316 ) 317 ); 318 } 319 320 echo 321 n.tag_end('tbody'). 322 n.tag_end('table'). 323 n.tag_end('div'). // End of .txp-listtables. 324 log_multiedit_form($page, $sort, $dir, $crit, $search_method). 325 tInput(). 326 n.tag_end('form'). 327 n.tag_start('div', array( 328 'class' => 'txp-navigation', 329 'id' => $event.'_navigation', 330 )). 331 pageby_form('log', $log_list_pageby). 332 nav_form('log', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit). 333 n.tag_end('div'); 334 } 335 336 echo n.tag_end('div'). // End of .txp-layout-1col. 337 n.'</div>'; // End of .txp-layout. 338 } 339 340 /** 341 * Saves a new pageby value to the server. 342 */ 343 344 function log_change_pageby() 345 { 346 event_change_pageby('log'); 347 log_list(); 348 } 349 350 /** 351 * Renders a multi-edit widget. 352 * 353 * @param int $page The page number 354 * @param string $sort The current sorting value 355 * @param string $dir The current sorting direction 356 * @param string $crit The current search criteria 357 * @param string $search_method The current search method 358 * @return string HTML 359 */ 360 361 function log_multiedit_form($page, $sort, $dir, $crit, $search_method) 362 { 363 $methods = array( 364 'delete' => gTxt('delete'), 365 ); 366 367 return multi_edit($methods, 'log', 'log_multi_edit', $page, $sort, $dir, $crit, $search_method); 368 } 369 370 /** 371 * Processes multi-edit actions. 372 */ 373 374 function log_multi_edit() 375 { 376 $deleted = event_multi_edit('txp_log', 'id'); 377 378 if ($deleted) { 379 $message = gTxt('logs_deleted', array('{list}' => $deleted)); 380 381 return log_list($message); 382 } 383 384 return log_list(); 385 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
title