/** * Insert view data in ap_meta table and update post meta ANSPRESS_VIEW_META * @param integer $data_id * @param string $type * @return boolean */ function ap_insert_views($data_id, $type) { if ($type == 'question') { $userid = get_current_user_id(); // log in DB only if not viewed before and not anonymous if (!ap_is_already_viewed(get_current_user_id(), $data_id) && $userid != 0) { /** * FILTER: ap_log_ip_view * Toggle ip logging for view count * @var boolean */ $log_ip = apply_filters('ap_log_ip_view', true); $ip = $log_ip ? $_SERVER['REMOTE_ADDR'] : ''; ap_add_meta($userid, 'post_view', $data_id, $ip); } $view = ap_get_qa_views($data_id); $view = $view + 1; update_post_meta($data_id, ANSPRESS_VIEW_META, apply_filters('ap_insert_views', $view)); do_action('after_insert_views', $data_id, $view); return true; } elseif ($type == 'profile') { $userid = get_current_user_id(); // log in DB only if not viewed before and not anonymous if (!ap_is_already_viewed(get_current_user_id(), $data_id, 'profile_view') && $userid != 0) { ap_add_meta($userid, 'profile_view', $data_id, $_SERVER['REMOTE_ADDR']); } $view = ap_get_profile_views($data_id); $view = $view + 1; update_user_meta($data_id, '__profile_views', apply_filters('ap_insert_views', $view)); do_action('after_insert_views', $data_id, $view); return true; } return false; }
/** * Question meta to display * @param false|integer $question_id * @return string * @since 2.0.1 */ function ap_display_question_metas($question_id = false) { if (false === $question_id) { $question_id = get_the_ID(); } $metas = array(); if (!is_question()) { if (ap_question_best_answer_selected()) { $metas['solved'] = '<span class="ap-best-answer-label ap-tip" title="' . __('answer accepted', 'ap') . '">' . __('Solved', 'ap') . '</span>'; } $view_count = ap_get_qa_views(); $metas['views'] = sprintf(__('<i>%d views</i>', 'ap'), $view_count); $metas['history'] = ap_get_latest_history_html($question_id, true); } /** * FILTER: ap_display_question_meta * Used to filter question display meta */ $metas = apply_filters('ap_display_question_metas', $metas, $question_id); $output = ''; if (!empty($metas) && is_array($metas)) { foreach ($metas as $meta => $display) { $output .= "<span class='ap-display-meta-item {$meta}'>{$display}</span>"; } } return $output; }
?> "> <span><?php echo ap_net_vote(); ?> </span> <?php _e('Votes', 'ap'); ?> </a> <a class="ap-vote-count ap-tip" href="#" title="<?php _e('Total views', 'ap'); ?> "> <span><?php echo ap_get_qa_views(); ?> </span> <?php _e('Views', 'ap'); ?> </a> <a class="ap-answer-count ap-tip" href="<?php echo ap_answers_link(); ?> " title="<?php _e('Total answers', 'ap'); ?> "> <span><?php echo ap_count_ans_meta();
<span class="ap-icon-hit ap-tlicon"></span> <ul class="ap-question-meta"> <li> <?php printf(__('<span>Asked</span><strong><time itemprop="datePublished" datetime="%s">%s Ago</time></strong>', 'ap'), get_the_time('c', get_question_id()), ap_human_time(get_the_time('U'))); ?> </li> <li> <?php $count = ap_count_ans(get_the_ID()); printf(_n('<span>Answer</span><strong data-view="ap-answer-count-label">1 Answer</strong>', '<span>Answers</span><strong data-view="ap-answer-count-label">%d Answers</strong>', $count, 'ap'), $count); ?> </li> <li> <?php $view_count = ap_get_qa_views(); printf(_n('<span>Viewed</span><strong>1 Times</strong>', '<span>Viewed</span><strong>%d Times</strong>', $view_count, 'ap'), $view_count); ?> </li> <li> <?php printf(__('<span>Active</span><strong><time class="updated" itemprop="dateUpdated" datetime="%s">%s Ago</time></strong>', 'ap'), mysql2date('c', ap_last_active(get_question_id())), ap_human_time(mysql2date('U', ap_last_active(get_question_id())))); ?> </li> </ul> </div> </div> <?php comments_template(); ?> </div>
/** * Return total view count * @return integer * @since 2.1 */ function ap_question_get_the_view_count() { return ap_get_qa_views(ap_question_get_the_ID()); }
_e('Ans', 'ap'); ?> </li> <?php } ?> <?php if ($show_views) { ?> <li class="ap-tip" title="<?php _e('Question was viewed by', 'ap'); ?> "><i class="ap-icon-hit ap-meta-icon"></i><?php printf(__('%d Views', 'ap'), ap_get_qa_views()); ?> </li> <?php } ?> <?php if ($show_category) { ?> <li class="ap-tip" title="<?php _e('Question category', 'ap'); ?> "><?php ap_question_categories_html(false, false); ?>