function process_bulk_action() { if ('delete' === $this->current_action()) { foreach ($_POST['item'] as $id) { AT_Audit::delete(intval($id)); } } }
function at_close($item) { if (check_ajax_referer('audittrail_view')) { $id = intval($_POST['id']); $item = AT_Audit::get($id); $this->render_admin('trail_item', array('item' => $item)); die; } }
/** * Displays the admin screen * * @return void **/ function admin_screen() { if (!current_user_can('edit_plugins') && !current_user_can('audit_trail')) { return; } // Decide what to do $sub = $this->submenu(); AT_Audit::expire(get_option('audit_expiry') === false ? 30 : get_option('audit_expiry')); if ($sub == '') { $this->screen_trail(); } else { if ($sub == 'options') { $this->screen_options(); } else { if ($sub == 'support') { $this->render_admin('support'); } } } }
function escape($value) { // Escape any special values $double = false; if (strpos($value, ',') !== false) { $double = true; } if (strpos($value, '"') !== false) { $double = true; $value = str_replace('"', '""', $value); } if ($double) { $value = '"' . $value . '"'; } return $value; } header('Content-Disposition: attachment; filename="audit-trail.csv"'); $trail = AT_Audit::get_everything(); if (count($trail) > 0) { echo "Date,Time,User,Operation,Item,IP\r\n"; foreach ($trail as $item) { $csv = array(); $csv[] = escape(date('Y-m-d', $item->happened_at)); $csv[] = escape(date('H:i', $item->happened_at)); $csv[] = escape($item->username); $csv[] = escape(strip_tags($item->get_operation())); $csv[] = escape(strip_tags($item->get_item())); $csv[] = escape(long2ip($item->ip)); echo implode(',', $csv) . "\r\n"; } }
function drainhole_upload($hole) { AT_Audit::create('drainhole_upload', $hole->id, serialize($hole)); }
/** * Create a new log item * * @param string $operation What function is being monitored (e.g. 'save_post') * @param int $item ID to the item being monitored (e.g post ID, comment ID) * @param string $data Any data associated with the item (e.g. the post) * @param string $title A title string in case the data may change in the future (i.e the current post title) * @param int $user The user ID (if different from the current user) * @return void **/ static function create($operation, $item = '', $data = '', $title = '', $user = false) { global $wpdb, $user_ID; $ip = AT_Audit::get_ip(); $ip = sprintf('%u', ip2long($ip)); if ($user === false) { $user = $user_ID; } $data = maybe_serialize($data); $values = array('user_id' => $user, 'ip' => $ip, 'operation' => $operation, 'item_id' => $item, 'happened_at' => current_time('mysql'), 'data' => maybe_serialize($data), 'title' => $title); $wpdb->insert($wpdb->prefix . 'audit_trail', $values); }
function template_redirect() { // Don't log 404's if (!is_404()) { global $post, $posts; if (isset($_GET['preview']) && $_GET['preview'] == 'true') { return; } AT_Audit::create('template_redirect', count($posts) > 1 ? 0 : $post->ID, $_SERVER['REQUEST_URI']); } }