Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 59 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| MailPoet_Contact_Tabs | |
0.00% |
0 / 58 |
|
0.00% |
0 / 5 |
420 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| instance | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| init_hooks | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| append_info_tabs | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
| generate_mailpoet_tab_html | |
0.00% |
0 / 41 |
|
0.00% |
0 / 1 |
156 | |||
| 1 | <?php |
| 2 | /* |
| 3 | * Jetpack CRM |
| 4 | * https://jetpackcrm.com |
| 5 | * |
| 6 | * MailPoet Sync: Contact Tabs |
| 7 | * Adds extra tab(s) to contact single view: vitals tab set |
| 8 | */ |
| 9 | namespace Automattic\JetpackCRM; |
| 10 | |
| 11 | // block direct access |
| 12 | defined( 'ZEROBSCRM_PATH' ) || exit( 0 ); |
| 13 | |
| 14 | /** |
| 15 | * MailPoet Contact Tabs class |
| 16 | */ |
| 17 | class MailPoet_Contact_Tabs { |
| 18 | |
| 19 | /** |
| 20 | * The single instance of the class. |
| 21 | */ |
| 22 | protected static $_instance = null; |
| 23 | |
| 24 | /** |
| 25 | * Setup MailPoet Contact Tabs |
| 26 | */ |
| 27 | public function __construct() { |
| 28 | |
| 29 | global $zbs; |
| 30 | |
| 31 | if ( $zbs->mailpoet_is_active() ) { |
| 32 | |
| 33 | // Initialise Hooks |
| 34 | $this->init_hooks(); |
| 35 | |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Main Class Instance. |
| 41 | * |
| 42 | * Ensures only one instance of MailPoet_Contact_Tabs is loaded or can be loaded. |
| 43 | * |
| 44 | * @since 2.0 |
| 45 | * @static |
| 46 | * @see |
| 47 | * @return MailPoet_Contact_Tabs main instance |
| 48 | */ |
| 49 | public static function instance() { |
| 50 | if ( self::$_instance === null ) { |
| 51 | self::$_instance = new self(); |
| 52 | } |
| 53 | return self::$_instance; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Initialise Hooks |
| 58 | */ |
| 59 | private function init_hooks() { |
| 60 | |
| 61 | // add in tabs |
| 62 | add_filter( 'jetpack-crm-contact-vital-tabs', array( $this, 'append_info_tabs' ), 10, 3 ); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Wire in ant applicable tabs |
| 67 | */ |
| 68 | public function append_info_tabs( $array, $id, $contact ) { |
| 69 | |
| 70 | global $zbs; |
| 71 | |
| 72 | if ( ! is_array( $array ) ) { |
| 73 | $array = array(); |
| 74 | } |
| 75 | |
| 76 | // MailPoet Info |
| 77 | if ( $zbs->mailpoet_is_active() ) { |
| 78 | $array[] = array( |
| 79 | 'id' => 'mailpoet-tab', |
| 80 | 'name' => __( 'MailPoet', 'zero-bs-crm' ), |
| 81 | 'content' => $this->generate_mailpoet_tab_html( $id, $contact ), |
| 82 | ); |
| 83 | } |
| 84 | |
| 85 | return $array; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Draw the Contacts MailPoet Vitals tab |
| 90 | */ |
| 91 | private function generate_mailpoet_tab_html( $object_id = -1, $contact = array() ) { |
| 92 | |
| 93 | global $zbs; |
| 94 | |
| 95 | // return html |
| 96 | $html = ''; |
| 97 | |
| 98 | // retrieve lists - we can do this either by checking the current email against mailpoet (as below) |
| 99 | // ... or we could use $contact['external_sources']['mailpoet'][0]['uid'] to call the sub by id |
| 100 | // ... here I've opted for current email, but if we need to we can switch to ^^ |
| 101 | |
| 102 | // Get just the lists: |
| 103 | // $subscriber_lists = $zbs->modules->mailpoet->get_mailpoet_lists_for_contact_from_email( $contact['email'] ); |
| 104 | |
| 105 | // Get all MailPoet subscriber info: |
| 106 | $subscriber = $zbs->modules->mailpoet->get_mailpoet_subscriber_by_email( $contact['email'] ); |
| 107 | |
| 108 | if ( is_array( $subscriber ) ) { |
| 109 | |
| 110 | $html = '<table class="ui fixed single line celled table zbs-view-vital-mailpoet"><tbody>'; |
| 111 | |
| 112 | // ID |
| 113 | /* |
| 114 | $html .= '<tr id="zbs-view-vital-mailpoet-id" class="wraplines">'; |
| 115 | $html .= '<td class="zbs-view-vital-mailpoet-label">ID</td>'; |
| 116 | $html .= '<td class="zbs-view-vital-mailpoet-value">' . $subscriber['id'] . '</td>'; |
| 117 | $html .= '</tr>'; |
| 118 | */ |
| 119 | |
| 120 | // Status |
| 121 | $html .= '<tr id="zbs-view-vital-mailpoet-status" class="wraplines">'; |
| 122 | $html .= '<td class="zbs-view-vital-mailpoet-label">' . __( 'Status', 'zero-bs-crm' ) . '</td>'; |
| 123 | $html .= '<td class="zbs-view-vital-mailpoet-value">' . ucwords( $subscriber['status'] ) . '</td>'; |
| 124 | $html .= '</tr>'; |
| 125 | |
| 126 | // Email Count |
| 127 | $html .= '<tr id="zbs-view-vital-mailpoet-email-count" class="wraplines">'; |
| 128 | $html .= '<td class="zbs-view-vital-mailpoet-label">' . __( 'Email Count', 'zero-bs-crm' ) . '</td>'; |
| 129 | $html .= '<td class="zbs-view-vital-mailpoet-value">' . zeroBSCRM_prettifyLongInts( ( isset( $subscriber['email_count'] ) ? $subscriber['email_count'] : 0 ) ) . '</td>'; |
| 130 | $html .= '</tr>'; |
| 131 | |
| 132 | // Lists |
| 133 | $html .= '<tr id="zbs-view-vital-mailpoet-lists" class="wraplines">'; |
| 134 | $html .= '<td class="zbs-view-vital-mailpoet-label">' . __( 'Lists', 'zero-bs-crm' ) . '</td>'; |
| 135 | $html .= '<td class="zbs-view-vital-mailpoet-value">'; |
| 136 | |
| 137 | if ( ! is_array( $subscriber['subscriptions'] ) || count( $subscriber['subscriptions'] ) <= 0 ) { |
| 138 | |
| 139 | $html .= '<div class="ui message info blue"><i class="ui icon info circle"></i>' . __( 'This contact is not a MailPoet subscriber.', 'zero-bs-crm' ) . '</div>'; |
| 140 | |
| 141 | } else { |
| 142 | |
| 143 | $html .= '<div class="ui segment">'; |
| 144 | $sub_count = 0; |
| 145 | |
| 146 | foreach ( $subscriber['subscriptions'] as $subscription ) { |
| 147 | |
| 148 | if ( $sub_count > 0 ) { |
| 149 | |
| 150 | $html .= '<div class="ui divider"></div>'; |
| 151 | |
| 152 | } |
| 153 | |
| 154 | $html .= '<a href="' . $zbs->modules->mailpoet->get_mailpoet_list_subs_link( $subscription['segment_id'] ) . '" target="_blank">' . ( isset( $subscription['segment_name'] ) ? $subscription['segment_name'] : __( 'MailPoet Segment', 'zero-bs-crm' ) ) . '</a>'; |
| 155 | |
| 156 | ++$sub_count; |
| 157 | } |
| 158 | |
| 159 | $html .= '</div>'; |
| 160 | |
| 161 | } |
| 162 | |
| 163 | $html .= '</td>'; |
| 164 | $html .= '</tr>'; |
| 165 | |
| 166 | // Tags |
| 167 | $html .= '<tr id="zbs-view-vital-mailpoet-lists" class="wraplines">'; |
| 168 | $html .= '<td class="zbs-view-vital-mailpoet-label">' . __( 'Tags', 'zero-bs-crm' ) . '</td>'; |
| 169 | $html .= '<td class="zbs-view-vital-mailpoet-value">'; |
| 170 | |
| 171 | if ( ! is_array( $subscriber['tags'] ) || count( $subscriber['tags'] ) <= 0 ) { |
| 172 | |
| 173 | $html .= '<div class="ui message info blue"><i class="ui icon info circle"></i>' . __( 'This MailPoet Subscriber does not have any tags.', 'zero-bs-crm' ) . '</div>'; |
| 174 | |
| 175 | } else { |
| 176 | |
| 177 | foreach ( $subscriber['tags'] as $tag ) { |
| 178 | |
| 179 | $html .= '<a class="ui tag label" href="' . $zbs->modules->mailpoet->get_mailpoet_list_tagged_link( $tag['tag_id'] ) . '" target="_blank">' . ( isset( $tag['name'] ) ? $tag['name'] : __( 'Unknown', 'zero-bs-crm' ) ) . '</a> '; |
| 180 | |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | $html .= '</td>'; |
| 185 | $html .= '</tr>'; |
| 186 | |
| 187 | $html .= '</tbody></table>'; |
| 188 | |
| 189 | // link |
| 190 | $html .= '<div style="padding:2em;text-align:center"><a href="' . $zbs->modules->mailpoet->get_mailpoet_sub_stats_link( $subscriber['id'] ) . '" target="_blank" class="ui button blue">' . __( 'View in MailPoet', 'zero-bs-crm' ) . '</a></div>'; |
| 191 | |
| 192 | } else { |
| 193 | |
| 194 | $html .= '<div class="ui message"><i class="ui icon info circle"></i>' . __( 'This contact does not have a MailPoet subscriber.', 'zero-bs-crm' ) . '</div>'; |
| 195 | |
| 196 | } |
| 197 | |
| 198 | return $html; |
| 199 | } |
| 200 | } |