_allow_caps ) ) {
$user = get_user_by( 'id', get_current_user_id() );
if ( ! $user ) {
wp_die( 'Not allowed here.' );
}
$user_cap = strtolower( key( $user->caps ) );
$allow_caps = array();
foreach ( $this->_caps as $key => $cap_allow ) {
if ( $key === $user_cap ) {
$allow_caps = array_merge( $allow_caps, $cap_allow );
break;
}
}
// TODO: Find better way to Multisite compatibility.
if ( is_super_admin() || current_user_can( 'view_all_aryo_activity_log' ) ) {
$allow_caps = $this->_caps['administrator'];
}
if ( empty( $allow_caps ) ) {
wp_die( 'Not allowed here.' );
}
$this->_allow_caps = array_unique( $allow_caps );
}
return $this->_allow_caps;
}
protected function _get_where_by_role() {
$allow_modules = array();
foreach ( $this->_roles as $key => $role ) {
if ( current_user_can( $key ) || current_user_can( 'view_all_aryo_activity_log' ) ) {
$allow_modules = array_merge( $allow_modules, $role );
}
}
if ( empty( $allow_modules ) ) {
wp_die( 'Not allowed here.' );
}
$allow_modules = array_unique( $allow_modules );
$where = array();
foreach ( $allow_modules as $type )
$where[] .= '`object_type` = \'' . $type . '\'';
$where_caps = array();
foreach ( $this->_get_allow_caps() as $cap )
$where_caps[] .= '`user_caps` = \'' . $cap . '\'';
return 'AND (' . implode( ' OR ', $where ) . ') AND (' . implode( ' OR ', $where_caps ) . ')';
}
public function get_action_label( $action ) {
return ucwords( str_replace( '_', ' ', __( $action, 'aryo-activity-log' ) ) );
}
public function __construct( $args = array() ) {
parent::__construct(
array(
'singular' => 'activity',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
)
);
$this->_roles = apply_filters(
'aal_init_roles',
array(
// admin
'manage_options' => array( 'Core', 'Export', 'Post', 'Taxonomy', 'User', 'Options', 'Attachment', 'Plugin', 'Widget', 'Theme', 'Menu', 'Comments' ),
// editor
'edit_pages' => array( 'Post', 'Taxonomy', 'Attachment', 'Comments' ),
)
);
$this->_caps = apply_filters(
'aal_init_caps',
array(
'administrator' => array( 'administrator', 'editor', 'author', 'guest' ),
'editor' => array( 'editor', 'author', 'guest' ),
'author' => array( 'author', 'guest' ),
)
);
add_screen_option(
'per_page',
array(
'default' => 50,
'label' => __( 'Activities', 'aryo-activity-log' ),
'option' => 'edit_aal_logs_per_page',
)
);
add_filter( 'set-screen-option', array( &$this, 'set_screen_option' ), 10, 3 );
set_screen_options();
}
public function get_columns() {
$columns = array(
'date' => __( 'Date', 'aryo-activity-log' ),
'author' => __( 'Author', 'aryo-activity-log' ),
'ip' => __( 'IP', 'aryo-activity-log' ),
'type' => __( 'Type', 'aryo-activity-log' ),
'label' => __( 'Label', 'aryo-activity-log' ),
'action' => __( 'Action', 'aryo-activity-log' ),
'description' => __( 'Description', 'aryo-activity-log' ),
);
return $columns;
}
public function get_sortable_columns() {
return array(
'ip' => 'hist_ip',
'date' => array( 'hist_time', true ),
);
}
public function column_default( $item, $column_name ) {
$return = '';
switch ( $column_name ) {
case 'action' :
$return = $this->get_action_label( $item->action );
break;
case 'date' :
$return = sprintf( '' . __( '%s ago', 'aryo-activity-log' ) . '', human_time_diff( $item->hist_time, current_time( 'timestamp' ) ) );
$return .= '
' . date( 'd/m/Y', $item->hist_time );
$return .= '
' . date( 'H:i:s', $item->hist_time );
break;
case 'ip' :
$return = $item->hist_ip;
break;
default :
if ( isset( $item->$column_name ) )
$return = $item->$column_name;
}
$return = apply_filters( 'aal_table_list_column_default', $return, $item, $column_name );
return $return;
}
public function column_author( $item ) {
global $wp_roles;
if ( ! empty( $item->user_id ) && 0 !== (int) $item->user_id ) {
$user = get_user_by( 'id', $item->user_id );
if ( $user instanceof WP_User && 0 !== $user->ID ) {
//$user->display_name
return sprintf(
'%s
%s',
get_edit_user_link( $user->ID ),
get_avatar( $user->ID, 40 ),
$user->display_name,
isset( $user->roles[0] ) && isset( $wp_roles->role_names[ $user->roles[0] ] ) ? $wp_roles->role_names[ $user->roles[0] ] : __( 'Unknown', 'aryo-activity-log' )
);
}
}
return sprintf(
'',
__( 'N/A', 'aryo-activity-log' )
);
}
public function column_type( $item ) {
$return = __( $item->object_type, 'aryo-activity-log' );
$return = apply_filters( 'aal_table_list_column_type', $return, $item );
return $return;
}
public function column_label( $item ) {
$return = '';
if ( ! empty( $item->object_subtype ) ) {
$pt = get_post_type_object( $item->object_subtype );
$return = ! empty( $pt->label ) ? $pt->label : $item->object_subtype;
}
$return = apply_filters( 'aal_table_list_column_label', $return, $item );
return $return;
}
public function column_description( $item ) {
$return = esc_html( $item->object_name );
switch ( $item->object_type ) {
case 'Post' :
$return = sprintf( '%s', get_edit_post_link( $item->object_id ), esc_html( $item->object_name ) );
break;
case 'Taxonomy' :
if ( ! empty( $item->object_id ) )
$return = sprintf( '%s', get_edit_term_link( $item->object_id, $item->object_subtype ), esc_html( $item->object_name ) );
break;
case 'Comments' :
if ( ! empty( $item->object_id ) && $comment = get_comment( $item->object_id ) ) {
$return = sprintf( '%s #%d', get_edit_comment_link( $item->object_id ), $item->object_name, $item->object_id );
}
break;
case 'Export' :
if ( 'all' === $item->object_name ) {
$return = __( 'All', 'aryo-activity-log' );
} else {
$pt = get_post_type_object( $item->object_name );
$return = ! empty( $pt->label ) ? $pt->label : $item->object_name;
}
break;
case 'Options' :
case 'Core' :
$return = __( $item->object_name, 'aryo-activity-log' );
break;
}
$return = apply_filters( 'aal_table_list_column_description', $return, $item );
return $return;
}
public function display_tablenav( $which ) {
if ( 'top' == $which ) {
$this->search_box( __( 'Search', 'aryo-activity-log' ), 'aal-search' );
}
?>
'search-submit') ); ?>