/**
     * @param $message - an array holding a result from the shub_message row
     * @param array $existing_rows - optional array passed in from the individual extension already having data for this row.
     * @return array
     */
    public function output_row($message, $existing_rows = array())
    {
        $extension_message = $this->get_message(false, false, $message['shub_message_id']);
        $messages = $extension_message->get_comments();
        $return = array();
        ob_start();
        echo $this->get_friendly_icon();
        ?>
        <a href="<?php 
        echo $extension_message->get_link();
        ?>
"
           target="_blank"><?php 
        echo htmlspecialchars($extension_message->get('account') ? $extension_message->get('account')->get('account_name') : 'Item');
        ?>
</a> <br/>
        <?php 
        echo htmlspecialchars($extension_message->get_type_pretty());
        ?>
        <?php 
        $return['shub_column_account'] = ob_get_clean();
        ob_start();
        $shub_product_id = $extension_message->get_product_id();
        $product_data = array();
        $item_data = array();
        $item = $extension_message->get('item');
        if (!$shub_product_id && $item) {
            $shub_product_id = $item->get('shub_product_id');
            $item_data = $item->get('item_data');
            if (!is_array($item_data)) {
                $item_data = array();
            }
        }
        if ($shub_product_id) {
            $shub_product = new SupportHubProduct();
            $shub_product->load($shub_product_id);
            $product_data = $shub_product->get('product_data');
            if (!empty($product_data['image'])) {
                ?>
                <img src="<?php 
                echo esc_attr($product_data['image']);
                ?>
" class="shub_friendly_icon">
            <?php 
            }
            ?>
            <?php 
            if (!empty($product_data['url'])) {
                ?>
                <a href="<?php 
                echo esc_url($product_data['url']);
                ?>
" target="_blank"><?php 
                echo htmlspecialchars($shub_product->get('product_name'));
                ?>
</a>
                <?php 
            } else {
                ?>
 <?php 
                echo htmlspecialchars($shub_product->get('product_name'));
                ?>
 <?php 
            }
        }
        $return['shub_column_product'] = ob_get_clean();
        $return['shub_column_time'] = '<span class="shub_time" data-time="' . esc_attr($extension_message->get('last_active')) . '" data-date="' . esc_attr(shub_print_date($extension_message->get('last_active'), true)) . '">' . shub_pretty_date($extension_message->get('last_active')) . '</span>';
        ob_start();
        // work out who this is from.
        $from = $extension_message->get_from();
        ?>
        <div class="shub_from_holder">
            <div class="shub_from_full">
                <?php 
        foreach ($from as $id => $from_data) {
            ?>
                    <div>
                        <a href="<?php 
            echo esc_url($from_data->get_link());
            ?>
" target="_blank"><img src="<?php 
            echo esc_attr($from_data->get_image());
            ?>
" class="shub_from_picture"></a> <?php 
            echo htmlspecialchars($from_data->get_name());
            ?>
                    </div>
                    <?php 
        }
        ?>
            </div>
            <?php 
        reset($from);
        if (isset($from_data)) {
            echo '<a href="' . $from_data->get_link() . '" target="_blank">' . '<img src="' . esc_attr($from_data->get_image()) . '" class="shub_from_picture"></a> ';
            echo '<span class="shub_from_count">';
            if (count($from) > 1) {
                echo '+' . (count($from) - 1);
            }
            echo '</span>';
        }
        ?>
        </div>
        <?php 
        $return['shub_column_from'] = ob_get_clean();
        ob_start();
        ?>
        <span style="float:right;">
		    <?php 
        echo count($messages) > 0 ? '(' . count($messages) . ')' : '';
        ?>
	    </span>
        <div class="shub_message_summary<?php 
        echo !isset($message['read_time']) || !$message['read_time'] ? ' unread' : '';
        ?>
"> <?php 
        // todo - pull in comments here, not just title/summary
        // todo - style customer and admin replies differently (eg <em> so we can easily see)
        $title = strip_tags($extension_message->get('title'));
        $summary = strip_tags($extension_message->get('summary'));
        echo htmlspecialchars(strlen($title) > 80 ? substr($title, 0, 80) . '...' : $title) . ($summary != $title ? '<br/>' . htmlspecialchars(strlen($summary) > 80 ? substr($summary, 0, 80) . '...' : $summary) : '');
        ?>
        </div>
        <?php 
        $return['shub_column_summary'] = ob_get_clean();
        ob_start();
        ?>
        <a href="<?php 
        echo $extension_message->link_open();
        ?>
" class="socialmessage_open shub_modal button" data-modaltitle="<?php 
        echo esc_attr($title);
        ?>
" data-network="<?php 
        echo esc_attr($this->id);
        ?>
" data-message_id="<?php 
        echo (int) $extension_message->get('shub_message_id');
        ?>
"><?php 
        _e('Open');
        ?>
</a>
        <?php 
        if ($extension_message->get('shub_status') == _shub_MESSAGE_STATUS_ANSWERED) {
            ?>
            <a href="#" class="socialmessage_action shub_message_action button"
               data-action="set-unanswered" data-post="<?php 
            echo esc_attr(json_encode(array('network' => $this->id, 'shub_message_id' => $extension_message->get('shub_message_id'))));
            ?>
"><?php 
            _e('Inbox');
            ?>
</a>
        <?php 
        } else {
            ?>
            <a href="#" class="socialmessage_action shub_message_action button"
               data-action="set-answered" data-post="<?php 
            echo esc_attr(json_encode(array('network' => $this->id, 'shub_message_id' => $extension_message->get('shub_message_id'))));
            ?>
"><?php 
            _e('Archive');
            ?>
</a>
        <?php 
        }
        ?>
        <?php 
        $return['shub_column_action'] = ob_get_clean();
        return $return;
    }
    public function output_message_list($allow_reply = true)
    {
        $message_id = $this->get('shub_message_id');
        $comments = $this->get_comments();
        $x = 0;
        foreach ($comments as $comment) {
            $x++;
            $from_user = $this->get_user($comment['shub_user_id']);
            $time = isset($comment['time']) ? $comment['time'] : false;
            // is this a queued-to-send message?
            $extra_class = '';
            $comment_status = '';
            $message_error = false;
            if (!empty($comment['shub_outbox_id'])) {
                $shub_outbox = new SupportHubOutbox($comment['shub_outbox_id']);
                if ($shub_outbox->get('shub_outbox_id') != $comment['shub_outbox_id']) {
                    // the outbox entry has been removed but this comment still references it
                    // todo: update this comment entry to not contain an shub_outbox_id
                } else {
                    switch ($shub_outbox->get('shub_status')) {
                        case _SHUB_OUTBOX_STATUS_QUEUED:
                        case _SHUB_OUTBOX_STATUS_SENDING:
                            $extra_class .= ' outbox_queued';
                            $comment_status = 'Currently Sending....' . $shub_outbox->get('shub_status');
                            break;
                        case _SHUB_OUTBOX_STATUS_FAILED:
                            $extra_class .= ' outbox_failed';
                            $comment_status = 'Failed to send message! Please check logs.';
                            $message_error = true;
                            break;
                    }
                }
            }
            if (!empty($comment['private'])) {
                $extra_class .= ' shub_message_private';
            }
            ?>
            <div class="shub_message shub_message_<?php 
            echo $x == 1 ? 'primary' : 'reply';
            echo $extra_class;
            ?>
">
                <div class="shub_message_picture">
                    <img src="<?php 
            echo $from_user->get_image();
            ?>
" />
                </div>
                <div class="shub_message_header">
                    <?php 
            if ($comment_status) {
                ?>
                        <div class="shub_comment_status"><?php 
                echo $comment_status;
                ?>
</div>
                    <?php 
            }
            ?>
                    <?php 
            echo $from_user->get_full_link();
            ?>
                    <span>
                        <?php 
            if ($time) {
                ?>
                            <span class="time" data-time="<?php 
                echo esc_attr($time);
                ?>
" data-date="<?php 
                echo esc_attr(shub_print_date($time, true));
                ?>
"><?php 
                echo shub_pretty_date($time);
                ?>
</span>
                        <?php 
            }
            ?>
                        <span class="wp_user">
                        <?php 
            // todo - better this! don't call on every message, load list in main loop and pass through all results.
            if (isset($envato_data['user_id']) && $envato_data['user_id']) {
                $user_info = get_userdata($envato_data['user_id']);
                echo ' (sent by ' . htmlspecialchars($user_info->display_name) . ')';
            }
            ?>
                        </span>
                        <span class="buyer_status_badges">
                            <?php 
            // work out of this buyer has bought something via the envato module.
            // first we have to find out what item this is:
            //echo "user:"******"<br>product:".$this->get_product_id()."<br>";
            // todo: store these as a flag in the message database so we can run stats on them and display a graph on the dashboard.
            $buyer_status = $this->get_buyer_status($comment['shub_user_id']);
            if (!empty($buyer_status['purchased'])) {
                echo '<span class="buyer_badge purchased">Purchased</span> ';
            }
            if (!empty($buyer_status['supported'])) {
                echo '<span class="buyer_badge supported">Supported</span> ';
            }
            if (!empty($buyer_status['unsupported'])) {
                echo '<span class="buyer_badge unsupported">Unsupported</span> ';
            }
            if (!empty($buyer_status['presale'])) {
                //echo '<span class="buyer_badge presale">Pre-sale</span> ';
            }
            // todo - add a badge for staff reply.
            ?>
                        </span>
                    </span>
                </div>
                <div class="shub_message_body">
                    <div>
                        <?php 
            echo shub_forum_text($comment['message_text']);
            ?>
                    </div>
                </div>
                <div class="shub_message_actions">
                    <?php 
            if ($message_error && !empty($comment['shub_outbox_id'])) {
                ?>
                        <button data-post="<?php 
                echo esc_attr(json_encode(array('action' => "support_hub_resend_outbox_message", 'shub_outbox_id' => $comment['shub_outbox_id'])));
                ?>
" class="btn button shub_message_action_button"><?php 
                _e('Re-Send');
                ?>
</button>
                        <button data-post="<?php 
                echo esc_attr(json_encode(array('action' => "support_hub_delete_outbox_message", 'shub_outbox_id' => $comment['shub_outbox_id'])));
                ?>
" class="btn button shub_message_action_button"><?php 
                _e('Delete Message');
                ?>
</button>
                    <?php 
            }
            ?>
                </div>
            </div>
        <?php 
        }
        if ($allow_reply) {
            ?>
            <div class="shub_message shub_message_reply shub_message_reply_box">
                <?php 
            $reply_shub_user = $this->get_reply_user();
            ?>
                <div class="shub_message_picture">
                      <img src="<?php 
            echo $reply_shub_user->get_image();
            ?>
" />
                </div>
                <div class="shub_message_header">
                     <?php 
            echo $reply_shub_user->get_full_link();
            ?>
                </div>
                <div class="shub_message_body">
                    <textarea placeholder="Write a reply..."></textarea>

                    <div class="shub_message_buttons">
                        <a href="#" class="shub_request_extra btn btn-default btn-xs button"
                           data-modaltitle="<?php 
            _e('Request Extra Details');
            ?>
" data-action="request_extra_details"
                           data-network="<?php 
            echo $this->network;
            ?>
"
                           data-<?php 
            echo $this->network;
            ?>
-message-id="<?php 
            echo $message_id;
            ?>
"><?php 
            _e('Request Details');
            ?>
</a>
                        <!-- <a href="#" class="shub_template_button btn btn-default btn-xs button"
                           data-modaltitle="<?php 
            _e('Send Template Message');
            ?>
" data-action="send_template_message"
                           data-network="<?php 
            echo $this->network;
            ?>
"
                           data-<?php 
            echo $this->network;
            ?>
-message-id="<?php 
            echo $message_id;
            ?>
"><?php 
            _e('Template');
            ?>
</a> -->

                        <button data-post="<?php 
            echo esc_attr(json_encode(array('account-id' => $this->get('shub_account_id'), 'message-id' => $message_id, 'network' => $this->network, 'last_activity' => $this->get('last_active'))));
            ?>
" class="btn button shub_send_message_reply_button shub_hide_when_no_message shub_button_loading"><?php 
            _e('Send');
            ?>
</button>
                    </div
                </div>
                <div class="shub_message_actions shub_hide_when_no_message">
                    <div>
                        <label
                            for="message_reply_archive_<?php 
            echo $message_id;
            ?>
"><?php 
            _e('Archive After Reply', 'shub');
            ?>
</label>
                        <input id="message_reply_archive_<?php 
            echo $message_id;
            ?>
" type="checkbox" name="archive"
                               data-reply="yes" value="1" checked>
                    </div>
                    <div>
                        <label
                            for="message_reply_private_<?php 
            echo $message_id;
            ?>
"><?php 
            _e('Mark As Private', 'shub');
            ?>
</label>
                        <input id="message_reply_private_<?php 
            echo $message_id;
            ?>
" type="checkbox" name="private"
                               data-reply="yes" value="1">
                    </div>
                    <div>
                        <label
                            for="message_reply_notify_email_<?php 
            echo $message_id;
            ?>
"><?php 
            _e('Notify Via Email', 'shub');
            ?>
</label>
                        <input id="message_reply_notify_email_<?php 
            echo $message_id;
            ?>
" type="checkbox" name="notify_email"
                               data-reply="yes" value="1">
                    </div>
                    <div>
                        <label
                            for="message_reply_debug_<?php 
            echo $message_id;
            ?>
"><?php 
            _e('Enable Debug Mode', 'shub');
            ?>
</label>
                        <input id="message_reply_debug_<?php 
            echo $message_id;
            ?>
" type="checkbox" name="debug"
                               data-reply="yes" value="1">
                    </div>
                    <?php 
            $this->reply_actions();
            ?>
                </div>
            </div>
            <?php 
        }
    }