/** * Constructor gets stored data from DB * * @access public */ function __construct() { $this->_seen_entries = array(); $this->settings = clgs_get_settings(); parent::__construct(array('singular' => 'entry_id', 'plural' => 'entries', 'ajax' => false)); }
/** * render log page * * @global string $pagenow * @global Clgs_DB $clgs_db * * @return void */ function clgs_manager_page() { global $pagenow, $clgs_db; extract(clgs_get_settings()); /*** Input sanitation ***/ $attrs = clgs_evaluate($_REQUEST, array('min_severity' => array('sanitize' => 'int', 'validate' => 'severity', 'default' => $def_severity_filter), 'seen' => array('sanitize' => 'bool', 'validate' => 'exists', 'default' => false), 'category' => array('sanitize' => 'string', 'validate' => 'registered'), 'entry_id' => array('sanitize' => 'int', 'validate' => 'positive'), 'orderby' => array('sanitize' => 'string', 'validate_array' => ['date', 'category', 'user_name', 'blog_name', 'severity'], 'default' => 'date'), 'order' => array('sanitize' => 'toupper_string', 'validate_array' => ['ASC', 'DESC'], 'default' => 'ASC'))); extract($attrs); //var_dump( $attrs ); /*** Render ***/ $table = new Clgs_Manager_Table(); $pageurl = add_query_arg('page', CLGS_LOG_PAGE, $pagenow); $pageurl = add_query_arg(compact('seen', 'min_severity'), $pageurl); // Show a single entry or a list? if (isset($entry_id)) { unset($attrs['category']); } ?> <div class="wrap"> <h1><?php _e('Application logs', 'custom-logging-service'); ?> </h1> <?php if (isset($attrs['category'])) { // single log category $log = $clgs_db->get_log($attrs['category']); $actionurl = wp_nonce_url(add_query_arg('category', urlencode($attrs['category']), $pageurl), 'bulk-category'); ?> <h2><?php echo __('Log category', 'custom-logging-service') . ': ' . $log->category; ?> </h2> <p><?php echo $log->description; ?> </p> <p> <a href="<?php echo $actionurl . '&action=mark-category'; ?> " title="<?php _e("Mark whole category as read", 'custom-logging-service'); ?> " ><?php _e('Mark whole category as read', 'custom-logging-service'); ?> </a> | <a href="<?php echo $actionurl . '&action=clear'; ?> " title="<?php _e("Remove all log entries from this category", 'custom-logging-service'); ?> "><?php _e('Clear', 'custom-logging-service'); ?> </a> | <a href="<?php echo $actionurl . '&action=unregister'; ?> " title="<?php _e("Delete this log category permanently (with all entries)", 'custom-logging-service'); ?> " ><?php _e('Delete', 'custom-logging-service'); ?> </a> | <a href="<?php echo $pageurl; ?> "><?php _e('Show all categories', 'custom-logging-service'); ?> </a> </p> <form method="get"> <input type="hidden" name="page" value="<?php echo CLGS_LOG_PAGE; ?> " /> <input type="hidden" name="action" value="view" /> <input type="hidden" name="category" value="<?php echo $log->category; ?> " /> <?php } else { ?> <h2><?php _e("New log entries from all categories", 'custom-logging-service'); ?> </h2> <form method="get"> <input type="hidden" name="page" value="<?php echo CLGS_LOG_PAGE; ?> " /> <input type="hidden" name="action" value="view" /> <?php } $table->set_attributes($attrs); $table->prepare_items(); $table->display(); ?> </form> <?php if (!isset($attrs['category'])) { // include a log category overview ?> <h2><?php _e('Log categories', 'custom-logging-service'); ?> </h2> <div id="clgs-log-list"><table class="wp-list-table widefat fixed striped"> <?php foreach ($clgs_db->get_logs() as $id => $log) { $caturl = add_query_arg('category', urlencode($log->category), $pageurl); $actionurl = wp_nonce_url($caturl, 'bulk-category'); ?> <tr class="<?php echo $id % 2 === 0 ? 'alternate' : ''; ?> "> <td class="column-primary"> <span><a href="<?php echo $caturl; ?> "><?php echo $log->category; ?> </a></span> <div class="row-actions visible"> <a href="<?php echo $actionurl . '&action=mark-category'; ?> " title="<?php _e("Mark whole category as read", 'custom-logging-service'); ?> " ><?php _e('Mark as read', 'custom-logging-service'); ?> </a> | <a href="<?php echo $actionurl . '&action=clear'; ?> " title="<?php _e("Remove all log entries from this category", 'custom-logging-service'); ?> "><?php _e('Clear', 'custom-logging-service'); ?> </a> | <a href="<?php echo $actionurl . '&action=unregister'; ?> " title="<?php _e("Delete this log category permanently (with all entries)", 'custom-logging-service'); ?> " ><?php _e('Delete', 'custom-logging-service'); ?> </a> </div> <button class="toggle-row" type="button"><span class="screen-reader-text"><?php _e('Show more details'); ?> </span></button> </td> <td><?php echo esc_attr($log->description); ?> </td> <?php } ?> </table></div> <?php } ?> </div> <?php }
/** * echos setting input field * * @global array $severity_list * * @param array $args(mixed) field info * * @return void */ function clgs_field_render($args) { global $severity_list; $id = $args[0]; $options = clgs_get_settings(); if ('log_entries_per_page' == $id) { ?> <input type="text" name="<?php echo CLGS_SETTINGS . "[{$id}]"; ?> " value="<?php echo $options[$id]; ?> "> <?php } elseif ('manager_role' == $id) { $name_attr = CLGS_SETTINGS . "[{$id}][]"; foreach (wp_roles()->get_names() as $key => $name) { $checked = in_array($key, $options[$id]) ? 'checked ' : ''; echo "<label><input type=\"checkbox\" name=\"{$name_attr}\" value=\"{$key}\" {$checked}/>"; echo translate_user_role($name) . "</label><br/>"; } } else { ?> <select name="<?php echo CLGS_SETTINGS . "[{$id}]"; ?> "> <?php foreach ($severity_list as $key => $value) { ?> <option value="<?php echo $key; ?> "<?php if ($key == $options[$id]) { echo ' selected="selected"'; } ?> ><?php echo $value; ?> </option> <?php } ?> </select> <?php } }