function wpcf7_flamingo_before_send_mail($contactform) { if (!(class_exists('Flamingo_Contact') && class_exists('Flamingo_Inbound_Message'))) { return; } if (empty($contactform->posted_data) || !empty($contactform->skip_mail)) { return; } $fields_senseless = $contactform->form_scan_shortcode(array('type' => array('captchar', 'quiz', 'acceptance'))); $exclude_names = array(); foreach ($fields_senseless as $tag) { $exclude_names[] = $tag['name']; } $posted_data = $contactform->posted_data; foreach ($posted_data as $key => $value) { if ('_' == substr($key, 0, 1) || in_array($key, $exclude_names)) { unset($posted_data[$key]); } } $email = isset($posted_data['your-email']) ? trim($posted_data['your-email']) : ''; $name = isset($posted_data['your-name']) ? trim($posted_data['your-name']) : ''; $subject = isset($posted_data['your-subject']) ? trim($posted_data['your-subject']) : ''; $meta = array(); $special_mail_tags = array('remote_ip', 'user_agent', 'url', 'date', 'time', 'post_id', 'post_name', 'post_title', 'post_url', 'post_author', 'post_author_email'); foreach ($special_mail_tags as $smt) { $meta[$smt] = apply_filters('wpcf7_special_mail_tags', '', '_' . $smt, false); } if (isset($contactform->akismet)) { $akismet = (array) $contactform->akismet; } Flamingo_Contact::add(array('email' => $email, 'name' => $name)); Flamingo_Inbound_Message::add(array('channel' => 'contact-form-7', 'subject' => $subject, 'from' => trim(sprintf('%s <%s>', $name, $email)), 'from_name' => $name, 'from_email' => $email, 'fields' => $posted_data, 'meta' => $meta, 'akismet' => $akismet)); }
function wpcf7_flamingo_before_send_mail($contactform) { if (!(class_exists('Flamingo_Contact') && class_exists('Flamingo_Inbound_Message'))) { return; } if (empty($contactform->posted_data) || !empty($contactform->skip_mail)) { return; } $fields_senseless = $contactform->form_scan_shortcode(array('type' => array('captchar', 'quiz', 'acceptance'))); $exclude_names = array(); foreach ($fields_senseless as $tag) { $exclude_names[] = $tag['name']; } $posted_data = $contactform->posted_data; foreach ($posted_data as $key => $value) { if ('_' == substr($key, 0, 1) || in_array($key, $exclude_names)) { unset($posted_data[$key]); } } $meta = array('remote_ip' => apply_filters('wpcf7_special_mail_tags', '', '_remote_ip'), 'url' => apply_filters('wpcf7_special_mail_tags', '', '_url'), 'date' => apply_filters('wpcf7_special_mail_tags', '', '_date'), 'time' => apply_filters('wpcf7_special_mail_tags', '', '_time'), 'post_id' => apply_filters('wpcf7_special_mail_tags', '', '_post_id'), 'post_name' => apply_filters('wpcf7_special_mail_tags', '', '_post_name'), 'post_title' => apply_filters('wpcf7_special_mail_tags', '', '_post_title'), 'post_url' => apply_filters('wpcf7_special_mail_tags', '', '_post_url'), 'post_author' => apply_filters('wpcf7_special_mail_tags', '', '_post_author'), 'post_author_email' => apply_filters('wpcf7_special_mail_tags', '', '_post_author_email')); $args = array('channel' => 'contact-form-7', 'fields' => $posted_data, 'meta' => $meta, 'email' => '', 'name' => '', 'from' => '', 'subject' => ''); if (!empty($posted_data['your-email'])) { $args['from_email'] = $args['email'] = trim($posted_data['your-email']); } if (!empty($posted_data['your-name'])) { $args['from_name'] = $args['name'] = trim($posted_data['your-name']); } if (!empty($posted_data['your-subject'])) { $args['subject'] = trim($posted_data['your-subject']); } $args['from'] = trim(sprintf('%s <%s>', $args['from_name'], $args['from_email'])); Flamingo_Contact::add($args); Flamingo_Inbound_Message::add($args); }
function flamingo_init() { /* L10N */ load_plugin_textdomain('flamingo', false, 'flamingo/languages'); /* Custom Post Types */ Flamingo_Contact::register_post_type(); Flamingo_Inbound_Message::register_post_type(); Flamingo_Outbound_Message::register_post_type(); do_action('flamingo_init'); }
function wpcf7_flamingo_submit($contactform, $result) { if (!class_exists('Flamingo_Contact') || !class_exists('Flamingo_Inbound_Message')) { return; } if ($contactform->in_demo_mode() || $contactform->is_true('do_not_store')) { return; } $cases = (array) apply_filters('wpcf7_flamingo_submit_if', array('spam', 'mail_sent', 'mail_failed')); if (empty($result['status']) || !in_array($result['status'], $cases)) { return; } $submission = WPCF7_Submission::get_instance(); if (!$submission || !($posted_data = $submission->get_posted_data())) { return; } $fields_senseless = $contactform->form_scan_shortcode(array('type' => array('captchar', 'quiz', 'acceptance'))); $exclude_names = array(); foreach ($fields_senseless as $tag) { $exclude_names[] = $tag['name']; } $exclude_names[] = 'g-recaptcha-response'; foreach ($posted_data as $key => $value) { if ('_' == substr($key, 0, 1) || in_array($key, $exclude_names)) { unset($posted_data[$key]); } } $email = wpcf7_flamingo_get_value('email', $contactform); $name = wpcf7_flamingo_get_value('name', $contactform); $subject = wpcf7_flamingo_get_value('subject', $contactform); $meta = array(); $special_mail_tags = array('remote_ip', 'user_agent', 'url', 'date', 'time', 'post_id', 'post_name', 'post_title', 'post_url', 'post_author', 'post_author_email'); foreach ($special_mail_tags as $smt) { $meta[$smt] = apply_filters('wpcf7_special_mail_tags', '', '_' . $smt, false); } $akismet = isset($submission->akismet) ? (array) $submission->akismet : null; if ('mail_sent' == $result['status']) { Flamingo_Contact::add(array('email' => $email, 'name' => $name)); } $channel_id = wpcf7_flamingo_add_channel($contactform->name(), $contactform->title()); if ($channel_id) { $channel = get_term($channel_id, Flamingo_Inbound_Message::channel_taxonomy); if (!$channel || is_wp_error($channel)) { $channel = 'contact-form-7'; } else { $channel = $channel->slug; } } else { $channel = 'contact-form-7'; } $args = array('channel' => $channel, 'subject' => $subject, 'from' => trim(sprintf('%s <%s>', $name, $email)), 'from_name' => $name, 'from_email' => $email, 'fields' => $posted_data, 'meta' => $meta, 'akismet' => $akismet, 'spam' => 'spam' == $result['status']); Flamingo_Inbound_Message::add($args); }
public static function find($args = '') { $defaults = array('posts_per_page' => 10, 'offset' => 0, 'orderby' => 'ID', 'order' => 'ASC', 'meta_key' => '', 'meta_value' => '', 'post_status' => 'any', 'tax_query' => array(), 'channel' => '', 'channel_id' => ''); $args = wp_parse_args($args, $defaults); $args['post_type'] = self::post_type; if (!empty($args['channel_id'])) { $args['tax_query'][] = array('taxonomy' => self::channel_taxonomy, 'terms' => $args['channel_id'], 'field' => 'term_id'); } if (!empty($args['channel'])) { $args['tax_query'][] = array('taxonomy' => self::channel_taxonomy, 'terms' => $args['channel'], 'field' => 'slug'); } $q = new WP_Query(); $posts = $q->query($args); self::$found_items = $q->found_posts; $objs = array(); foreach ((array) $posts as $post) { $objs[] = new self($post); } return $objs; }
function get_views() { $status_links = array(); $post_status = empty($_REQUEST['post_status']) ? '' : $_REQUEST['post_status']; // Inbox Flamingo_Inbound_Message::find(array('post_status' => 'any')); $posts_in_inbox = Flamingo_Inbound_Message::$found_items; $inbox = sprintf(_nx('Inbox <span class="count">(%s)</span>', 'Inbox <span class="count">(%s)</span>', $posts_in_inbox, 'posts', 'flamingo'), number_format_i18n($posts_in_inbox)); $status_links['inbox'] = sprintf('<a href="%1$s"%2$s>%3$s</a>', admin_url('admin.php?page=flamingo_inbound'), $this->is_trash || $this->is_spam ? '' : ' class="current"', $inbox); // Spam Flamingo_Inbound_Message::find(array('post_status' => Flamingo_Inbound_Message::spam_status)); $posts_in_spam = Flamingo_Inbound_Message::$found_items; $spam = sprintf(_nx('Spam <span class="count">(%s)</span>', 'Spam <span class="count">(%s)</span>', $posts_in_spam, 'posts', 'flamingo'), number_format_i18n($posts_in_spam)); $status_links['spam'] = sprintf('<a href="%1$s"%2$s>%3$s</a>', admin_url('admin.php?page=flamingo_inbound&post_status=spam'), 'spam' == $post_status ? ' class="current"' : '', $spam); // Trash Flamingo_Inbound_Message::find(array('post_status' => 'trash')); $posts_in_trash = Flamingo_Inbound_Message::$found_items; if (empty($posts_in_trash)) { return $status_links; } $trash = sprintf(_nx('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>', $posts_in_trash, 'posts', 'flamingo'), number_format_i18n($posts_in_trash)); $status_links['trash'] = sprintf('<a href="%1$s"%2$s>%3$s</a>', admin_url('admin.php?page=flamingo_inbound&post_status=trash'), 'trash' == $post_status ? ' class="current"' : '', $trash); return $status_links; }
function flamingo_load_inbound_admin() { $action = flamingo_current_action(); $redirect_to = admin_url('admin.php?page=flamingo_inbound'); if ('trash' == $action && !empty($_REQUEST['post'])) { if (!is_array($_REQUEST['post'])) { check_admin_referer('flamingo-trash-inbound-message_' . $_REQUEST['post']); } else { check_admin_referer('bulk-posts'); } $trashed = 0; foreach ((array) $_REQUEST['post'] as $post) { $post = new Flamingo_Inbound_Message($post); if (empty($post)) { continue; } if (!current_user_can('flamingo_delete_inbound_message', $post->id)) { wp_die(__('You are not allowed to move this item to the Trash.', 'flamingo')); } if (!$post->trash()) { wp_die(__('Error in moving to Trash.', 'flamingo')); } $trashed += 1; } if (!empty($trashed)) { $redirect_to = add_query_arg(array('message' => 'inboundtrashed'), $redirect_to); } wp_safe_redirect($redirect_to); exit; } if ('untrash' == $action && !empty($_REQUEST['post'])) { if (!is_array($_REQUEST['post'])) { check_admin_referer('flamingo-untrash-inbound-message_' . $_REQUEST['post']); } else { check_admin_referer('bulk-posts'); } $untrashed = 0; foreach ((array) $_REQUEST['post'] as $post) { $post = new Flamingo_Inbound_Message($post); if (empty($post)) { continue; } if (!current_user_can('flamingo_delete_inbound_message', $post->id)) { wp_die(__('You are not allowed to restore this item from the Trash.', 'flamingo')); } if (!$post->untrash()) { wp_die(__('Error in restoring from Trash.', 'flamingo')); } $untrashed += 1; } if (!empty($untrashed)) { $redirect_to = add_query_arg(array('message' => 'inbounduntrashed'), $redirect_to); } wp_safe_redirect($redirect_to); exit; } if ('delete_all' == $action) { check_admin_referer('bulk-posts'); $_REQUEST['post'] = flamingo_get_all_ids_in_trash(Flamingo_Inbound_Message::post_type); $action = 'delete'; } if ('delete' == $action && !empty($_REQUEST['post'])) { if (!is_array($_REQUEST['post'])) { check_admin_referer('flamingo-delete-inbound-message_' . $_REQUEST['post']); } else { check_admin_referer('bulk-posts'); } $deleted = 0; foreach ((array) $_REQUEST['post'] as $post) { $post = new Flamingo_Inbound_Message($post); if (empty($post)) { continue; } if (!current_user_can('flamingo_delete_inbound_message', $post->id)) { wp_die(__('You are not allowed to delete this item.', 'flamingo')); } if (!$post->delete()) { wp_die(__('Error in deleting.', 'flamingo')); } $deleted += 1; } if (!empty($deleted)) { $redirect_to = add_query_arg(array('message' => 'inbounddeleted'), $redirect_to); } wp_safe_redirect($redirect_to); exit; } if ('spam' == $action && !empty($_REQUEST['post'])) { if (!is_array($_REQUEST['post'])) { check_admin_referer('flamingo-spam-inbound-message_' . $_REQUEST['post']); } else { check_admin_referer('bulk-posts'); } $submitted = 0; foreach ((array) $_REQUEST['post'] as $post) { $post = new Flamingo_Inbound_Message($post); if (empty($post)) { continue; } if (!current_user_can('flamingo_spam_inbound_message', $post->id)) { wp_die(__('You are not allowed to spam this item.', 'flamingo')); } if ($post->spam()) { $submitted += 1; } } if (!empty($submitted)) { $redirect_to = add_query_arg(array('message' => 'inboundspammed'), $redirect_to); } wp_safe_redirect($redirect_to); exit; } if ('unspam' == $action && !empty($_REQUEST['post'])) { if (!is_array($_REQUEST['post'])) { check_admin_referer('flamingo-unspam-inbound-message_' . $_REQUEST['post']); } else { check_admin_referer('bulk-posts'); } $submitted = 0; foreach ((array) $_REQUEST['post'] as $post) { $post = new Flamingo_Inbound_Message($post); if (empty($post)) { continue; } if (!current_user_can('flamingo_unspam_inbound_message', $post->id)) { wp_die(__('You are not allowed to unspam this item.', 'flamingo')); } if ($post->unspam()) { $submitted += 1; } } if (!empty($submitted)) { $redirect_to = add_query_arg(array('message' => 'inboundunspammed'), $redirect_to); } wp_safe_redirect($redirect_to); exit; } if (!empty($_GET['export'])) { check_admin_referer('bulk-posts'); $sitename = sanitize_key(get_bloginfo('name')); $filename = (empty($sitename) ? '' : $sitename . '-') . sprintf('flamingo-inbound-%s.csv', date('Y-m-d')); header('Content-Description: File Transfer'); header("Content-Disposition: attachment; filename={$filename}"); header('Content-Type: text/csv; charset=' . get_option('blog_charset')); $args = array('posts_per_page' => -1, 'orderby' => 'date', 'order' => 'DESC'); if (!empty($_REQUEST['s'])) { $args['s'] = $_REQUEST['s']; } if (!empty($_REQUEST['orderby'])) { if ('subject' == $_REQUEST['orderby']) { $args['meta_key'] = '_subject'; $args['orderby'] = 'meta_value'; } elseif ('from' == $_REQUEST['orderby']) { $args['meta_key'] = '_from'; $args['orderby'] = 'meta_value'; } } if (!empty($_REQUEST['order']) && 'asc' == strtolower($_REQUEST['order'])) { $args['order'] = 'ASC'; } if (!empty($_REQUEST['m'])) { $args['m'] = $_REQUEST['m']; } if (!empty($_REQUEST['channel_id'])) { $args['channel_id'] = $_REQUEST['channel_id']; } if (!empty($_REQUEST['channel'])) { $args['channel'] = $_REQUEST['channel']; } $items = Flamingo_Inbound_Message::find($args); if (empty($items)) { exit; } $labels = array_keys($items[0]->fields); $labels[] = __('Date', 'flamingo'); echo flamingo_csv_row($labels); foreach ($items as $item) { $row = array(); foreach ($labels as $label) { $col = isset($item->fields[$label]) ? $item->fields[$label] : ''; if (is_array($col)) { $col = flamingo_array_flatten($col); $col = array_filter(array_map('trim', $col)); $col = implode(', ', $col); } $row[] = $col; } $row[] = get_post_time('c', true, $item->id); echo "\r\n" . flamingo_csv_row($row); } exit; } $post_id = !empty($_REQUEST['post']) ? $_REQUEST['post'] : ''; if (Flamingo_Inbound_Message::post_type == get_post_type($post_id)) { add_meta_box('submitdiv', __('Save', 'flamingo'), 'flamingo_inbound_submit_meta_box', null, 'side', 'core'); add_meta_box('inboundfieldsdiv', __('Fields', 'flamingo'), 'flamingo_inbound_fields_meta_box', null, 'normal', 'core'); } else { if (!class_exists('Flamingo_Inbound_Messages_List_Table')) { require_once FLAMINGO_PLUGIN_DIR . '/admin/includes/class-inbound-messages-list-table.php'; } $current_screen = get_current_screen(); add_filter('manage_' . $current_screen->id . '_columns', array('Flamingo_Inbound_Messages_List_Table', 'define_columns')); add_screen_option('per_page', array('label' => __('Messages', 'flamingo'), 'default' => 20)); } }
function column_history($item) { $history = array(); // User if ($user = get_user_by('email', $item->email)) { $link = sprintf('user-edit.php?user_id=%d', $user->ID); $history[] = '<a href="' . admin_url($link) . '">' . esc_html(__('User', 'flamingo')) . '</a>'; } // Comment $comment_count = (int) get_comments(array('count' => true, 'author_email' => $item->email, 'status' => 'approve', 'type' => 'comment')); if (0 < $comment_count) { $link = sprintf('edit-comments.php?s=%s', urlencode($item->email)); $history[] = '<a href="' . admin_url($link) . '">' . sprintf(__('Comment (%d)', 'flamingo'), $comment_count) . '</a>'; } // Contact channels $terms = get_terms(Flamingo_Inbound_Message::channel_taxonomy); if (!empty($terms) && !is_wp_error($terms)) { foreach ((array) $terms as $term) { Flamingo_Inbound_Message::find(array('channel' => $term->slug, 's' => $item->email)); $count = (int) Flamingo_Inbound_Message::$found_items; if (!$count) { continue; } $link = sprintf('admin.php?page=flamingo_inbound&channel=%1$s&s=%2$s', urlencode($term->slug), urlencode($item->email)); $history[] = '<a href="' . admin_url($link) . '">' . sprintf(_x('%s (%d)', 'contact history', 'flamingo'), $term->name, $count) . '</a>'; } } $output = ''; foreach ($history as $item) { $output .= '<li>' . $item . '</li>'; } $output = '<ul class="contact-history">' . $output . '</ul>'; return $output; }
function wpcf7_flamingo_serial_number($output, $name, $html) { if ('_serial_number' != $name) { return $output; } if (!class_exists('Flamingo_Inbound_Message') || !method_exists('Flamingo_Inbound_Message', 'count')) { return $output; } if (!($contact_form = WPCF7_ContactForm::get_current())) { return $output; } $channel_id = wpcf7_flamingo_add_channel($contact_form->name(), $contact_form->title()); if ($channel_id) { return 1 + (int) Flamingo_Inbound_Message::count(array('channel_id' => $channel_id)); } return 0; }