Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
204 changes: 97 additions & 107 deletions modules/calendar/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
* Construct the EF_Calendar class
Expand Down Expand Up @@ -856,20 +856,29 @@ 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',
Expand All @@ -878,7 +887,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 ) )
Expand All @@ -891,21 +900,74 @@ 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();

?>
<li class="<?php echo esc_attr( implode( ' ', $post_classes ) ); ?>" id="post-<?php echo esc_attr( $post->ID ); ?>">
<div style="clear:right;"></div>
<div class="item-static">
<div class="item-default-visible">
<div class="item-status"><span class="status-text"><?php echo esc_html( $status_object->label ); ?></span></div>
<div class="inner">
<span class="item-headline post-title"><strong><?php echo esc_html( _draft_or_post_title( $post->ID ) ); ?></strong></span>
<span class="item-headline post-title"><strong><?php echo esc_html( _draft_or_post_title( $post ) ); ?></strong></span>
</div>
<?php do_action( 'ef_calendar_item_html', $post->ID ); ?>
</div>
<div class="item-inner">
<?php $this->get_inner_information( $this->get_post_information_fields( $post ), $post ); ?>
<table class="item-information">
<?php foreach( $post_details as $field => $values ): ?>
<tr class="item-field item-information-<?php echo esc_attr( $field ); ?>">
<th class="label"><?php echo esc_html( $values['label'] ); ?>:</th>
<?php if ( $values['value'] && isset($values['type']) ): ?>
<?php if( isset( $user_can_modify_post ) && $user_can_modify_post ) : ?>
<td class="value<?php if( $user_can_modify_post ) { ?> editable-value<?php } ?>"><?php echo esc_html( $values['value'] ); ?></td>
<?php if( $user_can_modify_post ): ?>
<td class="editable-html hidden" data-type="<?php echo $values['type']; ?>" data-metadataterm="<?php echo str_replace( 'editorial-metadata-', '', str_replace( 'tax_', '', $field ) ); ?>"><?php echo $this->get_editable_html( $values['type'], $values['value'] ); ?></td>
<?php endif; ?>
<?php else: ?>
<td class="value"><?php echo esc_html( $values['value'] ); ?></td>
<?php endif; ?>
<?php elseif( $values['value'] ): ?>
<td class="value"><?php echo esc_html( $values['value'] ); ?></td>
<?php else: ?>
<td class="value"><em class="none"><?php echo _e( 'None', 'edit-flow' ); ?></em></td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
<?php do_action( 'ef_calendar_item_additional_html', $post->ID ); ?>
</table>
<?php
$item_actions = array();
if ( $this->current_user_can_modify_post( $post ) ) {
// Edit this post
$item_actions['edit'] = '<a href="' . get_edit_post_link( $post, true ) . '" title="' . esc_attr( __( 'Edit this item', 'edit-flow' ) ) . '">' . __( 'Edit', 'edit-flow' ) . '</a>';
// Trash this post
$item_actions['trash'] = '<a href="'. get_delete_post_link( $post ) . '" title="' . esc_attr( __( 'Trash this item' ), 'edit-flow' ) . '">' . __( 'Trash', 'edit-flow' ) . '</a>';
// Preview/view this post
if ( !in_array( $post->post_status, $this->published_statuses ) ) {
$item_actions['view'] = '<a href="' . esc_url( apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', get_permalink( $post ) ), $post ) ) . '" title="' . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;', 'edit-flow' ), $post->post_title ) ) . '" rel="permalink">' . __( 'Preview', 'edit-flow' ) . '</a>';
} elseif ( 'trash' != $post->post_status ) {
$item_actions['view'] = '<a href="' . get_permalink( $post ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;', 'edit-flow' ), $post->post_title ) ) . '" rel="permalink">' . __( 'View', 'edit-flow' ) . '</a>';
}
//Save metadata
$item_actions['save hidden'] = '<a href="#savemetadata" id="save-editorial-metadata" class="post-'. $post->ID .'" title="'. esc_attr( sprintf( __( 'Save &#8220;%s&#8221;', 'edit-flow' ), $post->post_title ) ) . '" >' . __( 'Save', 'edit-flow') . '</a>';
}
// Allow other plugins to add actions
$item_actions = apply_filters( 'ef_calendar_item_actions', $item_actions, $post->ID );
if ( count( $item_actions ) ) {
echo '<div class="item-actions">';
$html = '';
foreach ( $item_actions as $class => $item_action ) {
$html .= '<span class="' . esc_attr( $class ) . '">' . $item_action . ' | </span> ';
}
echo rtrim( $html, '| ' );
echo '</div>';
}
?>
<div style="clear:right;"></div>
</div>
</div>
</li>
Expand All @@ -914,85 +976,19 @@ 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()

/**
* get_inner_information description
* Functionality for generating the inner html elements on the calendar
* has been separated out so various ajax functions can reload certain
* parts of an inner html element.
* @param array $ef_calendar_item_information_fields
* @param WP_Post $post
* @param array $published_statuses
*
* @since 0.8
* 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_inner_information( $ef_calendar_item_information_fields, $post ) {
?>
<table class="item-information">
<?php foreach( $this->get_post_information_fields( $post ) as $field => $values ): ?>
<tr class="item-field item-information-<?php echo esc_attr( $field ); ?>">
<th class="label"><?php echo esc_html( $values['label'] ); ?>:</th>
<?php if ( $values['value'] && isset($values['type']) ): ?>
<?php if( isset( $values['editable'] ) && $this->current_user_can_modify_post( $post ) ) : ?>
<td class="value<?php if( $values['editable'] ) { ?> editable-value<?php } ?>"><?php echo esc_html( $values['value'] ); ?></td>
<?php if( $values['editable'] ): ?>
<td class="editable-html hidden" data-type="<?php echo $values['type']; ?>" data-metadataterm="<?php echo str_replace( 'editorial-metadata-', '', str_replace( 'tax_', '', $field ) ); ?>"><?php echo $this->get_editable_html( $values['type'], $values['value'] ); ?></td>
<?php endif; ?>
<?php else: ?>
<td class="value"><?php echo esc_html( $values['value'] ); ?></td>
<?php endif; ?>
<?php elseif( $values['value'] ): ?>
<td class="value"><?php echo esc_html( $values['value'] ); ?></td>
<?php else: ?>
<td class="value"><em class="none"><?php echo _e( 'None', 'edit-flow' ); ?></em></td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
<?php do_action( 'ef_calendar_item_additional_html', $post->ID ); ?>
</table>
<?php
$post_type_object = get_post_type_object( $post->post_type );
$item_actions = array();
if ( $this->current_user_can_modify_post( $post ) ) {
// Edit this post
$item_actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '" title="' . esc_attr( __( 'Edit this item', 'edit-flow' ) ) . '">' . __( 'Edit', 'edit-flow' ) . '</a>';
// Trash this post
$item_actions['trash'] = '<a href="'. get_delete_post_link( $post->ID) . '" title="' . esc_attr( __( 'Trash this item' ), 'edit-flow' ) . '">' . __( 'Trash', 'edit-flow' ) . '</a>';
// Preview/view this post
if ( !in_array( $post->post_status, $this->published_statuses ) ) {
$item_actions['view'] = '<a href="' . esc_url( apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ), $post ) ) . '" title="' . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;', 'edit-flow' ), $post->post_title ) ) . '" rel="permalink">' . __( 'Preview', 'edit-flow' ) . '</a>';
} elseif ( 'trash' != $post->post_status ) {
$item_actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;', 'edit-flow' ), $post->post_title ) ) . '" rel="permalink">' . __( 'View', 'edit-flow' ) . '</a>';
}
//Save metadata
$item_actions['save hidden'] = '<a href="#savemetadata" id="save-editorial-metadata" class="post-'. $post->ID .'" title="'. esc_attr( sprintf( __( 'Save &#8220;%s&#8221;', 'edit-flow' ), $post->post_title ) ) . '" >' . __( 'Save', 'edit-flow') . '</a>';
}
// Allow other plugins to add actions
$item_actions = apply_filters( 'ef_calendar_item_actions', $item_actions, $post->ID );
if ( count( $item_actions ) ) {
echo '<div class="item-actions">';
$html = '';
foreach ( $item_actions as $class => $item_action ) {
$html .= '<span class="' . esc_attr( $class ) . '">' . $item_action . ' | </span> ';
}
echo rtrim( $html, '| ' );
echo '</div>';
}
?>
<div style="clear:right;"></div>
<?php

} // generate_post_li_html()
function get_post_li_cache_key( $post_id ) {
return 'ef_calendar_post_details_' . $post_id;
}

function get_editable_html( $type, $value ) {

Expand Down Expand Up @@ -1057,13 +1053,8 @@ function get_post_information_fields( $post ) {
'value' => get_post_type_object( $post->post_type )->labels->singular_name,
);
}
// Publication time for published statuses
$published_statuses = array(
'publish',
'future',
'private',
);
if ( in_array( $post->post_status, $published_statuses ) ) {

if ( in_array( $post->post_status, $this->published_statuses ) ) {
if ( $post->post_status == 'future' ) {
$information_fields['post_date'] = array(
'label' => __( 'Scheduled', 'edit-flow' ),
Expand All @@ -1077,9 +1068,7 @@ function get_post_information_fields( $post ) {
}
}
// Taxonomies and their values
$args = array(
'post_type' => $post->post_type,
);
$args = array( 'post_type' => $post->post_type );
$taxonomies = get_object_taxonomies( $args, 'object' );
foreach( (array)$taxonomies as $taxonomy ) {
// Sometimes taxonomies skip by, so let's make sure it has a label too
Expand All @@ -1100,25 +1089,27 @@ function get_post_information_fields( $post ) {
} else {
$value = '';
}
//Used when editing editorial metadata and post meta
if ( is_taxonomy_hierarchical( $taxonomy->name ) )

//Used when editing editorial metadata and post meta
$type = 'taxonomy';
if ( is_taxonomy_hierarchical( $taxonomy->name ) ) {
$type = 'taxonomy hierarchical';
else
$type = 'taxonomy';
}

$information_fields[$key] = array(
'label' => $taxonomy->label,
'value' => $value,
'type' => $type,
);

if( $post->post_type == 'page' )
$ed_cap = 'edit_post';
if ( $post->post_type == 'page' ) {
$ed_cap = 'edit_page';
else
$ed_cap = 'edit_post';
}

if( current_user_can( $ed_cap, $post->ID ) )
if ( current_user_can( $ed_cap, $post->ID ) ) {
$information_fields[$key]['editable'] = true;
}
}

$information_fields = apply_filters( 'ef_calendar_item_information_fields', $information_fields, $post->ID );
Expand Down Expand Up @@ -1797,8 +1788,7 @@ function calendar_filter_options( $select_id, $select_name, $filters ) {
*/
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 );
}

/**
Expand Down
34 changes: 29 additions & 5 deletions modules/notifications/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,16 @@ public function filter_post_row_actions( $actions, $post ) {
* @since 0.8
*/
private function get_follow_action_parts( $post ) {
$current_user = wp_get_current_user();

$args = array(
'action' => 'ef_notifications_user_post_subscription',
'post_id' => $post->ID,
);
$following_users = $this->get_following_users( $post->ID );
if ( in_array( wp_get_current_user()->user_login, $following_users ) ) {
'action' => 'ef_notifications_user_post_subscription',
'post_id' => $post->ID,
);

$is_following = $this->is_user_following( $current_user, $post );

if ( $is_following ) {
$args['method'] = 'unfollow';
$title_text = __( 'Click to unfollow updates to this post', 'edit-flow' );
$follow_text = __( 'Following', 'edit-flow' );
Expand Down Expand Up @@ -1116,6 +1119,27 @@ function get_following_users( $post_id, $return = 'user_login' ) {
return $users;

}

/**
* Returns true if a user is following the post
*
* @param object $user The user to check
* @param object $post The post to check
* @return boolean If the user is following the post
*/
function is_user_following( $user, $post ) {

// Get following_users terms for the post
$users = wp_get_object_terms( $post->ID, $this->following_users_taxonomy, array('fields' => 'names') );

// Don't have any following users
if( !$users || is_wp_error($users) )
return false;

return true;

return in_array( $user->user_login, $users );
}

/**
* Gets a list of the usergroups that are following specified post
Expand Down