diff --git a/modules/calendar/calendar.php b/modules/calendar/calendar.php index 2d20b016..b3ea8cb2 100644 --- a/modules/calendar/calendar.php +++ b/modules/calendar/calendar.php @@ -21,7 +21,7 @@ class EF_Calendar extends EF_Module { var $max_visible_posts_per_date = 4; // total number of posts to be shown per square before 'more' link private $post_date_cache = array(); - private static $post_li_html_cache_key = 'ef_calendar_post_li_html'; + private static $post_li_details_cache_key = 'ef_calendar_post_li_html'; private int $max_weeks; private string $create_post_cap; @@ -899,20 +899,31 @@ function view_calendar() { * @return str HTML for a single post item */ function generate_post_li_html( $post, $post_date, $num = 0 ){ + + $user_can_modify_post = $this->current_user_can_modify_post( $post ); + $cache_key = $this->get_post_li_cache_key( $post->ID ); - $can_modify = ( $this->current_user_can_modify_post( $post ) ) ? 'can_modify' : 'read_only'; - $cache_key = $post->ID . $can_modify . '_' . get_current_user_id(); - $cache_val = wp_cache_get( $cache_key, self::$post_li_html_cache_key ); - // Because $num is pertinent to the display of the post LI, need to make sure that's what's in cache + $cache_val = wp_cache_get( $cache_key, self::$post_li_details_cache_key ); + + $post_details = array(); + if ( is_array( $cache_val ) && $cache_val['num'] == $num ) { $this->hidden = $cache_val['hidden']; - return $cache_val['post_li_html']; + $post_details = $cache_val['post_details']; + } else { + $post_details = $this->get_post_information_fields( $post ); + + $post_li_cache = array( + 'num' => $num, + 'post_details' => $post_details, + 'hidden' => $this->hidden, + ); + + wp_cache_set( $cache_key, $post_li_cache, self::$post_li_details_cache_key ); } - ob_start(); - $post_id = $post->ID; - $edit_post_link = get_edit_post_link( $post_id ); - $status_object = get_post_status_object( get_post_status( $post_id ) ); + $status_object = get_post_status_object( get_post_status( $post ) ); + $post_classes = array( 'day-item', @@ -921,7 +932,7 @@ function generate_post_li_html( $post, $post_date, $num = 0 ){ // Only allow the user to drag the post if they have permissions to // or if it's in an approved post status // This is checked on the ajax request too. - if ( $this->current_user_can_modify_post( $post ) && !in_array( $post->post_status, $this->published_statuses ) ) + if ( $user_can_modify_post && !in_array( $post->post_status, $this->published_statuses ) ) $post_classes[] = 'sortable'; if ( in_array( $post->post_status, $this->published_statuses ) ) @@ -934,8 +945,11 @@ function generate_post_li_html( $post, $post_date, $num = 0 ){ $post_classes[] = 'hidden'; $this->hidden++; } + $post_classes = apply_filters( 'ef_calendar_table_td_li_classes', $post_classes, $post_date, $post->ID ); + ob_start(); + ?>
  • @@ -943,12 +957,63 @@ function generate_post_li_html( $post, $post_date, $num = 0 ){
    label ); ?>
    - ID ) ); ?> +
    ID ); ?>
    - get_inner_information( $this->get_post_information_fields( $post ), $post ); ?> + + $values ): ?> + + + + + + + + + + + + + + + + + + + + ID ); ?> +
    :
    + current_user_can_modify_post( $post ) ) { + // Edit this post + $item_actions['edit'] = '' . __( 'Edit', 'edit-flow' ) . ''; + // Trash this post + $item_actions['trash'] = '' . __( 'Trash', 'edit-flow' ) . ''; + // Preview/view this post + if ( !in_array( $post->post_status, $this->published_statuses ) ) { + $item_actions['view'] = '' . __( 'Preview', 'edit-flow' ) . ''; + } elseif ( 'trash' != $post->post_status ) { + $item_actions['view'] = '' . __( 'View', 'edit-flow' ) . ''; + } + //Save metadata + $item_actions['save hidden'] = '' . __( 'Save', 'edit-flow') . ''; + } + // Allow other plugins to add actions + $item_actions = apply_filters( 'ef_calendar_item_actions', $item_actions, $post->ID ); + if ( count( $item_actions ) ) { + echo '
    '; + $html = ''; + foreach ( $item_actions as $class => $item_action ) { + $html .= '' . $item_action . ' | '; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + } + echo rtrim( $html, '| ' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo '
    '; + } + ?> +
  • @@ -957,17 +1022,20 @@ function generate_post_li_html( $post, $post_date, $num = 0 ){ $post_li_html = ob_get_contents(); ob_end_clean(); - $post_li_cache = array( - 'num' => $num, - 'post_li_html' => $post_li_html, - 'hidden' => $this->hidden, - ); - wp_cache_set( $cache_key, $post_li_cache, self::$post_li_html_cache_key ); - return $post_li_html; } // generate_post_li_html() + /** + * Returns the cache key for the post li cache + * @param int $post_id The id of the post + * + * @return str The cache key + */ + function get_post_li_cache_key( $post_id ) { + return 'ef_calendar_post_details_' . $post_id; + } + /** * get_inner_information description * Functionality for generating the inner html elements on the calendar @@ -1727,8 +1795,7 @@ function sanitize_filter( $key, $dirty_value ) { */ public function action_clean_li_html_cache( $post_id ) { - wp_cache_delete( $post_id . 'can_modify', self::$post_li_html_cache_key ); - wp_cache_delete( $post_id . 'read_only', self::$post_li_html_cache_key ); + wp_cache_delete( $this->get_post_li_cache_key( $post_id ), self::$post_li_details_cache_key ); } /**