Ejemplo n.º 1
0
 /**
  * Sends the leads history email
  *
  * @param   string
  * @return  bool $email_sent    Whether the email contents were sent successfully. A true return value does not automatically mean that the user received the email successfully. It just only means that the method used was able to process the request without any errors.
  */
 function send_new_lead_email($hashkey)
 {
     $ir_contact = new IR_Contact();
     $ir_contact->hashkey = $hashkey;
     $ir_contact->get_contact_history();
     $history = $ir_contact->history;
     $lead_email = isset($history->lead->lead_email) ? $history->lead->lead_email : '';
     $body = null;
     $body = $this->build_body($history);
     // Each line in an email can only be 998 characters long, so lines need to be broken with a wordwrap
     $body = wordwrap($body, 900, "\r\n");
     $options = get_option('inboundrocket_options');
     $to = $options['ir_email'] ? $options['ir_email'] : get_bloginfo('admin_email');
     // Get email from plugin settings, if none set, use admin email
     $tag_status = '';
     if (count($history->lead->last_submission['form_tags'])) {
         $tag_status = __('labeled as', 'inboundrocket') . ' "' . $history->lead->last_submission['form_tags'][0]['tag_text'] . '" ';
     }
     $return_status = $tag_status ? '' : ' ';
     if ($history->lead->total_visits > 1) {
         $return_status = __('by a returning visitor', 'inboundrocket') . ' ';
     }
     if ($history->lead->total_submissions > 1) {
         $return_status = __('by a returning contact', 'inboundrocket') . ' ';
     }
     $subject = __('Form submission', 'inboundrocket') . " " . $tag_status . $return_status . "on " . get_bloginfo('name') . " - " . $lead_email;
     $headers = "From: Inbound Rocket <*****@*****.**>\r\n";
     $headers .= "Reply-To: Inbound Rocket <*****@*****.**>\r\n";
     $headers .= "X-Mailer: PHP/" . phpversion() . "\r\n";
     $headers .= "MIME-Version: 1.0\r\n";
     $headers .= "Content-type: text/html; charset=utf-8\r\n";
     $email_sent = wp_mail($to, $subject, $body, $headers);
     inboundrocket_track_plugin_activity('Contact Notification Sent', array('service' => 'php_mail', 'to_email' => $to));
     return $email_sent;
 }
Ejemplo n.º 2
0
    /**
     * Creates view a contact's details + timeline history
     *
     * @param   int
     */
    function inboundrocket_render_contact_detail($lead_id)
    {
        $css_class = '';
        $ir_contact = new IR_Contact();
        $ir_contact->set_hashkey_by_id($lead_id);
        $ir_contact->get_contact_history();
        $lead_email = $ir_contact->history->lead->lead_email;
        $lead_firstname = $ir_contact->history->lead->lead_first_name;
        $lead_lastname = $ir_contact->history->lead->lead_last_name;
        // @TODO temporary hack
        preg_match("/\\w*[@](\\w*)/", $lead_email, $output_array);
        $company_name = $output_array[1];
        $lead_source = inboundrocket_strip_params_from_url($ir_contact->history->lead->lead_source);
        $gravatar_hash = md5(strtolower(trim($lead_email)));
        $lead_ip = $ir_contact->history->lead->lead_ip;
        if ($lead_ip == '127.0.0.1') {
            // workaround for local development showing Inbound Rocket HQ ^_^
            $lead_city = 'Fort Myers';
            $lead_state = 'FL';
            $lead_country = 'US';
            $lead_loc = '26.555200,-81.896340';
        } else {
            $geoip = json_decode(file_get_contents("http://ipinfo.io/{$lead_ip}"));
            $lead_city = isset($geoip->city) ? $geoip->city : '';
            $lead_state = isset($geoip->region) ? $geoip->region : '';
            $lead_country = isset($geoip->country) ? $geoip->country : '';
            $lead_loc = isset($geoip->loc) ? $geoip->loc : '';
            $lead_telcom = isset($geoip->org) ? $geoip->org : '';
            $lead_hostname = isset($geoip->hostname) ? $geoip->hostname : '';
            $lead_zipcode = isset($geoip->postal) ? $geoip->postal : '';
        }
        if (isset($_POST['edit_lists'])) {
            $updated_tags = array();
            foreach ($_POST as $name => $value) {
                if (strstr($name, 'tag_slug_')) {
                    array_push($updated_tags, $value);
                }
            }
            $ir_contact->update_contact_tags($lead_id, $updated_tags);
            $ir_contact->history->tags = $ir_contact->get_contact_tags($ir_contact->hashkey);
            echo '<script type="text/javascript"> location.reload(); </script>';
        }
        ?>
        <div class="ir-content">
	        <div class="ir-frame">
		        <div class="header">
					<nav role="navigation" class="header-nav drawer-nav nav-horizontal">
						<ul class="main-nav">
							<li class="inboundrocket-logo"><a href="<?php 
        echo admin_url('admin.php?page=inboundrocket_stats');
        ?>
" title="<?php 
        _e('Inbound Rocket Stats', 'inboundrocket');
        ?>
"><span>Inbound Rocket</span></a></li>
						</ul>
					</nav>
				</div><!-- header -->
				<div class="clouds-sm"></div>
				<div class="wrapper">
<?php 
        if (isset($_GET['stats_dashboard'])) {
            echo '<a href="' . admin_url('admin.php?page=inboundrocket_stats') . '">&larr; ' . __('Stats Dashboard', 'inboundrocket') . '</a>';
        } else {
            if (isset($_GET['redirect_to'])) {
                if (strstr($_GET['redirect_to'], 'contact_type')) {
                    $url_parts = parse_url(esc_url($_GET['redirect_to']));
                    parse_str($url_parts['query'], $url_vars);
                    if (isset($url_vars['contact_type']) && $url_vars['contact_type']) {
                        echo '<a href="' . esc_url($_GET['redirect_to']) . '">&larr; ' . __('All', 'inboundrocket') . '' . ucwords($url_vars['contact_type']) . '</a>';
                    } else {
                        echo '<a href="' . esc_url($_GET['redirect_to']) . '">&larr; ' . __('All Contacts', 'inboundrocket') . '</a>';
                    }
                } else {
                    echo '<a href="' . esc_url($_GET['redirect_to']) . '">&larr; ' . __('All Contacts', 'inboundrocket') . '</a>';
                }
            } else {
                echo '<a href="' . admin_url('/admin.php?page=inboundrocket_contacts') . '">&larr; ' . __('All Contacts', 'inboundrocket') . '</a>';
            }
        }
        if (isset($lead_firstname) && isset($lead_lastname)) {
            $lead_full_name = esc_html($lead_firstname) . " " . esc_html($lead_lastname);
        } else {
            $lead_full_name = '';
        }
        echo '<h2 class="' . $css_class . '">' . __('Contact info of:', 'inboundrocket') . ' ';
        echo !empty($lead_full_name) ? $lead_full_name : !empty($lead_firstname) ? esc_html($lead_firstname) . " " : !empty($lead_lastname) ? esc_html($lead_lastname) . " " : 'Unknown';
        if (!empty($lead_email)) {
            echo esc_html($lead_email);
        }
        echo '</h2>';
        echo '<div class="contact-header-wrap">';
        echo '<div class="contact-header-info">';
        echo '<div class="contact-lists">';
        if (isset($ir_contact->history->lead_lists)) {
            foreach ($ir_contact->history->lead_lists as $list) {
                if ($list->tag_set) {
                    echo '<a class="contact-list" href="' . admin_url('/admin.php?page=inboundrocket_contacts&contact_type=' . $list->tag_slug) . '"><span class="icon-profile"></span>' . $list->tag_text . '</a>';
                }
            }
        }
        ?>

                    <?php 
        add_thickbox();
        ?>
                    <div id="edit-contact-lead-lists" style="display:none;">
                        <h2>Edit Lists - <?php 
        echo $ir_contact->history->lead->lead_email;
        ?>
</h2>
                        <form id="edit_lists" action="" target="_parent" method="POST">

                            <?php 
        if (!empty($ir_contact->history->lead_lists)) {
            foreach ($ir_contact->history->lead_lists as $list) {
                echo '<p>';
                echo '<label for="tag_slug_' . $list->tag_slug . '">';
                echo '<input name="tag_slug_' . $list->tag_slug . '" type="checkbox" id="tag_slug_' . $list->tag_slug . '" value="' . $list->tag_id . '" ' . ($list->tag_set ? ' checked' : '') . '>' . $list->tag_text . '</label>';
                echo '</p>';
            }
        }
        ?>

                            <input type="hidden" name="edit_lists" value="1"/>
                            <p class="submit">
                                <input type="submit" name="submit" id="submit" class="button button-primary" value=<?php 
        _e('Save To List(s)', 'inboundrocket');
        ?>
"">
                            </p>
                        </form>
                    </div>

                    <a class="thickbox contact-edit-lists" href="#TB_inline?width=300&height=450&inlineId=edit-contact-lead-lists"><?php 
        _e('edit lead lists', 'inboundrocket');
        ?>
</a>

                    <?php 
        echo '</div>';
        echo '</div>';
        echo '</div>';
        echo '<div id="col-container">';
        echo '<div id="col-right">';
        echo '<div class="col-header">Lead Activity</div>';
        echo '<div class="col-wrap contact-history">';
        echo '<ul class="sessions">';
        $sessions = $ir_contact->history->sessions;
        foreach ($sessions as &$session) {
            $first_event = end($session['events']);
            $first_event_date = $first_event['event_date'];
            $session_date = date('F j, Y, g:ia', strtotime($first_event['event_date']));
            $session_start_time = date('g:ia', strtotime($first_event['event_date']));
            $last_event = array_values($session['events']);
            $session_end_time = date('g:ia', strtotime($last_event[0]['event_date']));
            echo '<li class="session">';
            echo '<h3 class="session-date">' . $session_date . ($session_start_time != $session_end_time ? ' - ' . $session_end_time : '') . '</h3>';
            echo '<ul class="events">';
            $events = $session['events'];
            foreach ($events as &$event) {
                if ($event['event_type'] == 'pageview') {
                    $pageview = $event['activities'][0];
                    echo '<li class="event pageview">';
                    if (!empty($pageview['event_date'])) {
                        echo '<div class="event-time">' . date('g:ia', strtotime($pageview['event_date'])) . '</div>';
                    }
                    echo '<div class="event-content">';
                    if (!empty($pageview['pageview_title'])) {
                        echo '<p class="event-title">' . $pageview['pageview_title'] . '</p>';
                    }
                    if (!empty($pageview['pageview_url'])) {
                        echo '<a class="event-detail pageview-url" target="_blank" href="' . $pageview['pageview_url'] . '">' . inboundrocket_strip_params_from_url($pageview['pageview_url']) . '</a>';
                    }
                    echo '</div>';
                    echo '</li>';
                    if (isset($pageview['event_date']) && $pageview['event_date'] == $first_event['event_date']) {
                        echo '<li class="event source">';
                        echo '<div class="event-time">' . date('g:ia', strtotime($pageview['event_date'])) . '</div>';
                        echo '<div class="event-content">';
                        echo '<p class="event-title">' . __('Traffic Source', 'inboundrocket') . ': ' . ($pageview['pageview_source'] ? '<a href="' . $pageview['pageview_source'] . '">' . inboundrocket_strip_params_from_url($pageview['pageview_source']) : 'Direct') . '</a></p>';
                        $url_parts = parse_url($pageview['pageview_source']);
                        if (isset($url_parts['query'])) {
                            if ($url_parts['query']) {
                                parse_str($url_parts['query'], $url_vars);
                                if (count($url_vars)) {
                                    echo '<ul class="event-detail fields">';
                                    foreach ($url_vars as $key => $value) {
                                        if (!$value) {
                                            continue;
                                        }
                                        echo '<li class="field">';
                                        echo '<label class="field-label">' . $key . ':</label>';
                                        echo '<p class="field-value">' . nl2br($value, true) . '</p>';
                                        echo '</li>';
                                    }
                                    echo '</ul>';
                                }
                            }
                        }
                        echo '</div>';
                        echo '</li>';
                    }
                } else {
                    if ($event['event_type'] == 'form') {
                        //die(print_r($event));
                        $submission = $event['activities'][0];
                        $form_fields = isset($submission['form_fields']) ? json_decode($submission['form_fields']) : '';
                        $num_form_fieds = count($form_fields);
                        if (isset($tag->tag_slug)) {
                            $tag_text = '<a class="contact-list" href="' . wp_nonce_url(admin_url('admin.php?page=inboundrocket_contacts&contact_type=' . $tag->tag_slug)) . '">' . $tag->tag_text . '</a>';
                        } else {
                            $tag_text = '';
                        }
                        echo '<li class="event form-submission">';
                        echo '<div class="event-time">' . date('g:ia', strtotime($submission['event_date'])) . '</div>';
                        echo '<div class="event-content">';
                        echo '<p class="event-title">';
                        echo '' . __('Filled out Form', 'inboundrocket') . ' (' . $event['form_name'] . ') ' . __('on page', 'inboundrocket') . ' <a href="' . $submission['form_page_url'] . '">' . $submission['form_page_title'] . '</a>';
                        if (isset($event['form_tags'][0]['tag_slug'])) {
                            echo ' ' . __('and tagged as', 'inboundrocket') . ' ';
                            for ($i = 0; $i < count($event['form_tags']); $i++) {
                                echo '<a href="' . wp_nonce_url(admin_url('admin.php?page=inboundrocket_contacts&contact_type=' . $event['form_tags'][$i]['tag_slug'])) . '">' . $event['form_tags'][$i]['tag_text'] . '</a> ';
                            }
                        }
                        echo '</p>';
                        echo '<ul class="event-detail fields">';
                        if (isset($form_fields) && is_array($form_fields)) {
                            foreach ($form_fields as $num => $field) {
                                echo '<li class="field">';
                                echo '<label class="field-label">' . esc_html($field->label) . ':</label>';
                                echo '<p class="field-value">' . esc_html($field->value) . '</p>';
                                echo '</li>';
                            }
                        }
                        echo '</ul>';
                        echo '</div>';
                        echo '</li>';
                    } else {
                        if ($event['event_type'] == 'text-share') {
                            $share = $event['activities'][0];
                            $title = get_the_title($share['post_id']);
                            $url = get_permalink($share['post_id']);
                            if ($share['share_type'] == 'ss-twitter-text') {
                                $type = __('Twitter (using Selection Sharer power-up)', 'inboundrocket');
                            } elseif ($share['share_type'] == 'ss-facebook-text') {
                                $type = __('Facebook (using Selection Sharer power-up)', 'inboundrocket');
                            } elseif ($share['share_type'] == 'ss-linkedin-text') {
                                $type = __('LinkedIn (using Selection Sharer power-up)', 'inboundrocket');
                            } elseif ($share['share_type'] == 'ss-email-text') {
                                $type = __('Email (using Selection Sharer power-up)', 'inboundrocket');
                            } elseif ($share['share_type'] == 'click-to-tweet') {
                                $type = __('Twitter (using Click-To-Tweet power-up)', 'inboundrocket');
                            }
                            echo '<li class="event text-share">';
                            echo '<div class="event-time">' . date('g:ia', strtotime($share['event_date'])) . '</div>';
                            echo '<div class="event-content">';
                            echo '<p class="event-title">' . __('Shared a text snippet from', 'inboundrocket') . ' <a href="' . $url . '">' . $title . '</a></p>';
                            echo '<ul class="event-detail fields">';
                            echo '<li class="field">';
                            echo '<label class="field-label">' . __('Text shared', 'inboundrocket') . ':</label>';
                            echo '<p class="field-value">' . $share['share'] . '</p>';
                            echo '</li>';
                            echo '<li class="field">';
                            echo '<label class="field-label">' . __('Shared to', 'inboundrocket') . ':</label>';
                            echo '<p class="field-value">' . $type . '</p>';
                            echo '</li>';
                            echo '</ul>';
                            echo '</div>';
                            echo '</li>';
                        } else {
                            if ($event['event_type'] == 'image-share') {
                                $share = $event['activities'][0];
                                $title = get_the_title($share['post_id']);
                                $url = get_permalink($share['post_id']);
                                if ($share['share_type'] == 'is-twitter-image') {
                                    $type = __('Twitter (using Image Sharer power-up)', 'inboundrocket');
                                } elseif ($share['share_type'] == 'is-facebook-image') {
                                    $type = __('Facebook (using Image Sharer power-up)', 'inboundrocket');
                                } elseif ($share['share_type'] == 'is-pinterest-image') {
                                    $type = __('Pinterest (using Image Sharer power-up)', 'inboundrocket');
                                }
                                echo '<li class="event image-share">';
                                echo '<div class="event-time">' . date('g:ia', strtotime($share['share_date'])) . '</div>';
                                echo '<div class="event-content">';
                                echo '<p class="event-title">' . __('Shared an image from', 'inboundrocket') . ' <a href="' . $url . '">' . $title . '</a></p>';
                                echo '<ul class="event-detail fields">';
                                echo '<li class="field">';
                                echo '<label class="field-label">' . __('Image shared', 'inboundrocket') . '</label>';
                                echo '<p class="field-value">VISUAL</p>';
                                echo '</li>';
                                echo '<li class="field">';
                                echo '<label class="field-label">' . __('Shared to', 'inboundrocket') . ':</label>';
                                echo '<p class="field-value">' . $type . '</p>';
                                echo '</li>';
                                echo '</ul>';
                                echo '</div>';
                                echo '</li>';
                            }
                        }
                    }
                }
            }
            echo '</ul>';
            echo '</li>';
        }
        echo '</ul>';
        echo '</div>';
        echo '</div>';
        echo '<div id="col-left" class="metabox-holder">';
        echo '<div class="col-header">Lead Profile</div>';
        echo '<div class="inboundrocket-meta-section">';
        echo '<table class="inboundrocket-meta-table">';
        echo '<tbody>';
        echo '<tr>';
        echo '<td>';
        echo '<img class="contact-header-avatar inboundrocket-dynamic-avatar_' . esc_attr($lead_id) . '" src="http://www.gravatar.com/avatar/' . $gravatar_hash . '"/>';
        echo '</td>';
        echo '<td>';
        echo '<table>';
        echo '<tr>';
        echo '<td><strong>' . __('Name', 'inboundrocket') . ':</strong></td>';
        echo '<td style="padding-left:10px;">';
        echo !empty($lead_full_name) ? $lead_full_name : !empty($lead_firstname) ? esc_html($lead_firstname) : !empty($lead_lastname) ? esc_html($lead_lastname) : __('No name provided', 'inboundrocket');
        echo '</td>';
        echo '</tr>';
        echo '<tr>';
        echo '<td><strong>' . __('Email', 'inboundrocket') . ':</strong></td>';
        echo '<td style="padding-left:10px;"><a href="mailto:' . esc_html($lead_email) . '" target="_blank">' . esc_html($lead_email) . '</a></td>';
        echo '</tr>';
        echo '<tr>';
        echo '<td><strong>' . __('Original source', 'inboundrocket') . ':</strong></td>';
        echo '<td style="padding-left:10px;">' . ($ir_contact->history->lead->lead_source ? '<a href="' . esc_url($ir_contact->history->lead->lead_source) . '">' . esc_html($lead_source) . '</a>' : 'Direct') . '</td>';
        echo '</tr>';
        echo '<tr>';
        echo '<td><strong>' . __('First visit', 'inboundrocket') . ':</strong></td>';
        echo '<td style="padding-left:10px;">' . esc_html(self::date_format_contact_stat($ir_contact->history->lead->first_visit)) . '</td>';
        echo '</tr>';
        echo '<tr>';
        echo '<td><strong>' . __('Pageviews', 'inboundrocket') . ':</strong></td>';
        echo '<td style="padding-left:10px;">' . esc_html($ir_contact->history->lead->total_pageviews) . '</td>';
        echo '</tr>';
        echo '<tr>';
        echo '<td><strong>' . __('Form submissions', 'inboundrocket') . ':</strong></d>';
        echo '<td style="padding-left:10px;">' . esc_html($ir_contact->history->lead->total_submissions) . '</td>';
        echo '</tr>';
        echo '<tr>';
        echo '<td><strong>' . __('Total shares', 'inboundrocket') . ':</strong></td>';
        echo '<td style="padding-left:10px;">' . esc_html($ir_contact->history->lead->total_shares) . '</td>';
        echo '</tr>';
        echo '</table>';
        echo '</td>';
        echo '</tr>';
        echo '<tr>';
        // @TODO create execption for localhost and if no city provided etc.
        echo '<td><strong>' . __('Location', 'inboundrocket') . ':</strong><br />' . esc_html($lead_city) . ', ' . esc_html($lead_state) . ' ' . esc_html($lead_country) . '</td>';
        echo '<td style="text-align:right;"><a target="_blank" href="https://www.google.com/maps/place/' . esc_html($lead_city) . ',+' . esc_html($lead_state) . '">' . __('View Larger Map', 'inboundrocket') . '</a></td>';
        echo '</tr>';
        echo '<tr>';
        echo '<td colspan="2"><img class="contact-map" src="https://maps.googleapis.com/maps/api/staticmap?center=' . esc_attr($lead_loc) . '&zoom=13&size=660x175&maptype=roadmap
&markers=color:red%7C' . esc_attr($lead_loc) . '" /></td>';
        echo '</tr>';
        echo '</tbody>';
        echo '</table>';
        echo '</div>';
        echo '<div class="inboundrocket-meta-section">';
        echo '<h4 class="inboundrocket-meta-header inboundrocket-premium-tag">' . __('Personal Info', 'inboundrocket') . '</h4>' . __('More background information about the contact, coming soon for premium users.', 'inboundrocket');
        echo '<table class="inboundrocket-meta-table">';
        echo '<tbody>';
        echo '<tr></tr>';
        echo '</tbody>';
        echo '</table>';
        echo '</div>';
        echo '<div class="inboundrocket-meta-section">';
        echo '<h4 class="inboundrocket-meta-header inboundrocket-premium-tag">' . __('Company Info', 'inboundrocket') . '</h4>';
        // echo '<p><b>About '. esc_html($company_name) .'</b></p>';
        ?>
					<table class="inboundrocket-meta-table">
						<tbody>
							<tr><?php 
        _e('In our upcoming release for premium users we will display all relevant company info.', 'inboundrocket');
        ?>
</tr>
						</tbody>
					</table>
					<!--
						<table class="inboundrocket-meta-table">
						<tbody>
							<tr>
								<th>Website</th>
								<td><a href="https://www.lipsum.com/" target="_blank">Lorem Ipsum inc.</a></td>
							</tr>
							<tr>
								<th>LinkedIn</th>
								<td><a href="https://www.linkedin.com/company/loremipsum" target="_blank">Lorem Ipsum</a></td>
							</tr>
							<tr>
								<th>Facebook</th>
								<td><a href="https://www.facebook.com/loremipsum" target="_blank">Lorem Ipsum</a></td>
							</tr>
							<tr>
								<th>Twitter</th>
								<td><a href="https://twitter.com/loremipsum" target="_blank">@LoremIpsum</a></td>
							</tr>
						</tbody>
					</table>
					-->
				</div>
				
				<div class="inboundrocket-meta-section">
					<h4 class="inboundrocket-meta-header inboundrocket-premium-tag"><?php 
        _e('Notes', 'inboundrocket');
        ?>
</h4>
					<table class="inboundrocket-meta-table">
						<tbody>
							<tr></tr>
						</tbody>
					</table>
				</div>
			</div>
		</div>        

<?php 
    }