/**
  * Get the leads for the contacts table based on $GET_['contact_type'] or $_GET['s'] (search)
  *
  * @return  array           associative array of all contacts
  */
 function get_contacts()
 {
     /*** 
            == FILTER ARGS ==
            - filter_action (visited)      = visited a specific page url (filter_action) 
            - filter_action (submitted)    = submitted a form on specific page url (filter_action) 
            - filter_content               = content for filter_action
            - filter_form                  = selector id/class
            - num_pageviews                = visited at least #n pages
            - s                            = search query on lead_email/lead_source
        */
     global $wpdb;
     $mysql_search_filter = '';
     $mysql_contact_type_filter = '';
     $mysql_action_filter = '';
     $filter_action_set = FALSE;
     $contact_type = isset($_GET['contact_type']) ? esc_attr($_GET['contact_type']) : 'all';
     $filter_action = isset($_GET['filter_action']) ? esc_attr($_GET['filter_action']) : 'visited';
     $filter_content = isset($_GET['filter_content']) ? esc_attr($_GET['filter_content']) : 'any-page';
     $s = isset($_GET['s']) ? esc_url($_GET['s']) : '';
     $filter_form = isset($_GET['filter_form']) ? esc_attr($_GET['filter_form']) : '';
     // search filter
     if (isset($s)) {
         $wp_version = get_bloginfo('version');
         $escaped_query = '';
         if ($wp_version >= 4) {
             $escaped_query = $wpdb->esc_like($s);
         } else {
             $escaped_query = @like_escape($s);
         }
         $mysql_search_filter = $wpdb->prepare(" AND ( l.lead_email LIKE '%%%s%%' OR l.lead_source LIKE '%%%s%%' ) ", $escaped_query, $escaped_query);
         inboundrocket_track_plugin_activity('Filtered on search term');
     }
     $filtered_contacts = array();
     // contact type filter
     if (!empty($contact_type) && $contact_type !== 'all') {
         // Query for the list_id, then find all hashkeys with that tag ID tied to them. Use those hashkeys to modify the query
         $q = $wpdb->prepare("SELECT \n                    DISTINCT ltr.contact_hashkey as lead_hashkey \n                FROM \n                    {$wpdb->ir_tag_relationships} ltr, {$wpdb->ir_tags} lt \n                WHERE \n                    lt.tag_id = ltr.tag_id AND \n                    ltr.tag_relationship_deleted = 0 AND  \n                    lt.tag_slug = %s GROUP BY ltr.contact_hashkey", $contact_type);
         $filtered_contacts = $wpdb->get_results($q, 'ARRAY_A');
         $num_contacts = count($filtered_contacts);
     } else {
         $q = "SELECT \n                    DISTINCT hashkey as lead_hashkey \n                FROM \n                    {$wpdb->ir_leads}\n                WHERE\n                \tlead_email IS NOT NULL\n                GROUP BY hashkey";
         $nonfiltered_contacts = $wpdb->get_results($q, 'ARRAY_A');
         $num_contacts = count($nonfiltered_contacts);
     }
     if (!empty($filter_action) && $filter_action === 'visited') {
         if (!empty($filter_content) && $filter_content !== 'any-page') {
             $q = $wpdb->prepare("SELECT lead_hashkey FROM {$wpdb->ir_pageviews} WHERE pageview_title LIKE '%%%s%%' GROUP BY lead_hashkey", $filter_content);
             $filtered_contacts = inboundrocket_merge_filtered_contacts($wpdb->get_results($q, 'ARRAY_A'), $filtered_contacts);
             $filter_action_set = TRUE;
             inboundrocket_track_plugin_activity('Filtered on page visited');
         }
     }
     // filter for a form submitted on a specific page
     if (!empty($filter_action) && $filter_action === 'submitted') {
         $filter_form = '';
         $filter_form_query = '';
         if (!empty($filter_form) && $filter_form && $filter_form !== 'any-form') {
             $filter_form = str_replace(array('#', '.'), '', $filter_form);
             $filter_form_query = $wpdb->prepare(" AND ( form_selector_id LIKE '%%%s%%' OR form_selector_classes LIKE '%%%s%%' )", $filter_form, $filter_form);
             inboundrocket_track_plugin_activity('Filtered on form submitted');
         }
         $q = $wpdb->prepare("SELECT lead_hashkey FROM {$wpdb->ir_submissions} WHERE form_page_title LIKE '%%%s%%' ", $filter_content != 'any-page' ? $filter_content : '');
         $q .= $filter_form_query ? $filter_form_query : '';
         $q .= " GROUP BY lead_hashkey";
         $filtered_contacts = inboundrocket_merge_filtered_contacts($wpdb->get_results($q, 'ARRAY_A'), $filtered_contacts);
         $filter_action_set = TRUE;
     }
     $filtered_hashkeys = inboundrocket_explode_filtered_contacts($filtered_contacts);
     $mysql_action_filter = '';
     if ($filter_action_set) {
         // If a filter action is set and there are no contacts, do a blank
         $mysql_action_filter = " AND l.hashkey IN ( " . ($filtered_hashkeys ? $filtered_hashkeys : "''") . " ) ";
     } else {
         $mysql_action_filter = $filtered_hashkeys ? " AND l.hashkey IN ( " . $filtered_hashkeys . " ) " : '';
     }
     // If a filter action isn't set, use the filtered hashkeys if they exist, else, don't include the statement
     // There's a filter and leads are in it
     if (isset($contact_type) && ($num_contacts || !$contact_type) || !isset($contact_type)) {
         $q = $wpdb->prepare("\n                SELECT \n                    l.lead_id AS lead_id,\n                    COUNT(DISTINCT ls.share_id) AS lead_shares,\n                    LOWER(DATE_SUB(l.lead_date, INTERVAL %d HOUR)) AS lead_date, l.lead_ip, l.lead_source, l.lead_email, l.hashkey, l.lead_first_name, l.lead_last_name,\n                    COUNT(DISTINCT s.form_id) AS lead_form_submissions,\n                    COUNT(DISTINCT p.pageview_id) AS lead_pageviews,\n                    LOWER(DATE_SUB(MAX(p.pageview_date), INTERVAL %d HOUR)) AS last_visit,\n                    ( SELECT COUNT(DISTINCT pageview_id) FROM {$wpdb->ir_pageviews} WHERE lead_hashkey = l.hashkey AND pageview_session_start = 1 AND pageview_deleted = 0 ) AS visits,\n                    ( SELECT MIN(pageview_source) AS pageview_source FROM {$wpdb->ir_pageviews} WHERE lead_hashkey = l.hashkey AND pageview_session_start = 1 AND pageview_deleted = 0 ) AS pageview_source \n                FROM \n                    {$wpdb->ir_leads} l\n                LEFT JOIN {$wpdb->ir_submissions} s ON l.hashkey = s.lead_hashkey\n                LEFT JOIN {$wpdb->ir_pageviews} p ON l.hashkey = p.lead_hashkey\n                LEFT JOIN {$wpdb->ir_shares} ls ON l.hashkey = ls.lead_hashkey \n                WHERE l.lead_email != '' AND l.lead_deleted = 0 AND l.hashkey != '' ", $wpdb->db_hour_offset, $wpdb->db_hour_offset);
         $q .= $mysql_contact_type_filter;
         $q .= $mysql_search_filter ? $mysql_search_filter : "";
         $q .= $mysql_action_filter ? $mysql_action_filter : "";
         $q .= " GROUP BY l.hashkey";
         $leads = $wpdb->get_results($q);
     } else {
         $leads = array();
     }
     $all_leads = array();
     $contact_count = 0;
     $num_pageviews = isset($_GET['num_pageviews']) ? esc_attr($_GET['num_pageviews']) : '';
     $page = isset($_REQUEST['page']) ? esc_attr($_REQUEST['page']) : '';
     $paged = isset($_GET['paged']) ? esc_attr($_GET['paged']) : '';
     if (count($leads)) {
         foreach ($leads as $key => $lead) {
             // filter for number of page views and skipping lead if it doesn't meet the minimum
             if (isset($filter_action) && $filter_action === 'num_pageviews') {
                 if ($lead->lead_pageviews < $filter_content) {
                     continue;
                 }
             }
             $url = inboundrocket_strip_params_from_url($lead->lead_source);
             $redirect_url = '';
             if (isset($contact_type) || isset($filter_action) || isset($filter_form) || isset($filter_content) || isset($num_pageviews) || isset($s) || isset($paged)) {
                 $redirect_url = urlencode(inboundrocket_get_current_url());
             }
             $lead_array = array('ID' => $lead->lead_id, 'hashkey' => $lead->hashkey, 'email' => sprintf('<a href="?page=%s&action=%s&lead=%s%s">' . "<img class='pull-left inboundrocket-contact-avatar inboundrocket-dynamic-avatar_" . substr($lead->lead_id, -1) . "' src='http://www.gravatar.com/avatar/" . md5(strtolower(trim($lead->lead_email))) . "' width='50px' height='50px' style='margin-top: 2px; border-radius: 25px;'/> " . '</a>', $page, 'view', $lead->lead_id, $redirect_url ? '&redirect_to=' . $redirect_url : '') . sprintf('<a href="?page=%s&action=%s&lead=%s%s">%s' . $lead->lead_email . '</a>', $page, 'view', $lead->lead_id, $redirect_url ? '&redirect_to=' . $redirect_url : '', strlen($lead->lead_first_name) || strlen($lead->lead_last_name) ? '<b>' . $lead->lead_first_name . ' ' . $lead->lead_last_name . '</b><br>' : ''), 'visits' => !isset($lead->visits) ? 1 : $lead->visits, 'submissions' => $lead->lead_form_submissions, 'shares' => isset($lead->lead_shares) ? $lead->lead_shares : '0', 'pageviews' => isset($lead->lead_pageviews) ? $lead->lead_pageviews : '0', 'date' => date('Y-m-d g:ia', strtotime($lead->lead_date)), 'source' => $lead->pageview_source ? "<a title=\"Visit page\" href=\"" . esc_url($lead->pageview_source) . "\" target=\"_blank\">" . inboundrocket_strip_params_from_url($lead->pageview_source) . "</a>" : 'Direct', 'last_visit' => date('Y-m-d g:ia', strtotime($lead->last_visit)), 'source' => $lead->lead_source ? "<a title=\"Visit page\" href=\"" . esc_url($lead->lead_source) . "\" target=\"_blank\">" . inboundrocket_strip_params_from_url($lead->lead_source) . "</a>" : 'Direct');
             array_push($all_leads, $lead_array);
             $contact_count++;
         }
     }
     $this->total_filtered = count($all_leads);
     return $all_leads;
 }
    /**
     * 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 
    }
 /**
  * Creates each session section separated by a spacer
  *
  * @param   stdClass    IR_Contact
  * @return  string      concatenated string of sessions
  */
 function build_sessions($history)
 {
     $built_sessions = "";
     $sessions = $history->sessions;
     foreach ($sessions as &$session) {
         $first_event = end($session['events']);
         $first_event_date = $first_event['activities'][0]['event_date'];
         $session_date = date('F j, Y, g:i a', strtotime($first_event_date));
         $last_event = array_values($session['events']);
         $last_event = $last_event[0];
         $last_activity = end($last_event['activities']);
         $session_end_time = date('g:i a', strtotime($last_activity['event_date']));
         $format = '<table class="row lead-timeline__date" style="border-spacing: 0;border-collapse: collapse;padding: 0px;vertical-align: top;text-align: left;width: 100%%;position: relative;display: block;"><tr style="padding: 0;vertical-align: top;text-align: left;"><td class="wrapper last" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 10px 20px 0px 0px;vertical-align: top;text-align: left;position: relative;padding-right: 0px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><table class="twelve columns" style="border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;margin: 0 auto;width: 580px;"><tr style="padding: 0;vertical-align: top;text-align: left;"><td class="text-pad" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0px 0px 10px;vertical-align: top;text-align: left;padding-left: 10px;padding-right: 10px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><h4 style="color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: bold;padding: 0;margin: 0;text-align: left;line-height: 1.3;word-break: normal;font-size: 14px;">%s - %s</h4></td><td class="expander" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;visibility: hidden;width: 0px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"></td></tr></table></td></tr></table>';
         $built_sessions .= sprintf($format, $session_date, $session_end_time);
         $events = $session['events'];
         foreach ($events as &$event) {
             if ($event['event_type'] == 'pageview') {
                 $pageview = $event['activities'][0];
                 $pageview_time = date('g:ia', strtotime($pageview['event_date']));
                 $pageview_url = $pageview['pageview_url'];
                 $pageview_title = $pageview['pageview_title'];
                 $pageview_source = $pageview['pageview_source'];
                 $format = '<table class="row lead-timeline__event pageview" style="border-spacing: 0;border-collapse: collapse;padding: 0px;vertical-align: top;text-align: left;width: 100%%;position: relative;display: block;background-color: #fff;border-top: 1px solid #dedede;border-right: 1px solid #dedede;border-left: 4px solid #28c;"><tr style="padding: 0;vertical-align: top;text-align: left;"><td class="wrapper" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 10px 20px 0px 0px;vertical-align: top;text-align: left;position: relative;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><table class="two columns" style="border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;margin: 0 auto;width: 80px;"><tr style="padding: 0;vertical-align: top;text-align: left;"><td class="text-pad" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0px 0px 10px;vertical-align: top;text-align: left;padding-left: 10px;padding-right: 10px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><p class="lead-timeline__event-time" style="margin: 0;color: #1f6696;font-family: Helvetica, Arial, sans-serif;font-weight: normal;padding: 0;text-align: left;line-height: 19px;font-size: 14px;margin-bottom: 10px;">%s</p></td><td class="expander" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;visibility: hidden;width: 0px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"></td></tr></table></td><td class="wrapper last" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 10px 20px 0px 0px;vertical-align: top;text-align: left;position: relative;padding-right: 0px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><table class="ten columns" style="border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;margin: 0 auto;width: 480px;"><tr style="padding: 0;vertical-align: top;text-align: left;"><td class="text-pad" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0px 0px 10px;vertical-align: top;text-align: left;padding-left: 10px;padding-right: 10px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><p class="lead-timeline__event-title" style="margin: 0;color: #1f6696;font-family: Helvetica, Arial, sans-serif;font-weight: normal;padding: 0;text-align: left;line-height: 19px;font-size: 14px;margin-bottom: 10px;">%s</p><p class="lead-timeline__pageview-url" style="margin: 0;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;padding: 0;text-align: left;line-height: 19px;font-size: 14px;margin-bottom: 10px;"><a href="%s" style="color: #999;text-decoration: none;">%s</a></p></td><td class="expander" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;visibility: hidden;width: 0px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"></td></tr></table></td></tr></table>';
                 $built_sessions .= sprintf($format, $pageview_time, $pageview_title, $pageview_url, inboundrocket_strip_params_from_url($pageview_url));
                 if ($pageview['event_date'] == $first_event_date) {
                     $format = '<table class="row lead-timeline__event traffic-source" style="margin-bottom: 20px;border-spacing: 0;border-collapse: collapse;padding: 0px;vertical-align: top;text-align: left;width: 100%%;position: relative;display: block;background-color: #fff;border-top: 1px solid #dedede;border-right: 1px solid #dedede;border-left: 4px solid #99aa1f;border-bottom: 1px solid #dedede;"><tr style="padding: 0;vertical-align: top;text-align: left;"><td class="wrapper" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 10px 20px 0px 0px;vertical-align: top;text-align: left;position: relative;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><table class="two columns" style="border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;margin: 0 auto;width: 80px;"><tr style="padding: 0;vertical-align: top;text-align: left;"><td class="text-pad" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0px 0px 10px;vertical-align: top;text-align: left;padding-left: 10px;padding-right: 10px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><p class="lead-timeline__event-time" style="margin: 0;color: #727e14;font-family: Helvetica, Arial, sans-serif;font-weight: normal;padding: 0;text-align: left;line-height: 19px;font-size: 14px;margin-bottom: 10px;">%s</p></td><td class="expander" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;visibility: hidden;width: 0px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"></td></tr></table></td><td class="wrapper last" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 10px 20px 0px 0px;vertical-align: top;text-align: left;position: relative;padding-right: 0px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><table class="ten columns" style="border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;margin: 0 auto;width: 480px;"><tr style="padding: 0;vertical-align: top;text-align: left;"><td class="text-pad" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0px 0px 10px;vertical-align: top;text-align: left;padding-left: 10px;padding-right: 10px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><p class="lead-timeline__event-title" style="margin: 0;color: #727e14;font-family: Helvetica, Arial, sans-serif;font-weight: normal;padding: 0;text-align: left;line-height: 19px;font-size: 14px;margin-bottom: 10px;">Traffic Source: %s</p> %s </td><td class="expander" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;visibility: hidden;width: 0px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"></td></tr></table></td></tr></table>';
                     $built_sessions .= sprintf($format, $pageview_time, $pageview_source ? '<a href="' . $pageview_source . '">' . inboundrocket_strip_params_from_url($pageview_source) . '</a>' : 'Direct', $this->build_source_url_params($pageview_source));
                 }
             } else {
                 if ($event['event_type'] == 'form') {
                     $submission = $event['activities'][0];
                     $submission_Time = date('g:ia', strtotime($submission['event_date']));
                     $submission_url = $submission['form_page_url'];
                     $submission_page_title = $submission['form_page_title'];
                     $submission_form_fields = json_decode($submission['form_fields']);
                     $submission_tags = '';
                     if (count($event['form_tags'])) {
                         $submission_tags = ' and tagged as ';
                         for ($i = 0; $i < count($event['form_tags']); $i++) {
                             $submission_tags .= '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=inboundrocket_contacts&contact_type=' . $event['form_tags'][$i]['tag_slug'] . '">' . $event['form_tags'][$i]['tag_text'] . '</a> ';
                         }
                     }
                     $format = '<table class="row lead-timeline__event submission" style="border-spacing: 0;border-collapse: collapse;padding: 0px;vertical-align: top;text-align: left;width: 100%%;position: relative;display: block;background-color: #fff;border-top: 1px solid #dedede;border-right: 1px solid #dedede;border-left: 4px solid #f6601d;"><tr style="padding: 0;vertical-align: top;text-align: left;"><td class="wrapper" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 10px 20px 0px 0px;vertical-align: top;text-align: left;position: relative;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><table class="two columns" style="border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;margin: 0 auto;width: 80px;"><tr style="padding: 0;vertical-align: top;text-align: left;"><td class="text-pad" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0px 0px 10px;vertical-align: top;text-align: left;padding-left: 10px;padding-right: 10px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><p class="lead-timeline__event-time" style="margin: 0;color: #b34a12;font-family: Helvetica, Arial, sans-serif;font-weight: normal;padding: 0;text-align: left;line-height: 19px;font-size: 14px;margin-bottom: 10px;">%s</p></td><td class="expander" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;visibility: hidden;width: 0px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"></td></tr></table></td><td class="wrapper last" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 10px 20px 0px 0px;vertical-align: top;text-align: left;position: relative;padding-right: 0px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><table class="ten columns" style="border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;margin: 0 auto;width: 480px;"><tr style="padding: 0;vertical-align: top;text-align: left;"><td class="text-pad" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0px 0px 10px;vertical-align: top;text-align: left;padding-left: 10px;padding-right: 10px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"><p class="lead-timeline__event-title" style="margin: 0;color: #b34a12;font-family: Helvetica, Arial, sans-serif;font-weight: normal;padding: 0;text-align: left;line-height: 19px;font-size: 14px;margin-bottom: 10px;">Filled out ' . $event['form_name'] . ' on page <a href="%s" style="color: #2ba6cb;text-decoration: none;">%s</a>%s</p> %s </td><td class="expander" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;visibility: hidden;width: 0px;color: #222222;font-family: Helvetica, Arial, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;"></td></tr></table></td></tr></table>';
                     $built_sessions .= sprintf($format, $submission_Time, $submission_url, $submission_page_title, $submission_tags, $this->build_form_fields($submission_form_fields));
                 } else {
                     if ($event['event_type'] == 'text-share') {
                         $textshare = $event['activities'][0];
                         $textshare_Time = date('g:ia', strtotime($textshare['event_date']));
                         $textshare_url = get_permalink($textshare['post_id']);
                         $textshare_page_title = get_the_title($textshare['post_id']);
                         $textshare_text_shared = $textshare['share'];
                         $textshare_shared_to = $textshare['share_type'];
                         $format = '<table class="row lead-timeline__event text-share" style="border-spacing: 0; border-collapse: collapse; padding: 0px; vertical-align: top; text-align: left; width: 100%%; position: relative; display: block; background-color: #fff; border-top: 1px solid #dedede; border-right: 1px solid #dedede; border-left: 4px solid #00caf0; border-bottom: 1px solid #dedede;"> <tr style="padding: 0; vertical-align: top; text-align: left;"> <td class="wrapper" style="word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; border-collapse: collapse; padding: 10px 0px 0px 0px; vertical-align: top; text-align: left; position: relative; color: #222222; font-family: Helvetica, Arial, sans-serif; font-weight: normal; margin: 0; line-height: 19px; font-size: 14px;"> <table class="two columns" style="border-spacing: 0; border-collapse: collapse; padding: 0; vertical-align: top; text-align: left; margin: 0 auto; width: 80px;"> <tr style="padding: 0; vertical-align: top; text-align: left;"> <td class="text-pad" style="word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; border-collapse: collapse; padding: 0px 0px 10px; vertical-align: top; text-align: left; padding-left: 10px; color: #222222; font-family: Helvetica, Arial, sans-serif; font-weight: normal; margin: 0; line-height: 19px; font-size: 14px;"> <p class="lead-timeline__event-time" style="margin: 0; color: #00caf0; font-family: Helvetica, Arial, sans-serif; font-weight: normal; padding: 0; text-align: left; line-height: 19px; font-size: 14px; margin-bottom: 10px;">%s</p></td><td class="expander" style="word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; border-collapse: collapse; padding: 0; vertical-align: top; text-align: left; visibility: hidden; width: 0px; color: #222222; font-family: Helvetica, Arial, sans-serif; font-weight: normal; margin: 0; line-height: 19px; font-size: 14px;"></td></tr></table> </td><td class="wrapper last" style="word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; border-collapse: collapse; padding: 10px 0px 0px 0px; vertical-align: top; text-align: left; position: relative; padding-right: 0px; color: #222222; font-family: Helvetica, Arial, sans-serif; font-weight: normal; margin: 0; line-height: 19px; font-size: 14px;"> <table class="ten columns" style="border-spacing: 0; border-collapse: collapse; padding: 0; vertical-align: top; text-align: left; margin: 0 auto; width: 480px;"> <tr style="padding: 0; vertical-align: top; text-align: left;"> <td class="text-pad" style="word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; border-collapse: collapse; padding: 0px 0px 10px; vertical-align: top; text-align: left; padding-left: 10px; color: #222222; font-family: Helvetica, Arial, sans-serif; font-weight: normal; margin: 0; line-height: 19px; font-size: 14px;"> <p class="lead-timeline__event-title" style="margin: 0; color: #00caf0; font-family: Helvetica, Arial, sans-serif; font-weight: normal; padding: 0; text-align: left; line-height: 19px; font-size: 14px; margin-bottom: 10px;">Shared a text snippet from <a href="%s" style="text-decoration: none; color: #6DC6DD;">%s</a></p><p style="text-transform: uppercase; letter-spacing: 0.05em; color: #999; margin-bottom: 6px; font-size: 0.9em;">text shared:</p><p style="font-size: 13px; line-height: 1.5;">%s</p><p style="text-transform: uppercase; letter-spacing: 0.05em; color: #999; margin-bottom: 6px; font-size: 0.9em;">shared to:</p><p style="font-size: 13px; line-height: 1.5;">%s</p></td><td class="expander" style="word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; border-collapse: collapse; padding: 0; vertical-align: top; text-align: left; visibility: hidden; width: 0px; color: #222222; font-family: Helvetica, Arial, sans-serif; font-weight: normal; margin: 0; line-height: 19px; font-size: 14px;"></td></tr></table> </td></tr></table>';
                         $built_sessions .= sprintf($format, $textshare_Time, $textshare_url, $textshare_page_title, $textshare_text_shared, $textshare_shared_to);
                     }
                 }
             }
         }
     }
     return $built_sessions;
 }