function ap_get_latest_history_html($post_id, $avatar = false, $icon = false) { $history = ap_get_latest_history($post_id); $html = ''; if ($history) { if ($avatar) { $html .= '<a class="ap-savatar" href="' . ap_user_link($history['user_id']) . '">' . get_avatar($history['user_id'], 20) . '</a>'; } if ($icon) { $html .= '<span class="' . ap_history_icon($history['type']) . ' ap-tlicon"></span>'; } $html .= '<span class="ap-post-history">' . sprintf(__('%s %s about %s ago', 'ap'), ap_user_display_name($history['user_id']), ap_history_name($history['type']), ap_human_time(mysql2date('U', $history['date']))) . '</span>'; } elseif (!$icon) { $html = '<span class="ap-post-history">' . sprintf(__('Asked by %s', 'ap'), ap_user_display_name()) . '</span>'; } if ($html) { return apply_filters('ap_latest_history_html', $html); } return false; }
/** * Get last active time * @param init $post_id * @return string * @since 2.0.1 */ function ap_last_active_time($post_id = false, $html = true) { $post = get_post($post_id); $post_id = !$post_id ? get_the_ID() : $post_id; $history = ap_get_latest_history($post_id); if (!$history) { $history['date'] = get_the_time('c', $post_id); $history['user_id'] = $post->post_author; $history['type'] = 'new_' . $post->post_type; } if (!$html) { return $history['date']; } $title = ap_history_title($history['type']); $title = esc_html('<span class="ap-post-history">' . sprintf(__('%s %s about %s ago', 'ap'), ap_user_display_name($history['user_id']), $title, '<time datetime="' . mysql2date('c', $history['date']) . '">' . ap_human_time(mysql2date('U', $history['date'])) . '</time>') . '</span>'); return sprintf(__('Active %s ago', 'ap'), '<a class="ap-tip" href="#" title="' . $title . '"><time datetime="' . mysql2date('c', $history['date']) . '">' . ap_human_time(mysql2date('U', $history['date']))) . '</time></a>'; }
/** * Restore __ap_history meta of question or answer * @param integer $post_id * @return void */ function ap_restore_question_history($post_id) { $history = ap_get_latest_history($post_id); if (!$history) { delete_post_meta($post_id, '__ap_history'); } else { update_post_meta($post_id, '__ap_history', array('type' => $history['type'], 'user_id' => $history['user_id'], 'date' => $history['date'])); } }
function ap_get_latest_history_html($post_id, $avatar = false, $icon = false) { $history = ap_get_latest_history($post_id); $html = ''; if ($history) { if ($icon) { $html .= '<span class="' . ap_history_icon($history['type']) . ' ap-tlicon"></span>'; } if ($avatar) { $html .= '<a class="ap-savatar" href="' . ap_user_link($history['user_id']) . '">' . get_avatar($history['user_id'], 22) . '</a>'; } if ($history['type'] == 'added_label' || $history['type'] == 'removed_label') { $label = ''; $terms = get_terms('question_label', array('include' => explode(',', $history['value']))); if ($terms) { foreach ($terms as $term) { $label .= ap_label_html($term); } } $label .= ' ' . _n('label', 'labels', count($terms), 'ap'); $title = ap_history_name($history['type'], $label); } else { $title = ap_history_name($history['type']); } $html .= '<span class="ap-post-history">' . sprintf(__('%s %s about <time class="updated" datetime="' . mysql2date('c', $history['date']) . '">%s</time> ago', 'ap'), ap_user_display_name($history['user_id']), $title, ap_human_time(mysql2date('U', $history['date']))) . '</span>'; } elseif (!$icon) { $html = '<span class="ap-post-history">' . sprintf(__('Asked by %s', 'ap'), ap_user_display_name()) . '</span>'; } if ($html) { return apply_filters('ap_latest_history_html', $html); } return false; }