Exemplo n.º 1
0
/**
 * 
 * Disparar E-mails
 * @param int $id comment id
 * @param int $comment_parent
 * @param int $comment_post
 * @param string $tipo
 */
function delibera_mailer_mailer($id, $comment_parent, $comment_post, $tipo = 'reply')
{
    require ABSPATH . WPINC . '/pluggable.php';
    add_filter('wp_mail_content_type', create_function('', 'return "text/html"; '));
    $comment = get_comment($id);
    $post = get_post($comment_post);
    $comment_parent = get_comment($comment_parent);
    if ($post->post_status == 'publish') {
        $options_plugin_delibera = delibera_get_config();
        if ($options_plugin_delibera["reposta-por-email"] == "N") {
            return false;
        }
        $subject_default = htmlspecialchars_decode($options_plugin_delibera["mailer_{$tipo}_assunto"]);
        $mensage_default = '';
        $users = get_users();
        if (!is_array($users)) {
            $users = array();
        }
        $seguiram = delibera_get_quem_seguiu($post->ID, 'ids');
        foreach ($users as $user) {
            if (user_can($user->ID, 'votar') && isset($user->user_email)) {
                $segue = array_search($user->ID, $seguiram);
                $user_notificacoes = get_user_meta($user->ID, 'delibera_resposta_email', true);
                if ($user_notificacoes == "N" && !$segue) {
                    continue;
                } else {
                    $mensage_tmp = $mensage_default;
                    $subject_tmp = $subject_default;
                    if (function_exists('qtrans_enableLanguage')) {
                        $lang = get_user_meta($user->ID, 'user_idioma', true);
                        if (strlen($lang) == 0) {
                            $lang = defined('WPLANG') && strlen(WPLANG) > 0 ? WPLANG : get_locale();
                        }
                        if (array_key_exists("mailer_{$tipo}-{$lang}", $options_plugin_delibera)) {
                            $mensage_tmp = htmlspecialchars_decode($options_plugin_delibera["mailer_{$tipo}-{$lang}"]) . delibera_notificar_get_mensagem_link($post);
                        }
                        if (array_key_exists("mailer_{$tipo}_assunto-{$lang}", $options_plugin_delibera)) {
                            $subject_tmp = htmlspecialchars_decode($options_plugin_delibera["mailer_{$tipo}_assunto-{$lang}"]);
                        }
                    }
                    $key = delibera_mailer_generateKey($user->ID, $id, get_current_blog_id());
                    $from = $options_plugin_delibera['delibera_mailer_from'];
                    $from_server = $options_plugin_delibera['delibera_mailer_from_server'];
                    $header = $headers = 'From: ' . $from . "\r\n" . 'Reply-To: ' . $key . '@' . $from_server . "\r\n" . 'X-Mailer: PHP/' . phpversion();
                    wp_mail($user->user_email, $subject_tmp . ' ' . get_the_title($comment_post), $mensage_tmp . get_comment_text($id), $header);
                }
            }
        }
    }
}
Exemplo n.º 2
0
function delibera_notificar_replace_vars($subject, $user, $postReport)
{
    global $post;
    if (!is_object($postReport)) {
        $postReport = get_post($postReport);
    }
    $post = $postReport;
    $opt = delibera_get_config();
    $author = get_user_by('id', $post->post_author);
    $subject = str_ireplace("{first_name}", $user->user_firstname, $subject);
    $subject = str_ireplace("{last_name}", $user->user_lastname, $subject);
    $subject = str_ireplace("{display_name}", $user->display_name, $subject);
    $subject = str_ireplace("{post_title}", $post->post_title, $subject);
    $subject = str_ireplace("{post_url}", delibera_notificar_get_mensagem_link($post), $subject);
    $subject = str_ireplace("{report_deadline}", $opt['dias_relatoria'], $subject);
    $subject = str_ireplace("{reporter_election}", $opt['dias_votacao_relator'], $subject);
    $subject = str_ireplace("{validation_days}", $opt['dias_validacao'], $subject);
    $subject = str_ireplace("{discuss_days}", $opt['dias_validacao'], $subject);
    $subject = str_ireplace("{election_days}", $opt['dias_votacao'], $subject);
    $subject = str_ireplace("{post_author}", $author->user_firstname, $subject);
    $subject = str_ireplace("{post_content}", get_the_content(), $subject);
    $subject = str_ireplace("{post_excerpt}", get_the_excerpt(), $subject);
    $campos = delibera_get_user_campos_form_registro();
    if ($campos > 0) {
        foreach ($campos as $campo) {
            $valor_replace = "";
            if ($campo['novo'] == true) {
                switch ($campo['tipo_painel']) {
                    case 'DropDown':
                        $valores = array();
                        if (is_array($campo['dados']) && count($campo['dados']) > 0) {
                            $valores = $campo['dados'];
                        } elseif (is_string($campo['dados']) && function_exists($campo['dados'])) {
                            $param = $campo['dados_param'] ? $campo['dados_param'] : array();
                            $ret = call_user_func($campo['dados'], $param);
                            if (is_array($ret) && count($ret) > 0) {
                                $valores = $ret;
                            }
                        }
                        foreach ($valores as $valor => $desc) {
                            if (strtolower(get_user_meta($user->ID, $campo['id'], true)) === strtolower($valor)) {
                                $valor_replace = $desc;
                            }
                        }
                        break;
                    case 'CheckBox':
                        $valor = true;
                        if (is_array($campo['dados']) && count($campo['dados']) > 0) {
                            $keys = array_keys($campo['dados']);
                            $valor = $keys[0];
                        } elseif (is_string($campo['dados']) && function_exists($campo['dados'])) {
                            $param = $campo['dados_param'] ? $campo['dados_param'] : array();
                            $ret = call_user_func($campo['dados'], $param);
                            if (is_array($ret) && count($ret) > 0) {
                                $keys = array_keys($ret);
                                $valor = $keys[0] == 0 ? $ret[0] : $keys[0];
                            } elseif (is_string($ret)) {
                                $valor = $ret;
                            }
                        }
                        if (strtolower(get_user_meta($user->ID, $campo['id'], true)) === strtolower($valor)) {
                            $valor_replace = __("Sim", 'delibera');
                        } else {
                            $valor_replace = __("Não", 'delibera');
                        }
                        break;
                    case 'Texto':
                    default:
                        $valor_replace = get_user_meta($user->ID, $campo['id'], true);
                        break;
                }
            }
            $subject = str_ireplace("{" . $campo['id'] . "}", $valor_replace, $subject);
        }
    }
    return $subject;
}