public function test_get_comment_excerpt_filtered() { $comment_id = self::factory()->comment->create(array('comment_content' => self::$bacon_comment)); add_filter('comment_excerpt_length', array($this, '_filter_comment_excerpt_length')); $excerpt = get_comment_excerpt($comment_id); $this->assertEquals(10, count(explode(' ', $excerpt))); }
function wildcat_recent_comments() { $comments = get_comments(array('number' => 5, 'date_query' => array(array('column' => 'comment_date', 'after' => '1 year ago')))); echo '<ul>'; foreach ($comments as $comment) { $link = get_comment_link($comment->comment_ID); $author = get_comment_author($comment->comment_ID); $excerpt = get_comment_excerpt($comment->comment_ID); echo "<li><a href=\"{$link}\">{$author}</a>: {$excerpt}</li>"; } echo "</ul>\n"; }
function widget($args, $instance) { global $comments, $comment; $cache = wp_cache_get('widget_recent_notes', 'widget'); if (!is_array($cache)) { $cache = array(); } if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return; } extract($args, EXTR_SKIP); $output = ''; $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Notes') : $instance['title']); if (!($number = (int) $instance['number'])) { $number = 5; } else { if ($number < 1) { $number = 1; } } if ($instance['datetime'] == 'date') { $new_instance['datetime'] = get_comment_date() . ": "; } elseif ($instance['datetime'] == 'date/time') { $new_instance['datetime'] = get_comment_date() . " at " . get_comment_time() . ": "; } else { $new_instance['datetime'] = null; } $datetime = $new_instance['datetime']; $comments = get_comments(array('number' => $number, 'status' => 'approve')); $output .= $before_widget; if ($title) { $output .= $before_title . $title . $after_title; } $output .= '<ul id="recentnotes">'; if ($comments) { foreach ((array) $comments as $comment) { $output .= '<li class="recentnotes">' . sprintf(_x('%1$s', 'widgets'), $datetime . '<a href="' . esc_url(get_comment_link($comment->comment_ID)) . '">' . get_the_title($comment->comment_post_ID) . ': ' . get_comment_excerpt() . '</a>') . '</li>'; } } $output .= '</ul>'; $output .= $after_widget; echo $output; $cache[$args['widget_id']] = $output; wp_cache_set('widget_recent_notes', $cache, 'widget'); }
function widget($args, $instance) { extract($args); /* User-selected settings. */ $title = apply_filters('widget_title', $instance['title']); $show_count = $instance['show_count']; $show_avatar = isset($instance['show_avatar']) ? $instance['show_avatar'] : false; $avatar_size = $instance['avatar_size']; $excerpt_length = $instance['excerpt_length']; /* Before widget (defined by themes). */ echo $before_widget; /* Title of widget (before and after defined by themes). */ if ($title) { echo $before_title . $title . $after_title; } $comments = get_comments(array('number' => $show_count, 'status' => 'approve', 'type' => 'comment')); echo '<ul class="recent-comments-list">'; foreach ($comments as $comment) { $comm_title = get_the_title($comment->comment_post_ID); $comm_link = get_comment_link($comment->comment_ID); ?> <li> <?php if ($show_avatar) { echo '<a href="' . $comm_link . '">' . get_avatar($comment, $size = $avatar_size) . '</a>'; } ?> <a href="<?php echo $comm_link; ?> "><?php echo $comment->comment_author; ?> :</a> <?php echo substr(get_comment_excerpt($comment->comment_ID), 0, $excerpt_length); ?> …<div class="clear"></div> </li> <?php } echo '</ul>'; /* After widget (defined by themes). */ echo $after_widget; }
function widget($args, $instance) { global $comments, $comment; $cache = wp_cache_get('widget_recent_comments', 'widget'); if (!is_array($cache)) { $cache = array(); } if (!isset($args['widget_id'])) { $args['widget_id'] = $this->id; } if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return; } extract($args); $output = ''; $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments', 'largo') : $instance['title'], $instance, $this->id_base); if (empty($instance['number']) || !($number = absint($instance['number']))) { $number = 5; } $comments = get_comments(apply_filters('widget_comments_args', array('number' => $number, 'status' => 'approve', 'post_status' => 'publish', 'type' => 'comment'))); $output .= $before_widget; if ($title) { $output .= $before_title . $title . $after_title; } $output .= '<ul id="recentcomments">'; if ($comments) { foreach ((array) $comments as $comment) { $output .= '<li class="recentcomments">'; $output .= '<p class="comment-excerpt">“' . get_comment_excerpt() . '”</p>'; $output .= '<p class="comment-meta">— ' . get_comment_author_link() . ' on <a href="' . esc_url(get_comment_link($comment->comment_ID)) . '">' . get_the_title($comment->comment_post_ID) . '</a></p>'; $output .= '</li>'; } } $output .= '</ul>'; $output .= $after_widget; echo $output; $cache[$args['widget_id']] = $output; wp_cache_set('widget_recent_comments', $cache, 'widget'); }
/** * Techozoic Home Page Comment Preview * * Comment preview section on home page. Pull comment excerpt for approved comments * displays in an unordered list at bottom of each post. * * @param string id of current post to pull comments for * * @access public * @since 1.8.7 */ function tech_comment_preview($ID) { global $comment; $tech_comment_num = of_get_option('comment_preview_num', '3'); $output = ""; $comment_array = get_comments(array('post_id' => $ID, 'number' => $tech_comment_num, 'type' => 'comment', 'status' => 'approve')); if ($comment_array) { $output .= '<ul class="comment-preview">'; foreach ($comment_array as $comment) { $output .= '<li class="comments-link">'; $output .= '<div class="comment-author">'; $output .= '<a href="' . get_comment_link() . '" title="' . $comment->comment_author . __(' posted on ', 'techozoic') . get_comment_date() . '">'; $output .= $comment->comment_author . __(' posted on ', 'techozoic') . get_comment_date(); $output .= '</a>'; $output .= '</div>'; $output .= '<div class="comment-text">'; $output .= get_comment_excerpt($comment->comment_ID); $output .= '</div>'; $output .= '</li>'; } $output .= '</ul>'; } print $output; }
/** * Return activity action title * @param array $args Activity arguments. * @return string * @since 2.4 */ function ap_get_activity_action_title($args) { $type = $args['type']; $content = ''; $primary_user_link = ap_user_link($args['user_id']); $primary_user_name = ap_user_display_name(array('user_id' => $args['user_id'])); $user = '******' . $primary_user_link . '">' . $primary_user_name . '</a>'; switch ($type) { case 'new_question': $question_title = '<a href="' . get_permalink($args['question_id']) . '">' . get_the_title($args['question_id']) . '</a>'; $content .= sprintf(__('%s asked question %s', 'ap'), $user, $question_title); break; case 'new_answer': $answer_title = '<a href="' . get_permalink($args['item_id']) . '">' . get_the_title($args['item_id']) . '</a>'; $content .= sprintf(__('%s answered on %s', 'ap'), $user, $answer_title); break; case 'new_comment': $question_title = '<a href="' . get_permalink($args['question_id']) . '">' . get_the_title($args['question_id']) . '</a>'; $comment = '<span class="ap-comment-excerpt"><a href="' . get_comment_link($args['item_id']) . '">' . get_comment_excerpt($args['item_id']) . '</a></span>'; $content .= sprintf(__('%s commented on question %s %s', 'ap'), $user, $question_title, $comment); break; case 'new_comment_answer': $title = '<a href="' . get_permalink($args['question_id']) . '">' . get_the_title($args['question_id']) . '</a>'; $comment = '<span class="ap-comment-excerpt"><a href="' . get_comment_link($args['item_id']) . '">' . get_comment_excerpt($args['item_id']) . '</a></span>'; $content .= sprintf(__('%s commented on answer %s %s', 'ap'), $user, $title, $comment); break; case 'edit_question': $question_title = '<a href="' . get_permalink($args['question_id']) . '">' . get_the_title($args['question_id']) . '</a>'; $content .= sprintf(__('%s edited question %s', 'ap'), $user, $question_title); break; case 'edit_answer': $answer_title = '<a href="' . get_permalink($args['item_id']) . '">' . get_the_title($args['item_id']) . '</a>'; $content .= sprintf(__('%s edited answer %s', 'ap'), $user, $answer_title); break; case 'edit_comment': $comment = '<a href="' . get_comment_link($args['item_id']) . '">' . get_comment_excerpt($args['item_id']) . '</a>'; $question_title = '<a href="' . get_permalink($args['question_id']) . '">' . get_the_title($args['question_id']) . '</a>'; $content .= sprintf(__('%s edited comment on %s %s', 'ap'), $user, $question_title, $comment); break; case 'answer_selected': $question_title = '<a href="' . get_permalink($args['question_id']) . '">' . get_the_title($args['question_id']) . '</a>'; $content .= sprintf(__('%s selected best answer for %s', 'ap'), $user, $question_title); break; case 'answer_unselected': $question_title = '<a href="' . get_permalink($args['question_id']) . '">' . get_the_title($args['question_id']) . '</a>'; $content .= sprintf(__('%s unselected best answer for question %s', 'ap'), $user, $question_title); break; case 'status_updated': $title = '<a href="' . get_permalink($args['question_id']) . '">' . get_the_title($args['question_id']) . '</a>'; $content .= sprintf(__('%s updated status of question %s', 'ap'), $user, $title); break; case 'status_updated_answer': $title = '<a href="' . get_permalink($args['item_id']) . '">' . get_the_title($args['item_id']) . '</a>'; $content .= sprintf(__('%s updated status of answer %s', 'ap'), $user, $title); break; } return apply_filters('ap_activity_action_title', $content, $args); }
?> { 'author_name': <?php echo cf_json_encode(get_comment_author()); ?> , 'author_url': <?php echo cf_json_encode(get_comment_author_url()); ?> , 'date': <?php echo cf_json_encode(get_comment_date('m/d/Y h:i A')); ?> , 'excerpt': <?php echo cf_json_encode(str_replace(array("\r\n", "\n", "\r"), '<br />', get_comment_excerpt())); ?> , 'type': <?php echo cf_json_encode($comment_type); ?> } <?php $count++; } } ?> ], 'trackback_url': <?php echo cf_json_encode(get_trackback_url()); ?>
public function edit_comment($comment_id) { $comment = get_comment($comment_id); $post = get_post($comment->comment_post_ID); if (!('question' == $post->post_type || 'answer' == $post->post_type)) { return; } $activity_arr = array('item_id' => $comment->comment_ID, 'permalink' => get_comment_link($comment), 'parent_type' => 'comment'); $user = ap_activity_user_name(get_current_user_id()); $comment_excerpt = '<span class="ap-comment-excerpt"><a href="' . get_comment_link($comment->comment_ID) . '">' . get_comment_excerpt($comment->comment_ID) . '</a></span>'; $post_title = '<a class="ap-q-link" href="' . wp_get_shortlink($comment->comment_post_ID) . '">' . get_the_title($comment->comment_post_ID) . '</a>'; if ($post->post_type == 'question') { $activity_arr['type'] = 'new_comment'; $activity_arr['question_id'] = $comment->comment_post_ID; $activity_arr['content'] = sprintf(__('%s commented on question %s %s', 'anspress-question-answer'), $user, $post_title, $comment_excerpt); } else { $activity_arr['type'] = 'new_comment_answer'; $activity_arr['question_id'] = $post->post_parent; $activity_arr['answer_id'] = $comment->comment_post_ID; $activity_arr['content'] = sprintf(__('%s commented on answer %s %s', 'anspress-question-answer'), $user, $post_title, $comment_excerpt); } $activity_id = ap_new_activity($activity_arr); // Add comment activity meta. update_post_meta($comment->comment_post_ID, '__ap_activity', array('type' => 'new_comment', 'user_id' => $comment->user_id, 'date' => current_time('mysql'))); if ($post->post_type == 'question') { $subscribers = ap_subscriber_ids($comment->comment_post_ID, array('q_post', 'q_all')); } else { $subscribers = ap_subscriber_ids($comment->comment_post_ID, 'a_all'); } // Remove current user from subscribers. $subscribers = ap_unset_current_user_from_subscribers($subscribers); ap_new_notification($activity_id, $subscribers); }
$i++; global $comment; $comment = $comments[$id]; ?> <div class="index-comment"> <div class="ic-avatar"><?php echo get_avatar(get_comment_author_email(), '37'); ?> </div> <div class="ic-text"> <div class="ic-meta ic-author"><?php echo get_comment_author_link(); ?> </div> <div class="ic-content"><?php echo get_comment_excerpt(); ?> </div> <div class="ic-meta ic-date"><?php echo get_comment_date('j F y'); ?> at <?php echo get_comment_date('H:i'); ?> </div> </div> </div> <?php } } }
function widget($args, $instance) { global $comments, $comment; $cache = wp_cache_get('widget_recent_comments', 'widget'); if (!is_array($cache)) { $cache = array(); } if (!isset($args['widget_id'])) { $args['widget_id'] = $this->id; } if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return; } extract($args, EXTR_SKIP); $output = ''; $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments', 'shiword') : $instance['title'], $instance, $this->id_base); if (empty($instance['number']) || !($number = absint($instance['number']))) { $number = 5; } if (!isset($instance['excerpt']) || empty($instance['excerpt']) || !($excerpt = absint($instance['excerpt']))) { $excerpt = 0; } $comments = get_comments(array('number' => $number, 'status' => 'approve', 'post_status' => 'publish')); $output .= $before_widget; if ($title) { $output .= $before_title . $title . $after_title; } $output .= '<ul id="recentcomments">'; if ($comments) { foreach ((array) $comments as $comment) { $the_excerpt = $excerpt ? '<div class="rc-preview">' . get_comment_excerpt($comment->comment_ID) . '</div>' : ''; $the_class = $excerpt ? ' class="small"' : ''; $output .= '<li class="recentcomments"> <span' . $the_class . '>' . sprintf(_x('%1$s on %2$s', 'widgets', 'shiword'), get_comment_author_link(), '<a href="' . esc_url(get_comment_link($comment->comment_ID)) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</span> ' . $the_excerpt . ' </li>'; } } $output .= '</ul>'; $output .= $after_widget; echo $output; $cache[$args['widget_id']] = $output; wp_cache_set('widget_recent_comments', $cache, 'widget'); }
/** * Return activity action title * @param array $args Activity arguments. * @return string * @since 2.4 */ function ap_get_activity_action_title($args) { $type = $args['type']; $content = ''; $primary_user_link = ap_user_link($args['user_id']); $primary_user_name = ap_user_display_name(array('user_id' => $args['user_id'])); $user = '******' . $primary_user_link . '">' . $primary_user_name . '</a>'; switch ($type) { case 'edit_comment': $comment = '<a class="ap-c-link" href="' . get_comment_link($args['item_id']) . '">' . get_comment_excerpt($args['item_id']) . '</a>'; $question_title = '<a class="ap-q-link" href="' . get_permalink($args['question_id']) . '">' . get_the_title($args['question_id']) . '</a>'; $content .= sprintf(__('%s edited comment on %s %s', 'ap'), $user, $question_title, $comment); break; case 'status_updated': $title = '<a class="ap-q-link" href="' . get_permalink($args['question_id']) . '">' . get_the_title($args['question_id']) . '</a>'; $content .= sprintf(__('%s updated status of question %s', 'ap'), $user, $title); break; case 'status_updated_answer': $title = '<a class="ap-q-link" href="' . get_permalink($args['item_id']) . '">' . get_the_title($args['item_id']) . '</a>'; $content .= sprintf(__('%s updated status of answer %s', 'ap'), $user, $title); break; case 'vote_up': $post = get_post($args['item_id']); $cpt_type = $post->post_type == 'question' ? __('question', 'ap') : __('answer', 'ap'); $title = '<a class="ap-q-link" href="' . $args['permalink'] . '">' . $post->post_title . '</a>'; $content .= sprintf(__('%s voted up on %s %s', 'ap'), $user, $cpt_type, $title); break; case 'reputation_gain': $post = get_post($args['item_id']); $title = '<a class="ap-q-link" href="' . $args['permalink'] . '">' . $post->post_title . '</a>'; $content .= sprintf(__('%s received %d reputation on %s', 'ap'), $user, $args['reputation'], $title); break; } return apply_filters('ap_activity_action_title', $content, $args); }
public function getExcerpt() { return get_comment_excerpt($this->getId()); }
?> { 'author_name': '<?php echo htmlspecialchars(get_comment_author(), ENT_QUOTES); ?> ', 'author_url': '<?php echo htmlspecialchars(get_comment_author_url(), ENT_QUOTES); ?> ', 'date': '<?php comment_date('m/d/Y h:i A'); ?> ', 'excerpt': '<?php echo str_replace(array("\r\n", "\n", "\r"), '<br />', htmlspecialchars(get_comment_excerpt(), ENT_QUOTES)); ?> ', 'type': '<?php echo $comment_type; ?> ' } <?php $count++; } } ?> ], 'trackback_url': '<?php trackback_url();
/** * Return the excerpt of the comment currently being iterated on. * * @package WP Idea Stream * @subpackage comments/tags * * @since 2.0.0 * * @uses wp_idea_stream() to get plugin's main instance * @uses get_post() to get the idea the comment is linked to * @uses get_comment_excerpt() to get the comment excerpt * @uses apply_filters() call 'wp_idea_stream_comments_get_comment_excerpt' to override the output * @return string the excerpt. */ function wp_idea_stream_comments_get_comment_excerpt() { $comment = wp_idea_stream()->comment_query_loop->comment; $title = ''; $idea = $comment->comment_post_ID; if (!empty($comment->idea)) { $idea = $comment->idea; } $idea = get_post($idea); if (post_password_required($idea)) { $excerpt = __('The idea, the comment was posted on, is password protected, you will need it to view its content.', 'wp-idea-stream'); // Private } else { if (!empty($idea->post_status) && 'private' == $idea->post_status && !wp_idea_stream_user_can('read_idea', $idea->ID)) { $excerpt = __('The idea, the comment was posted on is private, you cannot view its content.', 'wp-idea-stream'); // Public } else { $excerpt = get_comment_excerpt(wp_idea_stream()->comment_query_loop->comment->comment_ID); } } /** * @param string $excerpt the comment excerpt */ return apply_filters('wp_idea_stream_comments_get_comment_excerpt', $excerpt); }
function widget($args, $instance) { global $comments, $comment; $cache = wp_cache_get('widget_recent_comments', 'widget'); if (!is_array($cache)) { $cache = array(); } if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return; } extract($args, EXTR_SKIP); $output = ''; $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title']); if (!($number = absint($instance['number']))) { $number = 5; } $comments = get_comments(array('number' => $number, 'status' => 'approve', 'post_status' => 'publish')); $output .= $before_widget; if ($title) { $output .= $before_title . $title . $after_title; } $output .= '<ul id="recentcomments">'; if ($comments) { foreach ((array) $comments as $comment) { //$output .= '<li class="recentcomments">' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>'; $output .= '<li class="recentcomments"><a class="ui-link-inherit" href="' . esc_url(get_comment_link($comment->comment_ID)) . '">' . sprintf(_x('%1$s %2$s %3$s', 'widgets'), '<span class="ui-li-heading">' . get_the_title($comment->comment_post_ID) . '</span>', '<p><strong>' . get_comment_author($comment->comment_ID) . '</strong></p>', '<div><p>' . get_comment_excerpt($comment->comment_ID) . '</p></div>') . '</a></li>'; } } $output .= '</ul>'; $output .= $after_widget; echo $output; $cache[$args['widget_id']] = $output; wp_cache_set('widget_recent_comments', $cache, 'widget'); }
<?php foreach ($ultimatemember->shortcodes->loop as $comment) { ?> <div class="um-item"> <div class="um-item-link"><i class="um-icon-chatboxes"></i><a href="<?php echo get_comment_link($comment->comment_ID); ?> "><?php echo get_comment_excerpt($comment->comment_ID); ?> </a></div> <div class="um-item-meta"> <span><?php printf(__('On <a href="%1$s">%2$s</a>', 'ultimatemember'), get_permalink($comment->comment_post_ID), get_the_title($comment->comment_post_ID)); ?> </span> </div> </div> <?php } ?> <?php if (isset($ultimatemember->shortcodes->modified_args) && count($ultimatemember->shortcodes->loop) >= 10) { ?>
public function content($atts, $content = null) { $title = $order = $page_link = $text_size = $items = $el_class = $width = $el_position = ''; extract(shortcode_atts(array('title' => '', 'text_size' => '', 'item_count' => '-1', 'display_type' => 'standard', 'order_by' => 'rand', 'order' => 'ASC', 'link' => 'no', 'show_thumbnail' => 'yes', 'show_rating' => 'yes', 'columns' => '1', 'el_class' => '', 'el_position' => '', 'width' => '1/2'), $atts)); $output = ''; $next_icon = apply_filters('sf_next_icon', '<i class="ss-navigateright"></i>'); // REVIEWS QUERY SETUP global $woocommerce, $wpdb, $product; if ($display_type == "masonry") { $items .= '<ul class="product-reviews testimonials woocommerce masonry-items spb-isotope col-' . $columns . ' gutters row clearfix" data-layout-mode="masonry">'; } else { $items .= '<ul class="product-reviews testimonials woocommerce clearfix">'; } /* COLUMN VARIABLE CONFIG ================================================== */ $item_class = ""; if ($display_type == "masonry") { if ($columns == "1") { $item_class = "col-sm-12 "; } else { if ($columns == "2") { $item_class = "col-sm-6 "; } else { if ($columns == "3") { $item_class = "col-sm-4 "; } else { if ($columns == "4") { $item_class = "col-sm-3 "; } else { if ($columns == "5") { $item_class = "col-sm-sf-5 "; } } } } } } // PRODUCT REVIEWS LOOP $rand_numeric = rand(1, 2500000); if ($order_by == 'rand') { $order_by = 'RAND (' . $rand_numeric . ')'; } else { if ($order_by == 'title') { $order_by = 'p.post_title' . ' ' . $order; } else { if ($order_by == 'date') { $order_by = 'c.comment_date' . ' ' . $order; } } } $query = "SELECT c.* FROM {$wpdb->prefix}posts p, {$wpdb->prefix}comments c WHERE p.ID = c.comment_post_ID AND c.comment_approved > 0 AND p.post_type = 'product' AND p.post_status = 'publish' AND p.comment_count > 0 ORDER BY " . $order_by . " LIMIT 0, " . $item_count; $comments_products = $wpdb->get_results($query, OBJECT); if ($comments_products) { foreach ($comments_products as $comment_product) { $id_ = $comment_product->comment_post_ID; $name_author = $comment_product->comment_author; $comment_id = $comment_product->comment_ID; $_product = get_product($id_); $rating = intval(get_comment_meta($comment_id, 'rating', true)); $rating_html = $_product->get_rating_html($rating); if (get_the_title($id_)) { $link_title = get_the_title($id_); } else { $link_title = $id_; } $image_link = wp_get_attachment_image_src(get_post_thumbnail_id($id_), 'shop_thumbnail'); $items .= '<li id="comment-' . $comment_id . '" class="testimonial has-cite ' . $item_class . '">'; $items .= '<div class="content-comment testimonial-text">'; if ($link == "yes") { $items .= '<a href="' . get_comment_link($comment_id) . '" title="' . esc_attr($link_title) . '"></a>'; } $items .= '<div class="product-details clearfix">'; if (has_post_thumbnail($id_) && $show_thumbnail == "yes") { $items .= get_the_post_thumbnail($id_, 'shop_thumbnail'); } $items .= '<h4>' . $link_title . '</h4>'; if ($show_thumbnail == "yes") { $items .= $rating_html; } $items .= '</div>'; $items .= get_comment_excerpt($comment_id); $items .= '</div>'; $items .= '<div class="testimonial-cite">'; $items .= get_avatar($comment_product->comment_author_email, apply_filters('woocommerce_review_gravatar_size', '60'), ''); $items .= '<div class="cite-text has-cite-image">'; $items .= '<span class="cite-name">' . $name_author . '</span>'; $items .= '</div>'; $items .= '</li>'; } } else { $items .= '<li><p>' . __('No products reviews found.', 'swift-framework-plugin') . '</p></li>'; } $items .= '</ul>'; $el_class = $this->getExtraClass($el_class); $width = spb_translateColumnWidthToSpan($width); $el_class .= ' testimonial'; $output .= "\n\t" . '<div class="spb_content_element ' . $width . $el_class . '">'; $output .= "\n\t\t" . '<div class="spb-asset-content product-reviews-wrap ' . $text_size . '">'; $output .= $title != '' ? "\n\t\t\t" . $this->spb_title($title, '') : ''; $output .= "\n\t\t\t" . $items; $output .= "\n\t\t" . '</div> ' . $this->endBlockComment('.spb_wrapper'); $output .= "\n\t" . '</div> ' . $this->endBlockComment($width); $output = $this->startRow($el_position) . $output . $this->endRow($el_position); return $output; }
private function comment_list_item($_comment) { global $comment; $comment = $_comment; $comment_status = wp_get_comment_status($comment->comment_ID); if ('unapproved' == $comment_status) { $gray_start = '<font color="gray">'; $gray_end = '</font>'; } else { $gray_start = ''; $gray_end = ''; } $checkbox = ''; if (current_user_can('edit_post', $comment->comment_post_ID)) { $checkbox = '<input type="checkbox" name="delete_comments[]" value="' . intval($comment->comment_ID) . '" />'; } echo '<dt>'; printf(_c('%1$s%2$d:%3$s|comment-list-title', 'ktai_style'), $checkbox, $comment->comment_ID, $gray_start . mb_strcut(get_comment_excerpt(), 0, self::COMMENT_EXCERPT_SIZE) . $gray_end); echo '</dt><dd>'; ?> <img localsrc="46" alt=" @ " /><font color="<?php echo ks_option('ks_date_color'); ?> "><?php echo ks_comment_datetime(); ?> </font> <img localsrc="<?php comment_type(68, 112, 112); ?> " alt="[<?php comment_type(__('Comment', 'ktai_style'), __('Trackback'), __('Pingback')); ?> ] " /><?php comment_author(); ?> <br /><?php if (strlen($author_url_display) > self::COMMENT_AUTHOR_URL_LENGTH) { $author_url_display = substr($author_url_display, 0, self::COMMENT_AUTHOR_URL_LENGTH - 1) . '...'; } if ($comment->comment_author_url && 'http://' != $comment->comment_author_url) { $author_url_display = $comment->comment_author_url; $author_url_display = str_replace('http://www.', '', $author_url_display); $author_url_display = str_replace('http://', '', $author_url_display); if (strlen($author_url_display) > self::COMMENT_AUTHOR_URL_LENGTH) { $author_url_display = substr($author_url_display, 0, self::COMMENT_AUTHOR_URL_LENGTH - 1) . '...'; } ?> <img localsrc="112" alt="" /><font color="olive"><?php echo esc_html($author_url_display); ?> </font><br /><?php } if ($comment->comment_author_email && current_user_can('edit_post', $comment->comment_post_ID)) { ?> <img localsrc="108" alt="" /><font color="olive"><?php comment_author_email(); ?> </font><br /><?php } if (!$this->post_id && ($title = $this->get_post_title($comment->comment_post_ID))) { ?> <font color="gray" size="-1"><img localsrc="97" /><?php echo $title; ?> </font><br /><?php } $app_nonce = esc_html('&_wpnonce=' . wp_create_nonce("approve-comment_{$comment->comment_ID}")); $del_nonce = esc_html('&_wpnonce=' . wp_create_nonce("delete-comment_{$comment->comment_ID}")); $approve_url = esc_url('comment.php?action=approvecomment&p=' . $comment->comment_post_ID . '&c=' . $comment->comment_ID . $app_nonce); $unapprove_url = esc_url('comment.php?action=unapprovecomment&p=' . $comment->comment_post_ID . '&c=' . $comment->comment_ID . $app_nonce); $spam_url = esc_url('comment.php?action=spamcomment&p=' . $comment->comment_post_ID . '&c=' . $comment->comment_ID . $del_nonce); $unspam_url = esc_url('comment.php?action=unspamcomment&p=' . $comment->comment_post_ID . '&c=' . $comment->comment_ID . $del_nonce); $trash_url = esc_url('comment.php?action=trashcomment&p=' . $comment->comment_post_ID . '&c=' . $comment->comment_ID . $del_nonce); $untrash_url = esc_url('comment.php?action=untrashcomment&c=' . $comment->comment_ID . $del_nonce); $delete_url = esc_url('comment.php?action=deletecomment&p=' . $comment->comment_post_ID . '&c=' . $comment->comment_ID); // do not add nonce $edit_url = esc_url('comment.php?action=editcomment&c=' . $comment->comment_ID); $reply_url = esc_url('comment-reply.php?replytocom=' . $comment->comment_ID); $action_template_color = '<a href="%s"><font color="%s">%s</font></a>'; $action_template = '<a href="%s">%s</a>'; if (current_user_can('edit_post', $comment->comment_post_ID)) { $actions = array(); if (current_user_can('moderate_comments')) { if ('unapproved' == $comment_status || 'moderated' == $comment_status) { $actions['approve'] = sprintf($action_template_color, $approve_url, 'green', __('Approve')); $actions['spam'] = sprintf($action_template_color, $spam_url, 'red', __('Spam')); } elseif ('approved' == $_GET['comment_status'] && 'approved' == $comment_status) { $actions['unapprove'] = sprintf($action_template_color, $unapprove_url, '#ff9900', __('Unapprove')); } elseif ('spam' == $comment_status) { if (function_exists('wp_trash_comment') && EMPTY_TRASH_DAYS) { $actions['unspam'] = sprintf($action_template_color, $unspam_url, 'orange', __('Restore')); $actions['trash'] = sprintf($action_template_color, $trash_url, 'red', __('Trash')); } else { $actions['approve'] = sprintf($action_template_color, $approve_url, 'green', __('Approve')); $actions['delete'] = sprintf($action_template_color, $delete_url, 'red', __('Delete')); } } } if ('trash' == $comment_status) { $actions['restore'] = sprintf($action_template_color, $untrash_url, 'green', __('Restore')); $actions['delete'] = sprintf($action_template_color, $delete_url, 'red', __('Delete')); } elseif ('spam' != $comment_status) { $actions['edit'] = '<img localsrc="104" alt="" />' . sprintf($action_template, $edit_url, __('Edit')); if ('approved' == $comment_status && (NULL == $this->post_status || 'published' == $this->post_status)) { $actions['reply'] = '<img localsrc="149" alt="" />' . sprintf($action_template, $reply_url, __('Reply', 'ktai_style')); } } if ($actions) { $actions = apply_filters('comment_row_actions', array_filter($actions), $comment); echo '[ ' . implode(' | ', $actions) . ' ]'; } } }
function widget($args, $instance) { extract($args); $show_popular = $instance['show_popular'] == 'yes' ? true : false; $show_popular_number = $instance['show_popular_number']; $show_recent = $instance['show_recent'] == 'yes' ? true : false; $show_recent_number = $instance['show_recent_number']; $show_comments = $instance['show_comments'] == 'yes' ? true : false; $show_comments_number = $instance['show_comments_number']; $show_tags = $instance['show_tags'] == 'yes' ? true : false; $show_tags_number = $instance['show_tags_number']; ?> <div class="widget-grey-bg"> <?php echo $before_widget; ?> <div class="widget-title"> <?php if ($show_popular) { ?> <span>Интересные записи</span> <?php } ?> <?php if ($show_recent) { ?> <span>Последние посты</span> <?php } ?> <?php if ($show_comments) { ?> <span>Комментарии</span> <?php } ?> <?php if ($show_tags) { ?> <span>Популярные теги</span> <?php } ?> </div> <div class="tab_container"> <?php //Tab 1 if ($show_popular) { echo '<div id="tab1" class="tab_content">'; echo '<ul class="clearfix">'; $the_query = new WP_Query("orderby=comment_count&order=DESC&showposts={$show_popular_number}"); while ($the_query->have_posts()) { $the_query->the_post(); ?> <li class="clearfix"> <?php if (function_exists('has_post_thumbnail') && has_post_thumbnail()) { ?> <div class="post-thumb"> <a href="<?php the_permalink(); ?> " title="<?php the_title(); ?> "><?php resize_img("width=55&height=55"); ?> </a> </div> <?php } ?> <div class="detail"> <h3 class="entry-title"><a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a></h3> <span class="entry-meta"><?php the_time(get_option('date_format')); ?> // <a href="<?php comments_link(); ?> "><?php comments_number(__('Без комментариев', 'theme_textdomain'), __('1 Комментарий', 'theme_textdomain'), __('% Комментариев', 'theme_textdomain')); ?> </a></span> </div> </li> <?php } ?> </ul> </div> <?php } //Tab 2 if ($show_recent) { echo '<div id="tab2" class="tab_content">'; echo '<ul class="clearfix">'; $the_query = new WP_Query("showposts={$show_recent_number}"); while ($the_query->have_posts()) { $the_query->the_post(); ?> <li class="clearfix"> <?php if (function_exists('has_post_thumbnail') && has_post_thumbnail()) { ?> <div class="post-thumb"> <a href="<?php the_permalink(); ?> " title="<?php the_title(); ?> "><?php resize_img("width=55&height=55"); ?> </a> </div> <?php } ?> <div class="detail"> <h3 class="entry-title"><a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a></h3> <span class="entry-meta"><?php the_time(get_option('date_format')); ?> // <a href="<?php comments_link(); ?> "><?php comments_number(__('No Comments', 'theme_textdomain'), __('1 Comment', 'theme_textdomain'), __('% Comments', 'theme_textdomain')); ?> </a></span> </div> </li> <?php } ?> </ul> </div> <?php } //Tab3 if ($show_comments) { echo '<div id="tab3" class="tab_content">'; $comments = get_comments(array('number' => $show_comments_number, 'status' => 'approve', 'type' => 'comment')); echo '<ul class="clearfix">'; foreach ($comments as $comment) { $comm_title = get_the_title($comment->comment_post_ID); $comm_link = get_comment_link($comment->comment_ID); ?> <li class="clearfix"> <div class="post-thumb"> <a href="<?php echo $comm_link; ?> "><?php echo get_avatar($comment, 55); ?> </a> </div> <div class="detail"> <span class="entry-meta"><a href="<?php echo $comm_link; ?> "><?php echo substr(get_comment_excerpt($comment->comment_ID), 0, 100); ?> </a></span> </div> </li> <?php } ?> </ul> </div> <?php } //Tab 4 if ($show_tags) { ?> <div id="tab4" class="tab_content clearfix"> <?php wp_tag_cloud('largest=12&smallest=12&unit=px&number=' . $show_tags_number); ?> </div> <?php } ?> </div> <?php echo $after_widget; ?> </div> <?php }
/** * Display the excerpt of the current comment. * * @since 1.2.0 * * @param int $comment_ID ID of the comment for which to print the excerpt. * Default current comment. */ function comment_excerpt($comment_ID = 0) { $comment_excerpt = get_comment_excerpt($comment_ID); /** * Filter the comment excerpt for display. * * @since 1.2.0 * * @param string $comment_excerpt The comment excerpt text. */ echo apply_filters('comment_excerpt', $comment_excerpt); }
/** * Display the excerpt of the current comment. * * @since 1.2.0 * * @param int $comment_ID ID of the comment for which to print the excerpt. * Default current comment. */ function comment_excerpt($comment_ID = 0) { $comment_excerpt = get_comment_excerpt($comment_ID); /** * Filter the comment excerpt for display. * * @since 1.2.0 * @since 4.1.0 The `$comment_ID` parameter was added. * * @param string $comment_excerpt The comment excerpt text. * @param int $comment_ID The comment ID. */ echo apply_filters('comment_excerpt', $comment_excerpt, $comment_ID); }
/** * Display the excerpt of the current comment. * * @since 1.2.0 * @uses apply_filters() Calls 'comment_excerpt' hook before displaying excerpt * * @param int $comment_ID The ID of the comment for which to print the excerpt. Optional. */ function comment_excerpt($comment_ID = 0) { echo apply_filters('comment_excerpt', get_comment_excerpt($comment_ID)); }
function commentslider($atts, $content = null) { extract(shortcode_atts(array('before' => '', 'number' => 3, 'after' => '', 'pause' => '3000', 'slider' => 'true'), $atts)); $rand = substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 5)), 0, 5); $echo = "<ul class='recent_comments_widget' id='commentslider-{$rand}'>"; global $wpdb, $comments, $comment; $comments = $wpdb->get_results("SELECT comment_author, comment_author_email, comment_author_url, comment_ID, comment_post_ID, comment_content FROM {$wpdb->comments} WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT {$number}"); if ($comments) { foreach ($comments as $comment) { $echo .= '<li class="widget_last_comments"><div class="meta">' . get_avatar($comment, 12); $echo .= get_comment_author_link(); $echo .= ' | <a href="'; $echo .= get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '" >'; $echo .= get_the_title($comment->comment_post_ID) . '</a></div>' . '<p>' . get_comment_excerpt() . '</p></li>'; } } $echo .= "</ul>"; $echo .= "<!-- SLIDER {$slider} -->"; if ($slider != "false") { $echo .= "\t<script type='text/javascript'>\r\n\t\t\t\tjQuery(document).ready(function(\$) {\r\n\t\t\t\t\$('#commentslider-{$rand}').cycle({ \r\n\t\t\t\t fx: 'fade',\r\n\t\t\t\t timeout: '{$pause}',\r\n\t\t\t\t speed: '1000',\r\n\t\t\t\t pause: 1,\r\n\t\t\t\t fit: 1\r\n\t\t\t\t\t});\r\n\t\t\t\t});\t\t\r\n\t\t\t\t</script>"; } return $echo; }
function widget($args, $instance) { extract($args); /* User-selected settings. */ $title = apply_filters('widget_title', $instance['title']); $show_count = $instance['show_count']; $show_avatar = isset($instance['show_avatar']) ? $instance['show_avatar'] : false; $avatar_size = $instance['avatar_size']; $excerpt_length = $instance['excerpt_length']; $comments = get_comments(array('number' => $show_count, 'status' => 'approve', 'type' => 'comment')); if ($comments) { /* Before widget (defined by themes). */ echo $before_widget; /* Title of widget (before and after defined by themes). */ if ($title) { echo $before_title . $title . $after_title; } echo '<ul class="recent-comments-list">'; foreach ($comments as $comment) { $p = get_post($comment->comment_post_ID); if (!empty($p->post_password)) { continue; } $comm_title = get_the_title($comment->comment_post_ID); $comm_link = get_comment_link($comment->comment_ID); ?> <li> <?php if ($show_avatar) { echo '<a href="' . $comm_link . '">' . get_avatar($comment, $size = $avatar_size) . '</a>'; } $comment_text = get_comment_excerpt($comment->comment_ID); if (0 != $excerpt_length) { $last = substr(substr($comment_text, 0, $excerpt_length), -1); if (strlen(count_chars($comment_text, 3)) > $excerpt_length) { $comment_text = substr($comment_text, 0, $excerpt_length - 1) . preg_replace('/[^(\\x00-\\x7F)]*/', '', $last); } else { $comment_text = substr($comment_text, 0, $excerpt_length - 1); } } ?> <a href="<?php echo $comm_link; ?> "><strong class="comment-author"><?php echo $comment->comment_author; ?> </strong>:</a> <?php echo $comment_text; ?> … </li> <?php } echo '</ul>'; /* After widget (defined by themes). */ echo $after_widget; } //end if $comments }
function _likebtn_get_entity_excerpt($entity_name, $entity_id) { global $likebtn_nonpost_entities; $excerpt = ''; if ($entity_name == LIKEBTN_ENTITY_COMMENT) { $excerpt = get_comment_excerpt($entity_id); } elseif (!in_array($entity_name, $likebtn_nonpost_entities)) { $get_post = get_post($entity_id); $excerpt = $get_post->post_excerpt; if (!$excerpt) { $excerpt = $get_post->post_content; } if ($excerpt) { $excerpt = strip_tags($excerpt); $excerpt = strip_shortcodes($excerpt); //$post['excerpt'] = apply_filters('get_the_excerpt', $post['excerpt']); $excerpt = _likebtn_shorten_excerpt($excerpt); } } return $excerpt; }
function comment_excerpt() { echo apply_filters('comment_excerpt', get_comment_excerpt()); }
public function widget($args, $instance) { extract($args); $instance['title'] ? NULL : ($instance['title'] = ''); $title = apply_filters('widget_title', $instance['title']); $output = $before_widget . "\n"; if ($title) { $output .= $before_title . $title . $after_title; } ob_start(); /* Set tabs-nav order & output it /* ------------------------------------ */ $titles = array('recent' => $instance['title_latestpost'], 'popular' => $instance['title_hotpost'], 'comments' => $instance['title_comment']); $tabs = array(); $count = 0; $order = array('recent' => $instance['order_recent'], 'popular' => $instance['order_popular'], 'comments' => $instance['order_comments']); asort($order); foreach ($order as $key => $value) { if ($instance[$key . '_enable']) { $tabs[] = $key; $count++; } } if ($tabs && $count > 1) { $output .= $this->_create_tabs($titles, $tabs, $count); } ?> <?php if (ot_get_option('lazy_load_img') == 'on') { $lazy = 'class="box-hide" src="' . THEME_URI . '/images/image-pending.gif" data-original'; } else { $lazy = 'src'; } ?> <div class="tin-tabs-container"> <?php if ($instance['recent_enable']) { // Recent posts enabled? ?> <?php $recent = new WP_Query(); ?> <?php $recent->query('showposts=' . $instance["recent_num"] . '&cat=' . $instance["recent_cat_id"] . '&ignore_sticky_posts=1'); ?> <ul id="tab-recent" class="tin-tab group <?php if ($instance['recent_thumbs']) { echo 'thumbs-enabled'; } else { echo 'no-pic'; } ?> "> <?php while ($recent->have_posts()) { $recent->the_post(); ?> <?php $large_image_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large'); ?> <li> <?php if ($instance['recent_thumbs']) { // Thumbnails enabled? ?> <div class="tab-item-thumbnail"> <a href="<?php the_permalink(); ?> " title="<?php the_title(); ?> "> <?php if (has_post_thumbnail()) { ?> <div class="thumb-img"> <img <?php echo $lazy; ?> ="<?php echo tin_thumb_source($large_image_url[0], 125, 78, false); ?> " alt="<?php the_title(); ?> " /> <span><?php the_article_icon(); ?> </span> </div> <?php } else { ?> <div class="thumb-img"> <img <?php echo $lazy; ?> ="<?php $img = catch_first_image(); echo tin_thumb_source($img, 125, 78, false); ?> " alt="<?php the_title(); ?> " /> <span><?php the_article_icon(); ?> </span> </div> <?php } ?> </a> </div> <?php } ?> <div class="tab-item-inner group"> <p class="tab-item-title"><a href="<?php the_permalink(); ?> " rel="bookmark" title="<?php the_title(); ?> "><?php the_title(); ?> </a></p> <?php if ($instance['tabs_date']) { ?> <span class="tab-item-date"><?php the_time('Y-m-j'); ?> </span><?php } ?> <?php if ($instance['tabs_category']) { ?> <span class="tab-item-category"><?php the_category(' / '); ?> </span><?php } ?> </div> </li> <?php } ?> </ul><!--/.tin-tab--> <?php } ?> <?php if ($instance['popular_enable']) { // Popular posts enabled? ?> <?php $popular = new WP_Query(array('post_type' => array('post'), 'showposts' => $instance['popular_num'], 'cat' => $instance['popular_cat_id'], 'ignore_sticky_posts' => true, 'orderby' => 'comment_count', 'order' => 'dsc', 'date_query' => array(array('after' => $instance['popular_time'])))); ?> <ul id="tab-popular" class="tin-tab group <?php if ($instance['popular_thumbs']) { echo 'thumbs-enabled'; } else { echo 'no-pic'; } ?> "> <?php while ($popular->have_posts()) { $popular->the_post(); ?> <?php $large_image_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large'); ?> <li> <?php if ($instance['popular_thumbs']) { // Thumbnails enabled? ?> <div class="tab-item-thumbnail"> <a href="<?php the_permalink(); ?> " title="<?php the_title(); ?> "> <?php if (has_post_thumbnail()) { ?> <div class="thumb-img"> <img <?php echo $lazy; ?> ="<?php echo tin_thumb_source($large_image_url[0], 125, 78, false); ?> " alt="<?php the_title(); ?> " /> <span><?php the_article_icon(); ?> </span> </div> <?php } else { ?> <div class="thumb-img"> <img <?php echo $lazy; ?> ="<?php $img = catch_first_image(); echo tin_thumb_source($img, 125, 78, false); ?> " alt="<?php the_title(); ?> " /> <span><?php the_article_icon(); ?> </span> </div> <?php } ?> </a> </div> <?php } ?> <div class="tab-item-inner group"> <p class="tab-item-title"><a href="<?php the_permalink(); ?> " rel="bookmark" title="<?php the_title(); ?> "><?php the_title(); ?> </a></p> <?php if ($instance['tabs_date']) { ?> <span class="tab-item-date"><?php the_time('Y-m-j'); ?> </span><?php } ?> <?php if ($instance['tabs_category']) { ?> <span class="tab-item-category"><?php the_category(' / '); ?> </span><?php } ?> </div> </li> <?php } ?> </ul><!--/.tin-tab--> <?php } ?> <?php if ($instance['comments_enable']) { // Recent comments enabled? ?> <?php $args = array('number' => $instance["comments_num"], 'status' => 'approve', 'post_status' => 'publish'); if (isset($instance['comment_order']) && $instance['comment_order'] == 'vote') { $args['orderby'] = 'meta_value_num'; $args['meta_key'] = 'tin_comment_voteyes'; } $comments = get_comments($args); ?> <ul id="tab-comments" class="tin-tab group <?php if ($instance['comments_avatars']) { echo 'avatars-enabled'; } else { echo 'no-avatar'; } ?> "> <?php foreach ($comments as $comment) { ?> <li> <?php if ($instance['comments_avatars']) { // Avatars enabled? ?> <div class="tab-item-avatar"> <?php echo tin_get_avatar($comment->user_id, '96', tin_get_avatar_type($comment->user_id)); ?> </div> <?php } ?> <div class="tab-item-inner group"> <?php $comment_excerpt = preg_replace("'\\[private](.*?)\\[\\/private]'", '***该评论仅父级评论者及管理员可见***', get_comment_excerpt($comment->comment_ID)); $str = explode(' ', $comment_excerpt); $comment_excerpt = implode(' ', array_slice($str, 0, 11)); if (count($str) > 11 && substr($comment_excerpt, -1) != '.') { $comment_excerpt .= '...'; } ?> <div class="tab-item-comment"><span class="arrow-poptop"></span><a href="<?php echo esc_url(get_permalink($comment->comment_post_ID)); ?> "><i><?php echo $comment->comment_author; ?> </i><?php _e('说: ', 'xiapistudio'); echo $comment_excerpt; ?> </a><div class="tab-cmt-votes"><span class="cmt-vote"> <?php $c_name = 'tin_comment_vote_' . $comment->comment_ID; $cookie = isset($_COOKIE[$c_name]) ? $_COOKIE[$c_name] : ''; ?> <i class="fa fa-thumbs-o-up <?php if ($cookie == 1) { echo 'voted'; } ?> " title="<?php _e('顶', 'xiapistudio'); ?> " data="<?php echo $comment->comment_ID; ?> " data-type="1" data-num="<?php echo (int) get_comment_meta($comment->comment_ID, 'tin_comment_voteyes', true); ?> "><?php echo ' [' . (int) get_comment_meta($comment->comment_ID, 'tin_comment_voteyes', true) . ']'; ?> </i> <i class="fa fa-thumbs-o-down <?php if ($cookie == 2) { echo 'voted'; } ?> " title="<?php _e('踩', 'xiapistudio'); ?> " data="<?php echo $comment->comment_ID; ?> " data-type="2" data-num="<?php echo (int) get_comment_meta($comment->comment_ID, 'tin_comment_voteno', true); ?> "><?php echo ' [' . (int) get_comment_meta($comment->comment_ID, 'tin_comment_voteno', true) . ']'; ?> </i> </span></div></div> </div> </li> <?php } ?> </ul><!--/.tin-tab--> <?php } ?> </div> <?php $output .= ob_get_clean(); $output .= $after_widget . "\n"; echo $output; }
public function widget($args, $instance) { extract($args); $instance['title'] ? NULL : ($instance['title'] = ''); $title = apply_filters('widget_title', $instance['title']); $output = $before_widget . "\n"; if ($title) { $output .= $before_title . $title . $after_title; } ob_start(); /* Set tabs-nav order & output it /* ------------------------------------ */ $tabs = array(); $count = 0; $order = array('recent' => $instance['order_recent'], 'popular' => $instance['order_popular'], 'comments' => $instance['order_comments'], 'tags' => $instance['order_tags']); asort($order); foreach ($order as $key => $value) { if ($instance[$key . '_enable']) { $tabs[] = $key; $count++; } } if ($tabs && $count > 1) { $output .= $this->_create_tabs($tabs, $count); } ?> <div class="alx-tabs-container"> <?php if ($instance['recent_enable']) { // Recent posts enabled? ?> <?php $recent = new WP_Query(); ?> <?php $recent->query('showposts=' . $instance["recent_num"] . '&cat=' . $instance["recent_cat_id"] . '&ignore_sticky_posts=1'); ?> <ul id="tab-recent" class="alx-tab group <?php if ($instance['recent_thumbs']) { echo 'thumbs-enabled'; } ?> "> <?php while ($recent->have_posts()) { $recent->the_post(); ?> <li> <?php if ($instance['recent_thumbs']) { // Thumbnails enabled? ?> <div class="tab-item-thumbnail"> <a href="<?php the_permalink(); ?> " title="<?php the_title(); ?> "> <?php if (has_post_thumbnail()) { ?> <?php the_post_thumbnail('thumb-small'); ?> <?php } else { ?> <img src="<?php echo get_template_directory_uri(); ?> /img/thumb-small.png" alt="<?php the_title(); ?> " /> <?php } ?> <?php if (has_post_format('video') && !is_sticky()) { echo '<span class="thumb-icon small"><i class="fa fa-play"></i></span>'; } ?> <?php if (has_post_format('audio') && !is_sticky()) { echo '<span class="thumb-icon small"><i class="fa fa-volume-up"></i></span>'; } ?> <?php if (is_sticky()) { echo '<span class="thumb-icon small"><i class="fa fa-star"></i></span>'; } ?> </a> </div> <?php } ?> <div class="tab-item-inner group"> <?php if ($instance['tabs_category']) { ?> <p class="tab-item-category"><?php the_category(' / '); ?> </p><?php } ?> <p class="tab-item-title"><a href="<?php the_permalink(); ?> " rel="bookmark" title="<?php the_title(); ?> "><?php the_title(); ?> </a></p> <?php if ($instance['tabs_date']) { ?> <p class="tab-item-date"><?php the_time('j M, Y'); ?> </p><?php } ?> </div> </li> <?php } ?> <?php wp_reset_postdata(); ?> </ul><!--/.alx-tab--> <?php } ?> <?php if ($instance['popular_enable']) { // Popular posts enabled? ?> <?php $popular = new WP_Query(array('post_type' => array('post'), 'showposts' => $instance['popular_num'], 'cat' => $instance['popular_cat_id'], 'ignore_sticky_posts' => true, 'orderby' => 'comment_count', 'order' => 'dsc', 'date_query' => array(array('after' => $instance['popular_time'])))); ?> <ul id="tab-popular" class="alx-tab group <?php if ($instance['popular_thumbs']) { echo 'thumbs-enabled'; } ?> "> <?php while ($popular->have_posts()) { $popular->the_post(); ?> <li> <?php if ($instance['popular_thumbs']) { // Thumbnails enabled? ?> <div class="tab-item-thumbnail"> <a href="<?php the_permalink(); ?> " title="<?php the_title(); ?> "> <?php if (has_post_thumbnail()) { ?> <?php the_post_thumbnail('thumb-small'); ?> <?php } else { ?> <img src="<?php echo get_template_directory_uri(); ?> /img/thumb-small.png" alt="<?php the_title(); ?> " /> <?php } ?> <?php if (has_post_format('video') && !is_sticky()) { echo '<span class="thumb-icon small"><i class="fa fa-play"></i></span>'; } ?> <?php if (has_post_format('audio') && !is_sticky()) { echo '<span class="thumb-icon small"><i class="fa fa-volume-up"></i></span>'; } ?> <?php if (is_sticky()) { echo '<span class="thumb-icon small"><i class="fa fa-star"></i></span>'; } ?> </a> </div> <?php } ?> <div class="tab-item-inner group"> <?php if ($instance['tabs_category']) { ?> <p class="tab-item-category"><?php the_category(' / '); ?> </p><?php } ?> <p class="tab-item-title"><a href="<?php the_permalink(); ?> " rel="bookmark" title="<?php the_title(); ?> "><?php the_title(); ?> </a></p> <?php if ($instance['tabs_date']) { ?> <p class="tab-item-date"><?php the_time('j M, Y'); ?> </p><?php } ?> </div> </li> <?php } ?> <?php wp_reset_postdata(); ?> </ul><!--/.alx-tab--> <?php } ?> <?php if ($instance['comments_enable']) { // Recent comments enabled? ?> <?php $comments = get_comments(array('number' => $instance["comments_num"], 'status' => 'approve', 'post_status' => 'publish')); ?> <ul id="tab-comments" class="alx-tab group <?php if ($instance['comments_avatars']) { echo 'avatars-enabled'; } ?> "> <?php foreach ($comments as $comment) { ?> <li> <?php if ($instance['comments_avatars']) { // Avatars enabled? ?> <div class="tab-item-avatar"> <a href="<?php echo esc_url(get_comment_link($comment->comment_ID)); ?> "> <?php echo get_avatar($comment->comment_author_email, $size = '96'); ?> </a> </div> <?php } ?> <div class="tab-item-inner group"> <?php $str = explode(' ', get_comment_excerpt($comment->comment_ID)); $comment_excerpt = implode(' ', array_slice($str, 0, 11)); if (count($str) > 11 && substr($comment_excerpt, -1) != '.') { $comment_excerpt .= '...'; } ?> <div class="tab-item-name"><?php echo esc_attr($comment->comment_author); ?> <?php _e('says:', 'hueman'); ?> </div> <div class="tab-item-comment"><a href="<?php echo esc_url(get_comment_link($comment->comment_ID)); ?> "><?php echo esc_attr($comment_excerpt); ?> </a></div> </div> </li> <?php } ?> </ul><!--/.alx-tab--> <?php } ?> <?php if ($instance['tags_enable']) { // Tags enabled? ?> <ul id="tab-tags" class="alx-tab group"> <li> <?php wp_tag_cloud(); ?> </li> </ul><!--/.alx-tab--> <?php } ?> </div> <?php $output .= ob_get_clean(); $output .= $after_widget . "\n"; echo $output; }
function widget($args, $instance = array()) { global $wpdb; global $likebtn_nonpost_entities; global $likebtn_bbp_post_types; $has_posts = false; $post_types_count = 0; if (is_array($args)) { extract($args); } $instance = LikeBtnLikeButtonMostLikedWidget::prepareInstance($instance); if (is_array($instance)) { extract($instance); } /*$title = ''; if (isset($instance['title'])) { $title = $instance['title']; } $show_thumbnail = ''; if (isset($instance['show_thumbnail'])) { $show_thumbnail = $instance['show_thumbnail']; } $show_excerpt = ''; if (isset($instance['show_excerpt'])) { $show_excerpt = $instance['show_excerpt']; } $show_date = ''; if (isset($instance['show_date'])) { $show_date = $instance['show_date']; } $show_likes = ''; if (isset($instance['show_likes'])) { $show_likes = $instance['show_likes']; } $show_dislikes = ''; if (isset($instance['show_dislikes'])) { $show_dislikes = $instance['show_dislikes']; } // validate parameters if ($show_thumbnail == 'true') { $show_thumbnail = '1'; } if ($show_date == 'true') { $show_date = '1'; } if ($show_likes == 'true') { $show_likes = '1'; } if ($show_dislikes == 'true') { $show_dislikes = '1'; }*/ if (empty($instance['entity_name'])) { $instance['entity_name'] = array(LIKEBTN_ENTITY_POST); } foreach ($instance['entity_name'] as $entity_index => $entity_name) { $instance['entity_name'][$entity_index] = str_replace("'", '', trim($entity_name)); if (!in_array($entity_name, $likebtn_nonpost_entities)) { $has_posts = true; } } $query_limit = ''; if (isset($instance['number']) && (int) $instance['number'] > 0) { $query_limit = "LIMIT " . (int) $instance['number']; } // getting the most liked content $query = ''; // Posts if ($has_posts) { $query_post_types = "'" . implode("','", $instance['entity_name']) . "'"; $query .= "\n SELECT\n p.ID as 'post_id',\n p.post_title,\n p.post_date,\n CONVERT(pm_likes.meta_value, UNSIGNED INTEGER) as 'likes',\n CONVERT(pm_dislikes.meta_value, UNSIGNED INTEGER) as 'dislikes',\n CONVERT(pm_likes_minus_dislikes.meta_value, UNSIGNED INTEGER) as 'likes_minus_dislikes',\n p.post_type,\n p.post_mime_type,\n '' as url\n FROM {$wpdb->prefix}postmeta pm_likes\n LEFT JOIN {$wpdb->prefix}posts p\n ON (p.ID = pm_likes.post_id)\n LEFT JOIN {$wpdb->prefix}postmeta pm_dislikes\n ON (pm_dislikes.post_id = pm_likes.post_id AND pm_dislikes.meta_key = '" . LIKEBTN_META_KEY_DISLIKES . "')\n LEFT JOIN {$wpdb->prefix}postmeta pm_likes_minus_dislikes\n ON (pm_likes_minus_dislikes.post_id = pm_likes.post_id AND pm_likes_minus_dislikes.meta_key = '" . LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES . "')\n WHERE\n pm_likes.meta_key = '" . LIKEBTN_META_KEY_LIKES . "'\n AND p.post_status = 'publish'\n AND p.post_type in ({$query_post_types}) "; if (!empty($instance['time_range']) && $instance['time_range'] != 'all') { $query .= " AND post_date >= '" . $this->timeRangeToDateTime($instance['time_range']) . "'"; } $post_types_count++; } // Comments if (in_array(LIKEBTN_ENTITY_COMMENT, $instance['entity_name'])) { if ($post_types_count > 0) { $query .= " UNION "; } $query .= "\n SELECT\n p.comment_ID as 'post_id',\n p.comment_content as post_title,\n p.comment_date as 'post_date',\n CONVERT(pm_likes.meta_value, UNSIGNED INTEGER) as 'likes',\n CONVERT(pm_dislikes.meta_value, UNSIGNED INTEGER) as 'dislikes',\n CONVERT(pm_likes_minus_dislikes.meta_value, UNSIGNED INTEGER) as 'likes_minus_dislikes',\n '" . LIKEBTN_ENTITY_COMMENT . "' as post_type,\n '' as post_mime_type,\n '' as url\n FROM {$wpdb->prefix}commentmeta pm_likes\n LEFT JOIN {$wpdb->prefix}comments p\n ON (p.comment_ID = pm_likes.comment_id)\n LEFT JOIN {$wpdb->prefix}commentmeta pm_dislikes\n ON (pm_dislikes.comment_id = pm_likes.comment_id AND pm_dislikes.meta_key = '" . LIKEBTN_META_KEY_DISLIKES . "')\n LEFT JOIN {$wpdb->prefix}commentmeta pm_likes_minus_dislikes\n ON (pm_likes_minus_dislikes.comment_id = pm_likes.comment_id AND pm_likes_minus_dislikes.meta_key = '" . LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES . "')\n WHERE\n pm_likes.meta_key = '" . LIKEBTN_META_KEY_LIKES . "' \n AND p.comment_approved = 1 "; if (!empty($instance['time_range']) && $instance['time_range'] != 'all') { $query .= " AND comment_date >= '" . $this->timeRangeToDateTime($instance['time_range']) . "'"; } $post_types_count++; } // Custom items if (in_array(LIKEBTN_ENTITY_CUSTOM_ITEM, $instance['entity_name'])) { if ($post_types_count > 0) { $query .= " UNION "; } $query_post_types = "'" . implode("','", $instance['entity_name']) . "'"; $query .= "\n SELECT\n p.ID as 'post_id',\n p.identifier as 'post_title',\n '' as 'post_date',\n p.likes,\n p.dislikes,\n p.likes_minus_dislikes,\n '" . LIKEBTN_ENTITY_CUSTOM_ITEM . "' as 'post_type',\n '' as 'post_mime_type',\n url\n FROM {$wpdb->prefix}" . LIKEBTN_TABLE_ITEM . " p\n WHERE\n 1 = 1 "; $post_types_count++; } // BuddyPress Member if (in_array(LIKEBTN_ENTITY_BP_MEMBER, $instance['entity_name'])) { if ($post_types_count > 0) { $query .= " UNION "; } $query .= "\n SELECT\n p.ID as 'post_id',\n p.display_name as post_title,\n p.user_registered as 'post_date',\n CONVERT(pm_likes.meta_value, UNSIGNED INTEGER) as 'likes',\n CONVERT(pm_dislikes.meta_value, UNSIGNED INTEGER) as 'dislikes',\n CONVERT(pm_likes_minus_dislikes.meta_value, UNSIGNED INTEGER) as 'likes_minus_dislikes',\n '" . LIKEBTN_ENTITY_BP_MEMBER . "' as post_type,\n '' as post_mime_type,\n '' as url\n FROM {$wpdb->prefix}bp_xprofile_meta pm_likes\n LEFT JOIN {$wpdb->prefix}users p\n ON (p.ID = pm_likes.object_id AND pm_likes.object_type = '" . LIKEBTN_BP_XPROFILE_OBJECT_TYPE . "')\n LEFT JOIN {$wpdb->prefix}bp_xprofile_meta pm_dislikes\n ON (pm_dislikes.object_id = pm_likes.object_id AND pm_dislikes.object_type = '" . LIKEBTN_BP_XPROFILE_OBJECT_TYPE . "' AND pm_dislikes.meta_key = '" . LIKEBTN_META_KEY_DISLIKES . "')\n LEFT JOIN {$wpdb->prefix}bp_xprofile_meta pm_likes_minus_dislikes\n ON (pm_likes_minus_dislikes.object_id = pm_likes.object_id AND pm_likes_minus_dislikes.object_type = '" . LIKEBTN_BP_XPROFILE_OBJECT_TYPE . "' AND pm_likes_minus_dislikes.meta_key = '" . LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES . "')\n WHERE\n pm_likes.meta_key = '" . LIKEBTN_META_KEY_LIKES . "' \n AND p.user_status = 0 "; if (!empty($instance['time_range']) && $instance['time_range'] != 'all') { $query .= " AND p.user_registered >= '" . $this->timeRangeToDateTime($instance['time_range']) . "'"; } $post_types_count++; } // BuddyPress Activities if (in_array(LIKEBTN_ENTITY_BP_ACTIVITY_POST, $instance['entity_name']) || in_array(LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE, $instance['entity_name']) || in_array(LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT, $instance['entity_name']) || in_array(LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC, $instance['entity_name'])) { if ($post_types_count > 0) { $query .= " UNION "; } $query .= "\n SELECT \n p.id as 'post_id',\n CONCAT( IF(p.action != '', p.action, IF(p.content !='', p.content, IF(p.primary_link != '', p.primary_link, p.type))), IF(p.content != '' && p.type != 'bbp_topic_create' && p.type != 'new_blog_post', CONCAT(': ', p.content), '') ) as 'post_title',\n p.date_recorded as 'post_date',\n CONVERT(pm_likes.meta_value, UNSIGNED INTEGER) as 'likes',\n CONVERT(pm_dislikes.meta_value, UNSIGNED INTEGER) as 'dislikes',\n CONVERT(pm_likes_minus_dislikes.meta_value, UNSIGNED INTEGER) as 'likes_minus_dislikes',\n IF (p.type = 'bbp_topic_create',\n '" . LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC . "',\n IF (p.type = 'new_blog_post',\n '" . LIKEBTN_ENTITY_BP_ACTIVITY_POST . "',\n '" . LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE . "'\n )\n ) as post_type,\n '' as post_mime_type,\n '' as url\n FROM {$wpdb->prefix}bp_activity_meta pm_likes\n LEFT JOIN {$wpdb->prefix}bp_activity p\n ON (p.id = pm_likes.activity_id)\n LEFT JOIN {$wpdb->prefix}bp_activity_meta pm_dislikes\n ON (pm_dislikes.activity_id = pm_likes.activity_id AND pm_dislikes.meta_key = '" . LIKEBTN_META_KEY_DISLIKES . "')\n LEFT JOIN {$wpdb->prefix}bp_activity_meta pm_likes_minus_dislikes\n ON (pm_likes_minus_dislikes.activity_id = pm_likes.activity_id AND pm_likes_minus_dislikes.meta_key = '" . LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES . "')\n WHERE\n pm_likes.meta_key = '" . LIKEBTN_META_KEY_LIKES . "' \n AND p.hide_sitewide = 0\n AND p.is_spam = 0 "; if (!empty($instance['time_range']) && $instance['time_range'] != 'all') { $query .= " AND p.user_registered >= '" . $this->timeRangeToDateTime($instance['time_range']) . "'"; } $post_types_count++; } // bbPress Post if (in_array(LIKEBTN_ENTITY_BBP_POST, $instance['entity_name'])) { if ($post_types_count > 0) { $query .= " UNION "; } $query .= "\n SELECT\n p.ID as 'post_id',\n p.post_title,\n p.post_date,\n CONVERT(pm_likes.meta_value, UNSIGNED INTEGER) as 'likes',\n CONVERT(pm_dislikes.meta_value, UNSIGNED INTEGER) as 'dislikes',\n CONVERT(pm_likes_minus_dislikes.meta_value, UNSIGNED INTEGER) as 'likes_minus_dislikes',\n p.post_type,\n p.post_mime_type,\n '' as url\n FROM {$wpdb->prefix}postmeta pm_likes\n LEFT JOIN {$wpdb->prefix}posts p\n ON (p.ID = pm_likes.post_id)\n LEFT JOIN {$wpdb->prefix}postmeta pm_dislikes\n ON (pm_dislikes.post_id = pm_likes.post_id AND pm_dislikes.meta_key = '" . LIKEBTN_META_KEY_DISLIKES . "')\n LEFT JOIN {$wpdb->prefix}postmeta pm_likes_minus_dislikes\n ON (pm_likes_minus_dislikes.post_id = pm_likes.post_id AND pm_likes_minus_dislikes.meta_key = '" . LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES . "')\n WHERE\n pm_likes.meta_key = '" . LIKEBTN_META_KEY_LIKES . "'\n AND p.post_type in ('" . implode("', '", $likebtn_bbp_post_types) . "') \n AND p.post_status = 'publish' "; if (!empty($instance['time_range']) && $instance['time_range'] != 'all') { $query .= " AND post_date >= '" . $this->timeRangeToDateTime($instance['time_range']) . "'"; } $post_types_count++; } // bbPress User if (in_array(LIKEBTN_ENTITY_BBP_USER, $instance['entity_name'])) { if ($post_types_count > 0) { $query .= " UNION "; } $query .= "\n SELECT\n p.ID as 'post_id',\n p.display_name as post_title,\n p.user_registered as 'post_date',\n CONVERT(pm_likes.meta_value, UNSIGNED INTEGER) as 'likes',\n CONVERT(pm_dislikes.meta_value, UNSIGNED INTEGER) as 'dislikes',\n CONVERT(pm_likes_minus_dislikes.meta_value, UNSIGNED INTEGER) as 'likes_minus_dislikes',\n '" . LIKEBTN_ENTITY_BBP_USER . "' as post_type,\n '' as post_mime_type,\n '' as url\n FROM {$wpdb->prefix}usermeta pm_likes\n LEFT JOIN {$wpdb->prefix}users p\n ON (p.ID = pm_likes.user_id)\n LEFT JOIN {$wpdb->prefix}usermeta pm_dislikes\n ON (pm_dislikes.user_id = pm_likes.user_id AND pm_dislikes.meta_key = '" . LIKEBTN_META_KEY_DISLIKES . "')\n LEFT JOIN {$wpdb->prefix}usermeta pm_likes_minus_dislikes\n ON (pm_likes_minus_dislikes.user_id = pm_likes.user_id AND pm_likes_minus_dislikes.meta_key = '" . LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES . "')\n WHERE\n pm_likes.meta_key = '" . LIKEBTN_META_KEY_LIKES . "' \n AND p.user_status = 0 "; if (!empty($instance['time_range']) && $instance['time_range'] != 'all') { $query .= " AND p.user_registered >= '" . $this->timeRangeToDateTime($instance['time_range']) . "'"; } $post_types_count++; } if ($post_types_count > 1) { $query = "SELECT * FROM (" . $query . ") main_query"; } $query .= "\n ORDER BY "; switch ($instance['order']) { default: case 'likes': $query .= "likes"; break; case 'dislikes': $query .= "dislikes"; break; case 'likes_minus_dislikes': $query .= "likes_minus_dislikes"; break; } $query .= " DESC"; $query .= " {$query_limit}"; // echo "<pre>"; // print_r($query); // exit(); $posts = $wpdb->get_results($query); $post_loop = array(); if (count($posts) > 0) { foreach ($posts as $i => $db_post) { $post = array('id' => $db_post->post_id, 'type' => $db_post->post_type, 'post_mime_type' => $db_post->post_mime_type, 'title' => '', 'link' => '', 'likes' => '', 'dislikes' => '', 'date' => '', 'excerpt' => ''); // Title $post['title'] = _likebtn_prepare_title($db_post->post_type, $db_post->post_title); // Link $post['link'] = _likebtn_get_entity_url($db_post->post_type, $db_post->post_id, $db_post->url); $post['likes'] = $db_post->likes; $post['dislikes'] = $db_post->dislikes; if ($show_date) { $post['date'] = strtotime($db_post->post_date); } if ($show_excerpt) { if ($db_post->post_type == 'comment') { $post['excerpt'] = get_comment_excerpt($db_post->post_id); } elseif (!in_array($db_post->post_type, $likebtn_nonpost_entities)) { $get_post = get_post($db_post->post_id); $post['excerpt'] = $get_post->post_excerpt; if (!$post['excerpt']) { $post['excerpt'] = $get_post->post_content; } if ($post['excerpt']) { $post['excerpt'] = strip_tags($post['excerpt']); //$post['excerpt'] = apply_filters('get_the_excerpt', $post['excerpt']); $post['excerpt'] = _likebtn_shorten_excerpt($post['excerpt']); } } } // For bbPress replies if (!$post['title']) { $post['title'] = _likebtn_shorten_title($post['excerpt'], LIKEBTN_WIDGET_TITLE_LENGTH); } $post_loop[$i] = $post; } } // Get and include the template we're going to use ob_start(); include $this->getTemplateHierarchy(self::TEMPLATE); $result = ob_get_contents(); ob_get_clean(); return $result; }