<commit_before><?php

/**
 * @package anno
 * This file is part of the Annotum theme for WordPress
 * Built on the Carrington theme framework <http://carringtontheme.com>
 *
 * Copyright 2008-2011 Crowd Favorite, Ltd. All rights reserved. <http://crowdfavorite.com>
 * Released under the GPL license
 * http://www.opensource.org/licenses/gpl-license.php
 */

/**
 * Sends a notification email.
 *
 * @param string $type The type of notification to send
 * @param stdObj $post WP Post object
 * @param stdObj $comment WP Comment object
 * @param array $recipients Array of email addresses to send the notification to. This will merge with predetermined values.
 * @param mixed $single_user (id or WP User Object) User in which the notification directly refers to such as the User which was added as a reviewer. 
 * @param $data array of supporting data for notifications
 * @return bool true if mail sent successfully, false otherwise.
 */
function annowf_send_notification($type, $post = null, $comment = null, $recipients = null, $single_user = null, $data = false) {
	// Ensure that workflow notifications are enabled. This is also enforced prior to calls to annowf_send_notification
	if (!anno_workflow_enabled('notifications')) {
		return false;
	}
	else if (empty($type)) {
		return false;
	}
	
	$notification = annowf_notification_message($type, $post, $comment, $single_user, $data);
	if (is_null($recipients) || !is_array($recipients)) {
		$recipients = annowf_notification_recipients($type, $post);
	}
	else if (is_array($recipients)) {
		$recipients = array_merge($recipients, annowf_notification_recipients($type, $post));
	}
	$recipients = apply_filters('annowf_notification_recipients', array_unique($recipients), $type, $post);
	// Sitewide admin should never recieve any workflow notifications.
	$admin_email = get_option('admin_email');
	if ($key = array_search($admin_email, $recipients)) {
		unset($recipients[$key]);
	}
	$headers = array('BCC: '.implode(', ', array_unique($recipients)));

 	return @wp_mail(null, $notification['subject'], $notification['body'], $headers);
}

/**
 * Calculates a list of recipients based on the type of notification to be sent
 *
 * @param string $type The type of notification to send
 * @param stdObj $post WP Post object
 * @return array Array of emails (or empty).
 */
function annowf_notification_recipients($type, $post) {
	$recipients = array();
	switch ($type) {
		case 'submitted':
			$recipients = array_merge($recipients, annowf_get_role_emails('editor', $post));
		case 'in_review':
		case 're_review':
			$recipients = array_merge($recipients, annowf_get_role_emails('author', $post));	
			$recipients = array_merge($recipients, annowf_get_role_emails('administrator', $post));
			$recipients = array_merge($recipients, annowf_get_role_emails('reviewer', $post));
			break;
		case 'published':
			$recipients = array_merge($recipients, annowf_get_role_emails('author', $post));	
			$recipients = array_merge($recipients, annowf_get_role_emails('editor', $post));
			$recipients = array_merge($recipients, annowf_get_role_emails('administrator', $post));
			break;
		case 'revisions':
		case 'rejected':
		case 'approved':
			$recipients = array_merge($recipients, annowf_get_role_emails('author', $post));
			$recipients = array_merge($recipients, annowf_get_role_emails('administrator', $post));
			break;
		case 'general_comment':
			$recipients = array_merge($recipients, annowf_get_role_emails('author', $post));
			$recipients = array_merge($recipients, annowf_get_role_emails('administrator', $post));	
			$recipients = array_merge($recipients, annowf_get_role_emails('reviewer', $post));
			break;
		case 'review_comment':
		case 'review_recommendation':
			$recipients = array($recipients, annowf_get_role_emails('editor', $post));
			$recipients = array_merge($recipients, annowf_get_role_emails('administrator', $post));
			break;
		//Some cases intentionally left blank, should be passed to annowf_send_notification in recipients param.
		default:
			break;
	}
	return $recipients;
}

/**
 * Calculates a email subject and body for a given notification type<commit_msg>Editors now receive notifications when they should<commit_after><?php

/**
 * @package anno
 * This file is part of the Annotum theme for WordPress
 * Built on the Carrington theme framework <http://carringtontheme.com>
 *
 * Copyright 2008-2011 Crowd Favorite, Ltd. All rights reserved. <http://crowdfavorite.com>
 * Released under the GPL license
 * http://www.opensource.org/licenses/gpl-license.php
 */

/**
 * Sends a notification email.
 *
 * @param string $type The type of notification to send
 * @param stdObj $post WP Post object
 * @param stdObj $comment WP Comment object
 * @param array $recipients Array of email addresses to send the notification to. This will merge with predetermined values.
 * @param mixed $single_user (id or WP User Object) User in which the notification directly refers to such as the User which was added as a reviewer. 
 * @param $data array of supporting data for notifications
 * @return bool true if mail sent successfully, false otherwise.
 */
function annowf_send_notification($type, $post = null, $comment = null, $recipients = null, $single_user = null, $data = false) {
	// Ensure that workflow notifications are enabled. This is also enforced prior to calls to annowf_send_notification
	if (!anno_workflow_enabled('notifications')) {
		return false;
	}
	else if (empty($type)) {
		return false;
	}
	
	$notification = annowf_notification_message($type, $post, $comment, $single_user, $data);
	if (is_null($recipients) || !is_array($recipients)) {
		$recipients = annowf_notification_recipients($type, $post);
	}
	else if (is_array($recipients)) {
		$recipients = array_merge($recipients, annowf_notification_recipients($type, $post));
	}
	$recipients = apply_filters('annowf_notification_recipients', array_unique($recipients), $type, $post);
	// Sitewide admin should never recieve any workflow notifications.
	$admin_email = get_option('admin_email');
	if ($key = array_search($admin_email, $recipients)) {
		unset($recipients[$key]);
	}
	$headers = array('BCC: '.implode(', ', array_unique($recipients)));

 	return @wp_mail(null, $notification['subject'], $notification['body'], $headers);
}

/**
 * Calculates a list of recipients based on the type of notification to be sent
 *
 * @param string $type The type of notification to send
 * @param stdObj $post WP Post object
 * @return array Array of emails (or empty).
 */
function annowf_notification_recipients($type, $post) {
	$recipients = array();
	switch ($type) {
		case 'submitted':
		case 'in_review':
		case 're_review':
			$recipients = array_merge($recipients, annowf_get_role_emails('editor', $post));		
			$recipients = array_merge($recipients, annowf_get_role_emails('author', $post));	
			$recipients = array_merge($recipients, annowf_get_role_emails('administrator', $post));
			$recipients = array_merge($recipients, annowf_get_role_emails('reviewer', $post));
			break;
		case 'published':
		case 'revisions':
		case 'rejected':
		case 'approved':
			$recipients = array_merge($recipients, annowf_get_role_emails('editor', $post));
			$recipients = array_merge($recipients, annowf_get_role_emails('author', $post));
			$recipients = array_merge($recipients, annowf_get_role_emails('administrator', $post));
			break;
		case 'general_comment':
			$recipients = array_merge($recipients, annowf_get_role_emails('author', $post));
			$recipients = array_merge($recipients, annowf_get_role_emails('administrator', $post));	
			$recipients = array_merge($recipients, annowf_get_role_emails('reviewer', $post));
			break;
		case 'review_comment':
		case 'review_recommendation':
			$recipients = array_merge($recipients, annowf_get_role_emails('editor', $post));
			$recipients = array_merge($recipients, annowf_get_role_emails('administrator', $post));
			break;
		//Some cases intentionally left blank, should be passed to annowf_send_notification in recipients param.
		default:
			break;
	}
	return $recipients;
}

/**
 * Calculates a email subject and body for a given notification type
{'fraction_non_alphanumeric': 0.12329775487670225, 'fraction_numerical': 0.001962949331370384, 'mean_word_length': 5.5954692556634305, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1879003', 'n_tokens_mistral': 2757, 'n_tokens_neox': 2492, 'n_words': 710}