public function getLogRowHTMLOutput($oneLogRow, $args)
{
$defaults = array("type" => "overview");
$args = wp_parse_args($args, $defaults);
$header_html = $this->getLogRowHeaderOutput($oneLogRow);
$plain_text_html = $this->getLogRowPlainTextOutput($oneLogRow);
$sender_image_html = $this->getLogRowSenderImageOutput($oneLogRow);
// Details = for example thumbnail of media
$details_html = trim($this->getLogRowDetailsOutput($oneLogRow));
if ($details_html) {
$details_html = sprintf('<div class="SimpleHistoryLogitem__details">%1$s</div>', $details_html);
}
// subsequentOccasions = including the current one
$occasions_count = $oneLogRow->subsequentOccasions - 1;
$occasions_html = "";
if ($occasions_count > 0) {
$occasions_html = '<div class="SimpleHistoryLogitem__occasions">';
$occasions_html .= '<a href="#" class="SimpleHistoryLogitem__occasionsLink">';
$occasions_html .= sprintf(_n('+%1$s similar event', '+%1$s similar events', $occasions_count, "simple-history"), $occasions_count);
$occasions_html .= '</a>';
$occasions_html .= '<span class="SimpleHistoryLogitem__occasionsLoading">';
$occasions_html .= sprintf(__('Loading…', "simple-history"), $occasions_count);
$occasions_html .= '</span>';
$occasions_html .= '<span class="SimpleHistoryLogitem__occasionsLoaded">';
$occasions_html .= sprintf(__('Showing %1$s more', "simple-history"), $occasions_count);
$occasions_html .= '</span>';
$occasions_html .= '</div>';
}
// Add data atributes to log row, so plugins can do stuff
$data_attrs = "";
$data_attrs .= sprintf(' data-row-id="%1$d" ', $oneLogRow->id);
$data_attrs .= sprintf(' data-occasions-count="%1$d" ', $occasions_count);
$data_attrs .= sprintf(' data-occasions-id="%1$s" ', esc_attr($oneLogRow->occasionsID));
if (isset($oneLogRow->context["_server_remote_addr"])) {
$data_attrs .= sprintf(' data-ip-address="%1$s" ', esc_attr($oneLogRow->context["_server_remote_addr"]));
}
$arr_found_additional_ip_headers = $this->instantiatedLoggers["SimpleLogger"]["instance"]->get_event_ip_number_headers($oneLogRow);
if ($arr_found_additional_ip_headers) {
$data_attrs .= sprintf(' data-ip-address-multiple="1" ');
}
$data_attrs .= sprintf(' data-logger="%1$s" ', esc_attr($oneLogRow->logger));
$data_attrs .= sprintf(' data-level="%1$s" ', esc_attr($oneLogRow->level));
$data_attrs .= sprintf(' data-date="%1$s" ', esc_attr($oneLogRow->date));
$data_attrs .= sprintf(' data-initiator="%1$s" ', esc_attr($oneLogRow->initiator));
if (isset($oneLogRow->context["_user_id"])) {
$data_attrs .= sprintf(' data-initiator-user-id="%1$d" ', $oneLogRow->context["_user_id"]);
}
// If type is single then include more details
$more_details_html = "";
if ($args["type"] == "single") {
$more_details_html = apply_filters("simple_history/log_html_output_details_single/html_before_context_table", $more_details_html, $oneLogRow);
$more_details_html .= sprintf('<h2 class="SimpleHistoryLogitem__moreDetailsHeadline">%1$s</h2>', __("Context data", "simple-history"));
$more_details_html .= "<p>" . __("This is potentially useful meta data that a logger has saved.", "simple-history") . "</p>";
$more_details_html .= "<table class='SimpleHistoryLogitem__moreDetailsContext'>";
$more_details_html .= sprintf('<tr>
<th>%1$s</th>
<th>%2$s</th>
</tr>', "Key", "Value");
$logRowKeysToShow = array_fill_keys(array_keys((array) $oneLogRow), true);
/**
* Filter what keys to show from oneLogRow
*
* Array is in format
*
* Array
* (
* [id] => 1
* [logger] => 1
* [level] => 1
* ...
* )
*
*
* @since 2.0.29
*
* @param array with keys to show. key to show = key. value = boolean to show or not.
* @param object log row to show details from
*/
$logRowKeysToShow = apply_filters("simple_history/log_html_output_details_table/row_keys_to_show", $logRowKeysToShow, $oneLogRow);
// Hide some keys by default
unset($logRowKeysToShow["occasionsID"], $logRowKeysToShow["subsequentOccasions"], $logRowKeysToShow["rep"], $logRowKeysToShow["repeated"], $logRowKeysToShow["occasionsIDType"], $logRowKeysToShow["context"], $logRowKeysToShow["type"]);
foreach ($oneLogRow as $rowKey => $rowVal) {
// Only columns from oneLogRow that exist in logRowKeysToShow will be outputed
if (!array_key_exists($rowKey, $logRowKeysToShow) || !$logRowKeysToShow[$rowKey]) {
continue;
}
// skip arrays and objects and such
if (is_array($rowVal) || is_object($rowVal)) {
continue;
}
$more_details_html .= sprintf('<tr>
<td>%1$s</td>
<td>%2$s</td>
</tr>', esc_html($rowKey), esc_html($rowVal));
}
$logRowContextKeysToShow = array_fill_keys(array_keys((array) $oneLogRow->context), true);
/*
error_log($this->json_encode($logRowContextKeysToShow));
Marker - 2 maj 2015 20:51:54
[02-May-2015 18:51:57 UTC] {
"post_id": true,
"post_type": true,
"post_title": true,
"post_prev_post_title": true,
"post_new_post_title": true,
"post_prev_post_name": true,
"post_new_post_name": true,
"_message_key": true,
"_user_id": true,
"_user_login": true,
"_user_email": true,
"_server_remote_addr": true,
"_server_http_referer": true
}
*/
/**
* Filter what keys to show from the row context
*
* Array is in format
*
* Array
* (
* [plugin_slug] => 1
* [plugin_name] => 1
* [plugin_title] => 1
* [plugin_description] => 1
* [plugin_author] => 1
* [plugin_version] => 1
* ...
* )
*
*
* @since 2.0.29
*
* @param array with keys to show. key to show = key. value = boolean to show or not.
* @param object log row to show details from
*/
$logRowContextKeysToShow = apply_filters("simple_history/log_html_output_details_table/context_keys_to_show", $logRowContextKeysToShow, $oneLogRow);
foreach ($oneLogRow->context as $contextKey => $contextVal) {
// Only columns from context that exist in logRowContextKeysToShow will be outputed
if (!array_key_exists($contextKey, $logRowContextKeysToShow) || !$logRowContextKeysToShow[$contextKey]) {
continue;
}
$more_details_html .= sprintf('<tr>
<td>%1$s</td>
<td>%2$s</td>
</tr>', esc_html($contextKey), esc_html($contextVal));
}
$more_details_html .= "</table>";
$more_details_html = apply_filters("simple_history/log_html_output_details_single/html_after_context_table", $more_details_html, $oneLogRow);
$more_details_html = sprintf('<div class="SimpleHistoryLogitem__moreDetails">%1$s</div>', $more_details_html);
}
// Classes to add to log item li element
$classes = array("SimpleHistoryLogitem", "SimpleHistoryLogitem--loglevel-{$oneLogRow->level}", "SimpleHistoryLogitem--logger-{$oneLogRow->logger}");
if (isset($oneLogRow->initiator) && !empty($oneLogRow->initiator)) {
$classes[] = "SimpleHistoryLogitem--initiator-" . $oneLogRow->initiator;
}
if ($arr_found_additional_ip_headers) {
$classes[] = "SimpleHistoryLogitem--IPAddress-multiple";
}
// Always append the log level tag
$log_level_tag_html = sprintf(' <span class="SimpleHistoryLogitem--logleveltag SimpleHistoryLogitem--logleveltag-%1$s">%2$s</span>', $oneLogRow->level, $this->getLogLevelTranslated($oneLogRow->level));
$plain_text_html .= $log_level_tag_html;
/**
* Filter to modify classes added to item li element
*
* @since 2.0.7
*
* @param $classes Array with classes
*/
$classes = apply_filters("simple_history/logrowhtmloutput/classes", $classes);
// Generate the HTML output for a row
$output = sprintf('
<li %8$s class="%10$s">
<div class="SimpleHistoryLogitem__firstcol">
<div class="SimpleHistoryLogitem__senderImage">%3$s</div>
</div>
<div class="SimpleHistoryLogitem__secondcol">
<div class="SimpleHistoryLogitem__header">%1$s</div>
<div class="SimpleHistoryLogitem__text">%2$s</div>
%6$s <!-- details_html -->
%9$s <!-- more details html -->
%4$s <!-- occasions -->
</div>
</li>
', $header_html, $plain_text_html, $sender_image_html, $occasions_html, $oneLogRow->level, $details_html, $oneLogRow->logger, $data_attrs, $more_details_html, esc_attr(join(" ", $classes)));
// Get the main message row.
// Should be as plain as possible, like plain text
// but with links to for example users and posts
//SimpleLoggerFormatter::getRowTextOutput($oneLogRow);
// Get detailed HTML-based output
// May include images, lists, any cool stuff needed to view
//SimpleLoggerFormatter::getRowHTMLOutput($oneLogRow);
return trim($output);
}