'; } /** * Actor label. * * @param array $row Event row. * @return string */ public static function actor( array $row ) { if ( ! empty( $row['user_id'] ) ) { $name = '' !== $row['user_display'] ? $row['user_display'] : $row['user_login']; if ( ! empty( $row['user_role'] ) ) { $name .= ' · ' . $row['user_role']; } return $name; } $initiators = Vocabulary::initiators(); $key = isset( $row['initiator'] ) ? $row['initiator'] : 'anonymous'; return isset( $initiators[ $key ] ) ? $initiators[ $key ] : $key; } /** * Local initial for the person who caused the event. * * Drawn in the browser. This does not call get_avatar() or any remote avatar service. * * @param array $row Event row. * @param int $size Mark size in pixels. Sizes of 30 or less use the compact class. * @return string */ public static function avatar( array $row, $size = 36 ) { $size = max( 16, min( 96, (int) $size ) ); if ( ! empty( Settings::all()['use_gravatar'] ) && ! empty( $row['user_id'] ) && function_exists( 'get_avatar' ) ) { $html = get_avatar( (int) $row['user_id'], $size, '', '', array( 'class' => 'srah-avatar srah-avatar-gravatar', 'force_display' => true, ) ); if ( is_string( $html ) && '' !== $html ) { return $html; } } $name = self::actor( $row ); $letter = function_exists( 'mb_substr' ) ? mb_substr( $name, 0, 1, 'UTF-8' ) : substr( $name, 0, 1 ); $letter = strtoupper( (string) $letter ); if ( '' === $letter ) { $letter = '?'; } $class = 'srah-avatar srah-avatar-local'; if ( $size <= 30 ) { $class .= ' srah-avatar-sm'; } return '' . esc_html( $letter ) . ''; } /** * Row IDs a selection checkbox stands for, comma separated. * * A collapsed group lists every stored row so deleting it removes all repeats. * * @param array $row Event row. * @return string */ public static function selection( array $row ) { $ids = isset( $row['group_ids'] ) && is_array( $row['group_ids'] ) ? $row['group_ids'] : array(); if ( ! $ids && ! empty( $row['id'] ) ) { $ids = array( $row['id'] ); } return implode( ',', array_filter( array_map( 'absint', $ids ) ) ); } /** * One timeline card. * * @param array $row Event row. * @param array $args Display arguments. */ public static function card( array $row, array $args = array() ) { $args = wp_parse_args( $args, array( 'checkbox' => false, 'compact' => false, ) ); $severity = isset( $row['severity'] ) ? $row['severity'] : 'info'; $category = isset( $row['category'] ) ? $row['category'] : 'system'; $when = Time::display( isset( $row['created_gmt'] ) ? $row['created_gmt'] : '', isset( $row['created_ms'] ) ? (int) $row['created_ms'] : 0 ); $id = isset( $row['id'] ) ? (int) $row['id'] : 0; ?>
1 ) : ?>

> 1 ) : ?>

1 ) : ?>
UTC
$lines, 'field' => isset( $change['field'] ) ? (string) $change['field'] : '', ); continue; } $plain_changes[] = $change; } ?>

$value ) : ?>

'srah-thumb' ) ); } echo esc_html( isset( $change[ $side ] ) ? (string) $change[ $side ] : '' ); } /** * Stored line diff, or one rebuilt from the post's revisions. * * @param mixed $change Change row. * @param int $post_id Post ID. * @param int $revision_id Revision recorded with the event. * @return array */ private static function change_lines( $change, $post_id, $revision_id ) { if ( ! is_array( $change ) ) { return array(); } if ( ! empty( $change['lines'] ) && is_array( $change['lines'] ) ) { return $change['lines']; } $has_words = ( ! empty( $change['added'] ) && is_array( $change['added'] ) ) || ( ! empty( $change['removed'] ) && is_array( $change['removed'] ) ); if ( ! $has_words || ! $post_id || ! $revision_id ) { return array(); } return self::revision_hunks( $post_id, $revision_id ); } /** * Diff the recorded revision against the revision just before it. * * On current WordPress the revision saved after an update matches the new text. * * @param int $post_id Post ID. * @param int $revision_id Revision ID stored on the event. * @return array */ private static function revision_hunks( $post_id, $revision_id ) { static $cache = array(); $key = $post_id . ':' . $revision_id; if ( isset( $cache[ $key ] ) ) { return $cache[ $key ]; } $cache[ $key ] = array(); if ( ! function_exists( 'wp_get_post_revisions' ) ) { return $cache[ $key ]; } $current = get_post( $revision_id ); if ( ! $current instanceof \WP_Post ) { return $cache[ $key ]; } if ( $current->post_parent ) { $post_id = (int) $current->post_parent; } $revisions = wp_get_post_revisions( $post_id, array( 'posts_per_page' => 50, 'orderby' => 'date', 'order' => 'ASC', ) ); if ( ! is_array( $revisions ) || ! isset( $revisions[ $revision_id ] ) ) { return $cache[ $key ]; } $before = null; foreach ( $revisions as $revision ) { if ( (int) $revision->ID === (int) $revision_id ) { break; } $before = $revision; } if ( ! $before instanceof \WP_Post ) { return $cache[ $key ]; } $cache[ $key ] = Diff::hunks( $before->post_content, $current->post_content ); return $cache[ $key ]; } /** * GitHub-style added and removed lines. * * @param array $lines Encoded diff rows. * @param string $field Field label. */ private static function patch( array $lines, $field ) { if ( '' === $field ) { $field = __( 'Content', 'admintrace-activity-logger' ); } ?>