Exemplo n.º 1
0
    public function RenderWidget()
    {
        $results = WSAL_DB_Occurrence::LoadMulti(' 1 ORDER BY created_on DESC LIMIT ' . $this->_plugin->settings->GetDashboardWidgetMaxAlerts());
        ?>
<div><?php 
        if (!count($results)) {
            ?>
<p><?php 
            _e('No alerts found.', 'wp-security-audit-log');
            ?>
</p><?php 
        } else {
            ?>
<table class="wp-list-table widefat" cellspacing="0" cellpadding="0"
					   style="display: block; overflow-x: auto;">
					<thead>
						<th class="manage-column" style="width: 15%;" scope="col"><?php 
            _e('User', 'wp-security-audit-log');
            ?>
</th>
						<th class="manage-column" style="width: 85%;" scope="col"><?php 
            _e('Description', 'wp-security-audit-log');
            ?>
</th>
					</thead>
					<tbody><?php 
            $url = 'admin.php?page=' . $this->_plugin->views->views[0]->GetSafeViewName();
            $fmt = array(new WSAL_Views_AuditLogList_Internal($this->_plugin), 'meta_formatter');
            foreach ($results as $entry) {
                ?>
<tr>
								<td><?php 
                echo ($un = $entry->GetUsername()) ? esc_html($un) : '<i>unknown</i>';
                ?>
</td>
								<td>
									<a href="<?php 
                echo $url . '#Event' . $entry->id;
                ?>
"><?php 
                echo $entry->GetMessage($fmt);
                ?>
</a>
								</td>
							</tr><?php 
            }
            ?>
</tbody>
				</table><?php 
        }
        ?>
</div><?php 
    }
Exemplo n.º 2
0
 public function CleanUp()
 {
     $now = current_time('timestamp');
     $max_count = $this->plugin->settings->GetPruningLimit();
     $max_sdate = $this->plugin->settings->GetPruningDate();
     $max_stamp = $now - (strtotime($max_sdate) - $now);
     $cnt_items = WSAL_DB_Occurrence::Count();
     if ($cnt_items == $max_count) {
         return;
     }
     $max_items = max($cnt_items - $max_count + 1, 0);
     $is_date_e = $this->plugin->settings->IsPruningDateEnabled();
     $is_limt_e = $this->plugin->settings->IsPruningLimitEnabled();
     switch (true) {
         case $is_date_e && $is_limt_e:
             $cond = 'created_on < %d ORDER BY created_on ASC LIMIT %d';
             $args = array($max_stamp, $max_items);
             break;
         case $is_date_e && !$is_limt_e:
             $cond = 'created_on < %d';
             $args = array($max_stamp);
             break;
         case !$is_date_e && $is_limt_e:
             $cond = '1 ORDER BY created_on ASC LIMIT %d';
             $args = array($max_items);
             break;
         case !$is_date_e && !$is_limt_e:
             return;
     }
     if (!isset($cond)) {
         return;
     }
     $items = WSAL_DB_Occurrence::LoadMulti($cond, $args);
     if (!count($items)) {
         return;
     }
     foreach ($items as $item) {
         $item->Delete();
     }
     do_action('wsal_prune', $items, vsprintf($cond, $args));
 }
Exemplo n.º 3
0
 public function prepare_items()
 {
     $per_page = $this->_plugin->settings->GetViewPerPage();
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     $this->_column_headers = array($columns, $hidden, $sortable);
     //$this->process_bulk_action();
     $bid = (int) $this->get_view_site_id();
     $sql = ($bid ? "site_id={$bid}" : '1') . ' ORDER BY created_on DESC';
     $data = WSAL_DB_Occurrence::LoadMulti($sql, array());
     if (count($data)) {
         $this->_orderby = !empty($_REQUEST['orderby']) && isset($sortable[$_REQUEST['orderby']]) ? $_REQUEST['orderby'] : 'created_on';
         $this->_order = !empty($_REQUEST['order']) && $_REQUEST['order'] == 'asc' ? 'asc' : 'desc';
         if (isset($data[0]->{$this->_orderby})) {
             $numorder = in_array($this->_orderby, array('code', 'type', 'created_on'));
             usort($data, array($this, $numorder ? 'reorder_items_int' : 'reorder_items_str'));
         }
     }
     $current_page = $this->get_pagenum();
     $total_items = count($data);
     $data = array_slice($data, ($current_page - 1) * $per_page, $per_page);
     $this->items = $data;
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
 }