Esempio n. 1
0
/**
 * Custom meta Box For Author select.
 */
function annowf_author_meta_box($post)
{
    if (!anno_user_can('select_author')) {
        $author = get_userdata($post->post_author);
        echo esc_html($author->user_login);
    } else {
        $authors = anno_get_authors($post->ID);
        ?>
<label class="screen-reader-text" for="post_author_override"><?php 
        _ex('Author', 'Author meta box dropdown label', 'anno');
        ?>
</label>
<?php 
        wp_dropdown_users(array('include' => implode(',', $authors), 'name' => 'post_author_override', 'selected' => $post->post_author, 'include_selected' => true));
    }
}
Esempio n. 2
0
/**
 * Takes a snapshot of author/co-authors user data and stores it in post data
 * Only stores on publish and does not overwrite existing.
 */
function anno_users_snapshot($post_id, $post)
{
    if ($post->post_status == 'publish' && $post->post_type == 'article') {
        $authors = anno_get_authors($post->ID);
        $author_meta = get_post_meta($post_id, '_anno_author_snapshot', true);
        if (!is_array($author_meta)) {
            $author_meta = array();
        }
        foreach ($authors as $author_id) {
            $author_meta[$author_id] = anno_snapshot_user_data($author_id, $post_id, $author_meta);
        }
        update_post_meta($post_id, '_anno_author_snapshot', $author_meta);
    }
}
 /**
  * Get an array of ids for all contributors to a given post.
  * @param int $post_id (optional) the ID of the post to get from. Defaults to current post.
  * @return array
  */
 public function get_author_ids($post_id = null)
 {
     if (empty($post_id)) {
         global $post;
         $post_id = $post->ID;
     }
     /* Get the additional contributors, if the workflow is turned on. */
     $authors = anno_get_authors($post_id);
     return $authors;
 }
Esempio n. 4
0
/**
 * Get an array of emails for a given role, be it a global or per post role.
 *
 * @param string $role The role of the users to fetch
 * @param stdObj $post A WP post object
 * @return array Returns an array of emails of users of a given role. Returns an empty array if no users are found
 */
function annowf_get_role_emails($role, $post = null)
{
    switch ($role) {
        case 'administrator':
        case 'editor':
            $users = get_users(array('role' => $role));
            break;
        case 'co-author':
        case 'co_author':
        case 'author':
            $user_ids = anno_get_authors($post->ID);
            if (!empty($user_ids)) {
                $users = get_users(array('include' => $user_ids));
            }
            break;
        case 'reviewer':
            $user_ids = anno_get_reviewers($post->ID);
            if (!empty($user_ids)) {
                $users = get_users(array('include' => $user_ids));
            }
            break;
        default:
            break;
    }
    if (!empty($users) && is_array($users)) {
        return array_map('anno_user_email', $users);
    }
    return array();
}
Esempio n. 5
0
/**
 * Calculates a email subject and body for a given notification type
 *
 * @param string $type The type of notification to send
 * @param stdObj $post WP Post object
 * @param stdObj $comment WP Comment object
 * @param mixed $single_user (id or object) User in which the notification directly refers to such as the User in which was added as a reviewer.
 * @return array Array consisting of email title and body
 */
function annowf_notification_message($type, $post, $comment, $single_user = null, $data = false)
{
    $footer = get_option('blogname') . ' ' . home_url();
    $author = get_userdata($post->post_author);
    $author = anno_user_display($author);
    if (!empty($single_user->ID)) {
        $single_user_id = $single_user->ID;
    } else {
        $single_user_id = $single_user;
    }
    if (!empty($single_user)) {
        $single_user = anno_user_display($single_user);
    }
    // Used in determining a user's recommendation
    $authors = anno_get_authors($post->ID);
    $author_names = array_map('anno_user_display', $authors);
    $edit_link = get_edit_post_link($post->ID, null);
    $title = $post->post_title;
    $excerpt = strip_tags($post->post_excerpt ? $post->post_excerpt : $post->post_content);
    if (strlen($excerpt) > 255) {
        $excerpt = substr($excerpt, 0, 252) . '...';
    }
    $reviewer_instructions = _x('To review this article, please visit the URL above and navigate to the Reviews section. You may leave comments and questions in this section as well as providing a general review of \'Approve\', \'Reject\' or \'Request Revisions\' from the dropdown.', 'Instructions sent to reviewers via email notification', 'anno');
    $notification = array('subject' => '', 'body' => '');
    switch ($type) {
        // Status change to: submitted
        case 'submitted':
            $notification = array('subject' => sprintf(_x('New Submission: %s by %s.', 'Email notification subject', 'anno'), $title, $author), 'body' => sprintf(_x('The following article has been submitted for review:
--------------------
Title: %s
Author(s): %s
Excerpt: %s
%s

%s', 'Email notification body', 'anno'), $title, implode(', ', $author_names), $excerpt, $edit_link, $footer));
            break;
            // Status change to: in_review from submitted
        // Status change to: in_review from submitted
        case 'in_review':
            $notification = array('subject' => sprintf(_x('%s now in review.', 'Email notification subject', 'anno'), $title), 'body' => sprintf(_x('Review has begun for: %s

%s

%s', 'Email notification body', 'anno'), $title, $edit_link, $footer));
            break;
            // Status change to: in_review from draft (revisions have occured)
        // Status change to: in_review from draft (revisions have occured)
        case 're_review':
            $notification = array('subject' => sprintf(_x('%s now in review.', 'Email notification subject', 'anno'), $title), 'body' => sprintf(_x('Revisions have been made for %s and we ask you to please re-review the article.

%s

%s', 'Email notification body', 'anno'), $title, $edit_link, $footer));
            break;
            // Status change to: approved
        // Status change to: approved
        case 'approved':
            $notification = array('subject' => sprintf(_x('%s review is complete. APPROVED.', 'Email notification subject', 'anno'), $title), 'body' => sprintf(_x('Thank you for your contribution to %s. We are pleased to inform you that the article, %s, has been approved!

You will receive an additional notification when the article is published.

Thank you.

%s', 'Email notification body', 'anno'), $title, $title, $footer));
            break;
            // Status change to: rejected
        // Status change to: rejected
        case 'rejected':
            $notification = array('subject' => sprintf(_x('%s review is complete.', 'Email notification subject', 'anno'), $title), 'body' => sprintf(_x('Thank you for contributing to %s.  After our review process, we have decided not to accept the article at this time.
--------------------
Title: %s

%s

%s', 'Email notification body', 'anno'), $title, $title, $edit_link, $footer));
            break;
            // Status change to: draft (from in_review)
        // Status change to: draft (from in_review)
        case 'revisions':
            $notification = array('subject' => sprintf(_x('%s review is complete. CHANGES REQUESTED.', 'Email notification subject', 'anno'), $title), 'body' => sprintf(_x('Thank you for contributing to %s.  After reviewing your article, we would like to request some changes.  Please open the article here:

%s

and refer to the comments listed.  Once you have updated your submission in accordance with the comments, please resubmit your article.

Thank you.

%s', 'Email notification body', 'anno'), $title, $edit_link, $footer));
            break;
            // Status change to: published
        // Status change to: published
        case 'published':
            $notification = array('subject' => sprintf(_x('%s has been published.', 'Email notification subject', 'anno'), $title), 'body' => sprintf(_x('The following article has been published: %s

%s

%s', 'Email notification body', 'anno'), $title, $edit_link, $footer));
            break;
        case 'reviewer_added':
            $notification = array('subject' => sprintf(_x('%s has been invited to review %s by %s', 'Email notification subject', 'anno'), $single_user, $title, $author), 'body' => sprintf(_x('%s has been invited to review the following article:
--------------------
Title: %s
Author(s): %s
Excerpt: %s
%s

%s
%s', 'Email notification body', 'anno'), $single_user, $title, implode(', ', $author_names), $excerpt, $edit_link, $reviewer_instructions, $footer));
            break;
        case 'co_author_added':
            $notification = array('subject' => sprintf(_x('%s has been invited to co-author %s by %s', 'Email notification subject', 'anno'), $single_user, $title, $author), 'body' => sprintf(_x('%s has been invited to co-author %s by %s.
%s

%s', 'Email notification body', 'anno'), $single_user, $title, $author, $edit_link, $footer));
            break;
        case 'primary_author':
            $notification = array('subject' => sprintf(_x('%s is now the primary author on %s', 'Email notification subject', 'anno'), $author, $single_user), 'body' => sprintf(_x('%s is now the primary author on %s.
%s

%s', 'Email notification body', 'anno'), $author, $title, $edit_link, $footer));
            break;
        case 'review_recommendation':
            global $anno_review_options;
            //Get user review
            $review_key = annowf_get_user_review($post->ID, $single_user_id);
            switch ($review_key) {
                // Translate here so the entire sentence can be a translated string instead of bits and pieces
                case 1:
                    $action_text = sprintf(_x('%s has reviewed %s and has accepted the article for publication.', 'Email review action text', 'anno'), $single_user, $title);
                    break;
                case 2:
                    $action_text = sprintf(_x('%s has reviewed %s and has requested revisions be made to the article prior to publication.', 'Email review action text', 'anno'), $single_user, $title);
                    break;
                case 3:
                    $action_text = sprintf(_x('%s has reviewed %s and has rejected the article for publication.', 'Email review action text', 'anno'), $single_user, $title);
                    break;
                default:
                    $action_text = '';
                    break;
            }
            $notification = array('subject' => sprintf(_x('%s has reviewed %s', 'Email notification subject', 'anno'), $single_user, $title), 'body' => sprintf(_x('%s
%s

%s', 'Email notification body', 'anno'), $action_text, $edit_link, $footer));
            break;
        case 'reviewer_update':
            // Get review
            $reviewer = get_user_by('id', $single_user_id);
            global $anno_review_options;
            $review_key = annowf_get_user_review($post->ID, $single_user_id);
            if ($data['status'] == 'revisions') {
                $status = _x('requested to make revisions', 'Email notification status', 'anno');
            } else {
                global $annowf_states;
                // approved, published, rejected
                $status = $annowf_states[$data['status']];
            }
            $notification = array('subject' => sprintf(_x('An article you reviewed, %s, has been %s', 'Email notification subject', 'anno'), $title, $status), 'body' => sprintf(_x('%s by %s has been %s
%s
--------------------
You left a review of : %s
--------------------

Thank you for your contribution. At this time the review process is completed; you will be notified of any further updates to this article.

%s', 'Email notification body', 'anno'), $title, implode(', ', $author_names), $status, $edit_link, $anno_review_options[(int) $review_key], $footer));
            break;
        default:
            break;
    }
    if (!empty($comment)) {
        $comment_author = anno_user_display($comment->user_id);
        $comment_edit_link = get_edit_post_link($comment->comment_post_ID, null) . '#comment-' . $comment->comment_ID;
        switch ($type) {
            case 'general_comment':
                $notification = array('subject' => sprintf(_x('New internal comment on %s', 'Email notification subject', 'anno'), $title), 'body' => sprintf(_x('The following comment was submitted on %s by %s.
--------------------
%s
--------------------
%s

%s', 'Email notification body', 'anno'), $title, $comment_author, $comment->comment_content, $comment_edit_link, $footer));
                break;
            case 'review_comment':
                $notification = array('subject' => sprintf(_x('New reviewer comment on %s', 'Email notification subject', 'anno'), $title), 'body' => sprintf(_x('The following comment was submitted on %s by %s.
--------------------
%s
--------------------
%s

%s', 'Email notification body', 'anno'), $title, $comment_author, $comment->comment_content, $comment_edit_link, $footer));
                break;
            default:
                break;
        }
    }
    return apply_filters('annowf_notfication', $notification, $type, $post, $comment);
}
/**
 * Takes a snapshot of author/co-authors user data and stores it in post data
 * Only stores on publish and does not overwrite existing.
 */
function anno_users_snapshot($post_id, $post)
{
    if ($post->post_status == 'publish' && $post->post_type == 'article') {
        $authors = anno_get_authors($post->ID);
        $author_meta = get_post_meta($post_id, '_anno_author_snapshot', true);
        if (!is_array($author_meta)) {
            $author_meta = array();
        }
        foreach ($authors as $author_id) {
            if (array_key_exists($author_id, $author_meta)) {
                continue;
            }
            $author = get_userdata($author_id);
            if ($author) {
                $author_meta[$author->ID] = array('id' => $author->ID, 'surname' => $author->last_name, 'given_names' => $author->first_name, 'prefix' => get_user_meta($author->ID, '_anno_prefix', true), 'suffix' => get_user_meta($author->ID, '_anno_suffix', true), 'degrees' => get_user_meta($author->ID, '_anno_degrees', true), 'affiliation' => get_user_meta($author->ID, '_anno_affiliation', true), 'bio' => $author->user_description, 'email' => $author->user_email, 'link' => $author->user_url);
            } else {
                delete_post_meta($post->ID, '_anno_author_' . $author_id);
            }
        }
        update_post_meta($post_id, '_anno_author_snapshot', $author_meta);
    }
}