Example #1
0
 /**
  * @ticket 30412
  */
 public function test_get_approved_comments_with_post_id_0_should_return_empty_array()
 {
     $p = $this->factory->post->create();
     $ca1 = $this->factory->comment->create(array('comment_post_ID' => $p, 'comment_approved' => '1'));
     $found = get_approved_comments(0);
     $this->assertSame(array(), $found);
 }
/**
 * 
 */
function digressit_add_comment_change_notice()
{
    $comments = get_approved_comments($_GET['post']);
    if (count($comments)) {
        add_action('admin_notices', 'digressit_change_content_warning');
    }
}
Example #3
0
function filterCommentsNumber($count)
{
    global $id;
    if (empty($id)) {
        return $count;
    }
    $comments = get_approved_comments((int) $id);
    $comments = array_filter($comments, "stripTrackback");
    return sizeof($comments);
}
Example #4
0
/**
 * Updates comment count to only include comments
 *
 * @since 1.0
 * @global int $id The current post id
 *
 * @param int $count Current number of comments/pings of current post
 *
 * @return int The number of comments only
 */
function k2_comment_count($count)
{
    global $id;
    if ($count == 0) {
        return $count;
    }
    $comments = get_approved_comments($id);
    $comments = array_filter($comments, 'k2_strip_trackback');
    return count($comments);
}
 /**
  * Don't count reactions when determining
  * the number of comments on a post.
  */
 public function comment_count($count)
 {
     global $id;
     $comment_count = 0;
     $comments = get_approved_comments($id);
     foreach ($comments as $comment) {
         if ('emoji-reaction' !== $comment->comment_type) {
             $comment_count++;
         }
     }
     return $comment_count;
 }
function wiziapp_getCommentsCount($post_id)
{
    $comments = get_approved_comments($post_id);
    /**
     * @todo check for failures
     */
    $status = TRUE;
    $message = '';
    $header = array('action' => 'commentsCount', 'status' => $status, 'code' => $status ? 200 : 4004, 'message' => $message);
    echo json_encode(array('header' => $header, 'count' => count($comments)));
    exit;
}
Example #7
0
/**
 * Comments count without pingback/trackback.
 *
 * @since 0.0.1
 *
 * @param int $count The filter need this.
 * @return int The comments number.
 */
function vp_filter_comments_count($count)
{
    global $id;
    $comments = get_approved_comments($id);
    $comment_count = 0;
    foreach ($comments as $comment) {
        if ($comment->comment_type == "") {
            $comment_count++;
        }
    }
    return $comment_count;
}
 /**
  * Get all reviews from a product.
  *
  * @param WP_REST_Request $request
  * @return array
  */
 public function get_items($request)
 {
     $product = get_post((int) $request['product_id']);
     if (empty($product->post_type) || 'product' !== $product->post_type) {
         return new WP_Error('woocommerce_rest_product_invalid_id', __('Invalid product id.', 'woocommerce'), array('status' => 404));
     }
     $reviews = get_approved_comments($product->ID);
     $data = array();
     foreach ($reviews as $review_data) {
         $review = $this->prepare_item_for_response($review_data, $request);
         $review = $this->prepare_response_for_collection($review);
         $data[] = $review;
     }
     return rest_ensure_response($data);
 }
Example #9
0
 /**
  * Builds an email without specific recipient info that can be used as a template for all recipients.
  *
  * The set_recipient method can be called to fill in recipient-specific fields.
  *
  * @since 2.0.0
  *
  * @param Prompt_Post_Rendering_Context $context      Rendering context for the target post
  * @param array                         $args         {
  * @type bool                           $excerpt_only Override the excerpt only checkbox in the delivery metabox.
  *                                                    }
  */
 public function __construct(Prompt_Post_Rendering_Context $context, $args = array())
 {
     $this->context = $context;
     $context->setup();
     $prompt_author = $context->get_author();
     $prompt_post = $context->get_post();
     $is_api_delivery = Prompt_Enum_Email_Transports::API == Prompt_Core::$options->get('email_transport');
     $will_strip_content = (!$is_api_delivery and $context->has_fancy_content());
     $subject = html_entity_decode($prompt_post->get_wp_post()->post_title, ENT_QUOTES);
     list($footnote_html, $footnote_text) = $this->footnote_content();
     if ('draft' == $prompt_post->get_wp_post()->post_status) {
         /* translators: %s is a post title */
         $subject = sprintf(__('PREVIEW of %s', 'Postmatic'), $subject);
         $footnote_html = $footnote_text = '';
     }
     $excerpt_only = Prompt_Admin_Delivery_Metabox::excerpt_only($prompt_post->id());
     if (isset($args['excerpt_only'])) {
         $excerpt_only = $args['excerpt_only'];
     }
     $this->comments = get_approved_comments($prompt_post->id());
     $template_data = array('prompt_author' => $prompt_author, 'prompt_post' => $prompt_post, 'featured_image_src' => $context->get_the_featured_image_src(), 'excerpt_only' => $excerpt_only, 'the_text_content' => $context->get_the_text_content(), 'subject' => $subject, 'alternate_versions_menu' => $context->alternate_versions_menu(), 'is_api_delivery' => $is_api_delivery, 'will_strip_content' => $will_strip_content, 'comments' => $this->comments);
     /**
      * Filter new post email template data.
      *
      * @param array      $template_data      {
      * @type Prompt_User $prompt_author
      * @type Prompt_Post $prompt_post
      * @type array       $featured_image_src url, width, height
      * @type bool        $excerpt_only       whether to include only the post excerpt
      * @type string      $the_text_content
      * @type string      $subject
      * @type bool        $is_api_delivery
      * @type bool        $will_strip_content
      *                                       }
      */
     $template_data = apply_filters('prompt/post_email/template_data', $template_data);
     $html_template = new Prompt_Template("new-post-email.php");
     $text_template = new Prompt_Text_Template("new-post-email-text.php");
     $batch_message_template = array('subject' => $subject, 'from_name' => '{{{from_name}}}', 'text_content' => $text_template->render($template_data), 'html_content' => $html_template->render($template_data), 'message_type' => Prompt_Enum_Message_Types::POST, 'reply_to' => '{{{reply_to}}}', 'footnote_html' => $footnote_html, 'footnote_text' => $footnote_text);
     $this->replyable = (comments_open($prompt_post->id()) and !$excerpt_only);
     if (!$this->replyable) {
         $batch_message_template['from_address'] = $prompt_author->get_wp_user()->user_email;
     }
     $default_values = array('from_name' => $this->to_utf8(get_option('blogname')));
     $context->reset();
     parent::__construct($batch_message_template, array(), $default_values);
 }
Example #10
0
function dsq_can_replace()
{
    global $id, $post;
    $replace = get_option('disqus_replace');
    if ('draft' == $post->post_status) {
        return false;
    }
    if (!get_option('disqus_forum_url')) {
        return false;
    } else {
        if ('all' == $replace) {
            return true;
        }
    }
    if (!isset($post->comment_count)) {
        $num_comments = 0;
    } else {
        if ('empty' == $replace) {
            // Only get count of comments, not including pings.
            // If there are comments, make sure there are comments (that are not track/pingbacks)
            if ($post->comment_count > 0) {
                // Yuck, this causes a DB query for each post.  This can be
                // replaced with a lighter query, but this is still not optimal.
                $comments = get_approved_comments($post->ID);
                foreach ($comments as $comment) {
                    if ($comment->comment_type != 'trackback' && $comment->comment_type != 'pingback') {
                        $num_comments++;
                    }
                }
            } else {
                $num_comments = 0;
            }
        } else {
            $num_comments = $post->comment_count;
        }
    }
    return 'empty' == $replace && 0 == $num_comments || 'closed' == $replace && 'closed' == $post->comment_status;
}
Example #11
0
 function hs_count_only_comments($post_id)
 {
     $count = 0;
     $comment_array = get_approved_comments($post_id);
     foreach ($comment_array as $comment) {
         if ($comment->comment_type == '') {
             $count++;
         }
     }
     return $count;
 }
Example #12
0
/**
* TODO: Add paging support here
* 
*/
function wiziapp_buildPostCommentSubCommentsPage($post_id, $p_comment_id)
{
    //    $numberOfPosts = appcom_getAppCommentsListLimit();
    $screen_conf = $GLOBALS['WiziappScreens']->getScreenLayout('comments', 'sub_list');
    $page = array();
    $comments = get_approved_comments($post_id);
    // First add the parent comment to the list
    $parentCommentSection = array('section' => array('title' => '', 'id' => 'parent_comment', 'items' => array()));
    $subCommentsSection = array('section' => array('title' => '', 'id' => 'subComments', 'items' => array()));
    $comment = get_comment($p_comment_id);
    wiziapp_appendComponentByLayout($parentCommentSection['section']['items'], $screen_conf['header'], $comment);
    foreach ($comments as $comment) {
        // Only add top level comments unless told otherwise
        if ($comment->comment_parent == $p_comment_id) {
            wiziapp_appendComponentByLayout($subCommentsSection['section']['items'], $screen_conf['items'], $comment);
        }
    }
    //$post = get_post($post_id);
    //$title = str_replace('&', '&', $post->post_title);
    $title = __("Comments", 'title');
    $screen = wiziapp_prepareSectionScreen(array($parentCommentSection, $subCommentsSection), $title, "List");
    echo json_encode($screen);
}
 function extract_xml($siteId, $offset = 0)
 {
     $maxqueries = 50;
     $maxlength = 500000;
     $index = $offset;
     $next_chunk = false;
     $total_queries = 0;
     do {
         $total_queries++;
         if ($total_queries > $maxqueries) {
             $next_chunk = true;
             break;
         }
         $args = array('post_type' => 'any', 'numberposts' => 20, 'offset' => $index);
         $myposts = new WP_Query($args);
         if (!isset($articles)) {
             $articles = '';
         }
         $inner_idx = 0;
         if ($myposts->have_posts()) {
             while ($myposts->have_posts()) {
                 $myposts->the_post();
                 if ($parent_id = wp_is_post_revision(get_the_ID())) {
                     $post_id = $parent_id;
                 } else {
                     $post_id = get_the_ID();
                 }
                 $newArticle = '<article id="' . $post_id . '"><title>' . $this->comment_data_filter(get_the_title()) . '</title><source>' . get_permalink(get_the_ID()) . '</source>';
                 if (get_post_time('c', true) != null && !strstr(get_post_time('c', true), '0000-00-00')) {
                     $newArticle .= '<created>' . preg_replace('/\\s/', 'T', get_post_time('c', true)) . 'Z</created>';
                 }
                 $comment_array = get_approved_comments(get_the_ID());
                 $comment_array = array_filter($comment_array, array('LFAPPS_Comments_Import_Impl', 'skip_trackback_filter'));
                 foreach ($comment_array as $comment) {
                     $comment_content = $this->comment_data_filter($comment->comment_content);
                     if ($comment_content == "") {
                         continue;
                         #don't sync blank
                     }
                     $commentParent = $comment->comment_parent ? " parent-id=\"{$comment->comment_parent}\"" : '';
                     $commentXML = "<comment id=\"{$comment->comment_ID}\"{$commentParent}>";
                     $commentXML .= '<author format="html">' . $this->comment_data_filter($comment->comment_author) . '</author>';
                     $commentXML .= '<author-email format="html">' . $this->comment_data_filter($comment->comment_author_email) . '</author-email>';
                     $commentXML .= '<author-url format="html">' . $this->comment_data_filter($comment->comment_author_url) . '</author-url>';
                     $commentXML .= '<body format="wphtml">' . $comment_content . '</body>';
                     $use_date = $comment->comment_date_gmt;
                     if ($use_date == '0000-00-00 00:00:00Z') {
                         $use_date = $comment->comment_date;
                     }
                     if ($use_date != null && !strstr($use_date, '0000-00-00')) {
                         $commentXML .= '<created>' . preg_replace('/\\s/', 'T', $use_date) . 'Z</created>';
                     } else {
                         // We need to supply a datetime so the XML parser does not fail
                         $now = new DateTime();
                         $commentXML .= '<created>' . $now->format('Y-m-d\\TH:i:s\\Z') . '</created>';
                     }
                     $commentXML .= '</comment>';
                     $newArticle .= $commentXML;
                 }
                 $newArticle .= '</article>';
                 if (strlen($newArticle) + strlen($articles) > $maxlength && strlen($articles)) {
                     $next_chunk = true;
                     break;
                 } else {
                     $inner_idx += 1;
                     $articles .= $newArticle;
                 }
                 unset($newArticle);
             }
         }
     } while ($myposts->found_posts != 0 && !$next_chunk && ($index = $index + 10));
     if (strlen($articles) == 0) {
         return 'no-data';
     } else {
         return 'to-offset:' . ($inner_idx + $index) . "\n" . $this->wrap_xml($articles);
     }
 }
function wp_geshi_filter_and_replace_code_snippets()
{
    global $wp_query;
    global $wp_geshi_comments;
    // Iterate over all posts in this query.
    foreach ($wp_query->posts as $post) {
        // Extract code snippets from the content. Replace them.
        $post->post_content = wp_geshi_filter_replace_code($post->post_content);
        // Iterate over all approved comments belonging to this post.
        // Store comments with uuid (code replacement) in `$wp_geshi_comments`.
        $comments = get_approved_comments($post->ID);
        foreach ($comments as $comment) {
            $wp_geshi_comments[$comment->comment_ID] = wp_geshi_filter_replace_code($comment->comment_content);
        }
    }
}
 public static function filter_comments_number($count)
 {
     global $id;
     if (empty($id)) {
         return $count;
     }
     $comments = get_approved_comments((int) $id);
     $comments = array_filter($comments, array("AECUtility", 'filter_strip_trackbacks'));
     return sizeof($comments);
 }
Example #16
0
function mystique_comment_count($comment_types = 'comments', $post_id = false)
{
    global $id;
    $post_id = (int) $post_id;
    if (!$post_id) {
        $post_id = $id;
    }
    $comments = get_approved_comments($post_id);
    $num_pings = 0;
    $num_comments = 0;
    foreach ($comments as $comment) {
        if (get_comment_type() != "comment") {
            $num_pings++;
        } else {
            $num_comments++;
        }
    }
    return $comment_types == 'comments' ? $num_comments : $num_pings;
}
Example #17
0
 /**
  * LazyestCommentor::get_approved_comments()
  * Adds filevar varaiable to comments
  * 
  * @since 1.1.0
  * @return array all comments on gallery 
  */
 function get_approved_comments()
 {
     global $lg_gallery, $wpdb;
     $page_id = (int) $lg_gallery->get_option('gallery_id');
     $comments = get_approved_comments($page_id);
     $files = $wpdb->get_results("SELECT * FROM {$lg_gallery->table}");
     $results = $wpdb->get_results("SELECT comment_id, meta_value FROM  {$wpdb->commentmeta} WHERE meta_key = 'lazyest';");
     foreach ($comments as $comment) {
         $img_id = 0;
         foreach ($results as $result) {
             if ($comment->comment_ID == $result->comment_id) {
                 $img_id = $result->meta_value;
                 break;
             }
         }
         if (0 == $img_id) {
             $comment->filevar = '';
         } else {
             foreach ($files as $file) {
                 if ($file->img_ID == $img_id) {
                     $comment->filevar = $file->file;
                     break;
                 }
             }
         }
     }
     return $comments;
 }
Example #18
0
        echo show_comments($c, true);
        ?>
        <?php 
    }
    ?>
      </ul>
    </div>
    <div class="comment-input">
      <?php 
    get_template_part('shared/comment_form');
    ?>
    </div>
  <?php 
} else {
    ?>
    <span class="article__section--text">
      <i class="material-icons">comment</i>
      <?php 
    echo count(get_approved_comments(get_the_ID()));
    ?>
    </span>
    <div class="comment-input">
      <?php 
    get_template_part('shared/comment_form');
    ?>
    </div>
  <?php 
}
?>
</div>
Example #19
0
/**
 * Retrieve the amount of Pingback/Trackbacks a post has.
 *
 * @param int $count The Comment Count
 * @param int $post_id The Post ID
 * @return int The number of Pingback/Trackbacks a post has
 *
 * @since rtPanel 2.0
 */
function pingback_trackback_count($count, $post_id)
{
    $comments = get_approved_comments($post_id);
    $pingtrack_count = 0;
    foreach ($comments as $comment) {
        if ($comment->comment_type != '') {
            $pingtrack_count++;
        }
    }
    return $pingtrack_count;
}
 /**
  * @group bp_blogs_comment_sync_activity_comment
  * @group post_type_comment_activities
  */
 public function test_bp_blogs_comment_sync_activity_comment_for_custom_post_type()
 {
     if (is_multisite()) {
         $b = $this->factory->blog->create();
         switch_to_blog($b);
         add_filter('comment_flood_filter', '__return_false');
     } else {
         $b = get_current_blog_id();
     }
     $u = $this->factory->user->create();
     $userdata = get_userdata($u);
     $labels = array('name' => 'bars', 'singular_name' => 'bar');
     register_post_type('foo', array('labels' => $labels, 'public' => true, 'supports' => array('comments')));
     add_post_type_support('foo', 'buddypress-activity');
     bp_activity_set_post_type_tracking_args('foo', array('comment_action_id' => 'new_foo_comment'));
     add_filter('bp_disable_blogforum_comments', '__return_false');
     $p = $this->factory->post->create(array('post_author' => $u, 'post_type' => 'foo'));
     $a1 = bp_activity_get_activity_id(array('type' => 'new_foo', 'filter' => array('item_id' => $b, 'secondary_item_id' => $p)));
     $c = wp_new_comment(array('comment_post_ID' => $p, 'comment_author' => $userdata->user_nicename, 'comment_author_url' => 'http://buddypress.org', 'comment_author_email' => $userdata->user_email, 'comment_content' => 'this is a foo comment', 'comment_type' => '', 'comment_parent' => 0, 'user_id' => $u));
     $a2 = bp_activity_new_comment(array('content' => 'this should generate a new foo comment', 'user_id' => $u, 'activity_id' => $a1));
     $activity_args = array('type' => 'activity_comment', 'display_comments' => 'stream', 'meta_query' => array(array('key' => 'bp_blogs_foo_comment_id', 'compare' => 'exists')));
     $a = bp_activity_get($activity_args);
     $aids = wp_list_pluck($a['activities'], 'id');
     $cids = wp_list_pluck(get_approved_comments($p), 'comment_ID');
     foreach ($aids as $aid) {
         $this->assertTrue(in_array(bp_activity_get_meta($aid, 'bp_blogs_foo_comment_id'), $cids), 'The comment ID should be in the activity meta');
     }
     foreach ($cids as $cid) {
         $this->assertTrue(in_array(get_comment_meta($cid, 'bp_activity_comment_id', true), $aids), 'The activity ID should be in the comment meta');
     }
     _unregister_post_type('foo');
     if (is_multisite()) {
         restore_current_blog();
         remove_filter('comment_flood_filter', '__return_false');
     }
     remove_filter('bp_disable_blogforum_comments', '__return_false');
 }
Example #21
0
<?php

if (have_comments()) {
    $comment_count = 0;
    $pings_and_tracks = 0;
    foreach (get_approved_comments($id) as $comment) {
        if ($comment->comment_type === '') {
            $comment_count++;
        } else {
            $pings_and_tracks++;
        }
    }
    if ($comment_count > 0) {
        ?>

		<div id="comments" class="the_comments">
			<h3 class="post_title"><?php 
        _e('Comments', 'localize_adventure');
        ?>
</h3>
			<ul class="commentlist"><?php 
        wp_list_comments(array('avatar_size' => 100, 'style' => 'li', 'type' => 'comment'));
        ?>
</ul>
		</div>

	<?php 
    }
    if ($pings_and_tracks > 0) {
        ?>
Example #22
0
            </div>
        
        <?php 
}
?>
    </div>
    <?php 
do_action('digressit_toplevel_commentbox');
?>
    </div>
    
    <div id="comments-sort-all"><?php 
_e('show all', 'digressit');
?>
 (<?php 
echo count(get_approved_comments($post->ID));
?>
)</div>    
    <div id="no-comments"><?php 
_e('There are no comments. Click the text to your left to make a new comment.', 'digressit');
?>
</div>
    <?php 
if (have_comments()) {
    ?>
        <?php 
    global $post;
    ?>
    
        <div id="commentlist" class="commentlist">
        <?php 
Example #23
0
/**
 * @return bool
 */
function dsq_can_replace()
{
    global $id, $post;
    if (get_option('disqus_active') === '0') {
        return false;
    }
    $replace = get_option('disqus_replace');
    $dcl_gnrl_options = get_option('dcl_gnrl_options');
    $excluded_cpts = dcl_splite_to_array($dcl_gnrl_options['dcl_cpt_exclude']);
    if (is_feed()) {
        return false;
    }
    if (!isset($post)) {
        return false;
    }
    if ('draft' == $post->post_status) {
        return false;
    }
    if (!get_option('disqus_forum_url')) {
        return false;
    }
    if ('product' == get_post_type()) {
        return false;
    }
    // exclude cpts
    if (in_array(get_post_type(), $excluded_cpts)) {
        return false;
    } else {
        if ('all' == $replace) {
            return true;
        }
    }
    if (!isset($post->comment_count)) {
        $num_comments = 0;
    } else {
        if ('empty' == $replace) {
            // Only get count of comments, not including pings.
            // If there are comments, make sure there are comments (that are not track/pingbacks)
            if ($post->comment_count > 0) {
                // Yuck, this causes a DB query for each post.  This can be
                // replaced with a lighter query, but this is still not optimal.
                $comments = get_approved_comments($post->ID);
                foreach ($comments as $comment) {
                    if ($comment->comment_type != 'trackback' && $comment->comment_type != 'pingback') {
                        $num_comments++;
                    }
                }
            } else {
                $num_comments = 0;
            }
        } else {
            $num_comments = $post->comment_count;
        }
    }
    return 'empty' == $replace && 0 == $num_comments || 'closed' == $replace && 'closed' == $post->comment_status;
}
Example #24
0
/** build the XML file, sitemap_baidu.xml **/
function build_baidu_sitemap()
{
    global $wpdb, $posts, $wp_version;
    $get_baidu_sitemap_options = get_option(BAIDU_SITEMAP_OPTION);
    if (!empty($get_baidu_sitemap_options)) {
        list($lc_blog_url, $lc_admin_email, $lc_updatePeri, $lc_limits, $lc_sitemap_auto, $lc_order_1, $lc_order_2, $lc_order_3, $lc_comments, $lc_post_length, $lc_post_cat, $lc_post_views, $lc_pickcats, $lc_comments_count, $lc_views_count, $lc_sitemap_html, $lc_sitemap_publish_post, $lc_support, $lc_baidu_sitemap_by_post) = explode("|", $get_baidu_sitemap_options);
    }
    $lc_pickcats_array = explode(";", $lc_pickcats);
    $blog_home = get_bloginfo('url');
    /** Get the current time **/
    $blogtime = current_time('mysql');
    list($today_year, $today_month, $today_day, $hour, $minute, $second) = split('([^0-9])', $blogtime);
    /** XML_begin **/
    $xml_begin = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
    $xml_begin .= '<document xmlns:bbs="http://www.baidu.com/search/bbs_sitemap.xsd">' . "\n";
    $xml_begin .= xml_annotate();
    $xml_begin .= '<webSite>' . "{$lc_blog_url}" . '</webSite>' . "\n";
    $xml_begin .= '<webMaster>' . "{$lc_admin_email}" . '</webMaster>' . "\n";
    $xml_begin .= '<updatePeri>' . "{$lc_updatePeri}" . '</updatePeri>' . "\n";
    $xml_begin .= '<updatetime>' . "{$today_year}-{$today_month}-{$today_day} {$hour}:{$minute}:{$second}" . '</updatetime>' . "\n";
    $xml_begin .= '<version>' . "WordPress" . '</version>' . "\n";
    //echo $xml_begin;
    /** get the post title,ID,post_date from database **/
    $sql = "SELECT DISTINCT ID\r\n\t\tFROM {$wpdb->posts}\r\n\t\tLEFT JOIN {$wpdb->comments} ON ( {$wpdb->posts}.ID = {$wpdb->comments}.comment_post_ID ) \r\n\t\tWHERE post_password = ''\r\n\t\tAND post_type = 'post'\r\n\t\tAND post_status = 'publish'\r\n\t\tORDER BY {$lc_order_1} DESC \r\n\t\tLIMIT 0,{$lc_limits}";
    $recentposts = $wpdb->get_results($sql);
    if ($recentposts) {
        foreach ($recentposts as $post) {
            /** Post URL **/
            $permalink = EscapeXML(stripslashes_deep(get_permalink($post->ID)));
            if ($lc_blog_url) {
                $permalink = str_replace("{$blog_home}", "{$lc_blog_url}", $permalink);
            }
            //2009-11-25
            /** Post **/
            $my_post = get_post($post->ID, ARRAY_A);
            $post_title = EscapeXML(stripslashes_deep($my_post['post_title']));
            $post_date = $my_post['post_date'];
            /** show the comments info **/
            if ($lc_comments == '1') {
                $comment_count = $my_post['comment_count'];
                $comment_array = get_approved_comments($post->ID);
                if ($comment_array) {
                    $last_comment = array_pop($comment_array);
                    $my_comment = get_comment($last_comment->comment_ID, ARRAY_A);
                    $comment_date = $my_comment['comment_date'];
                } else {
                    $comment_date = $post_date;
                }
            }
            /** show the post_length **/
            if ($lc_post_length == '1') {
                $post_content_str = strlen($my_post['post_content']);
            }
            /** show the cat name **/
            if ($lc_post_cat == '1') {
                $category = get_the_category($post->ID);
                if (count($category) == '1') {
                    $my_cat = EscapeXML(stripslashes_deep($category[0]->cat_name));
                }
                if (count($category) == '2') {
                    $my_cat = EscapeXML(stripslashes_deep($category[0]->cat_name . "," . $category[1]->cat_name));
                }
                if (count($category) == '3') {
                    $my_cat = EscapeXML(stripslashes_deep($category[0]->cat_name . "," . $category[1]->cat_name . "," . $category[2]->cat_name));
                }
                if (count($category) == '4') {
                    $my_cat = EscapeXML(stripslashes_deep($category[0]->cat_name . "," . $category[1]->cat_name . "," . $category[2]->cat_name . "," . $category[3]->cat_name));
                }
                if (count($category) == '5') {
                    $my_cat = EscapeXML(stripslashes_deep($category[0]->cat_name . "," . $category[1]->cat_name . "," . $category[2]->cat_name . "," . $category[3]->cat_name . "," . $category[4]->cat_name));
                }
            }
            /** show the post_views **/
            if (function_exists('the_views')) {
                //echo "YES";
                //echo $post->ID."#";
                $sql_views = "SELECT DISTINCT meta_value as views\r\n\t\t\t\tFROM {$wpdb->postmeta}\r\n\t\t\t\tWHERE post_id = '{$post->ID}'\r\n\t\t\t\tAND meta_key = 'views'\r\n\t\t\t\tLIMIT 0,1";
                $post_views_array = $wpdb->get_results($sql_views);
                if ($post_views_array || !empty($post_views_array)) {
                    foreach ($post_views_array as $post_views) {
                        if ($post_views) {
                            $post_views = number_format_i18n(intval($post_views->views));
                        } else {
                            $post_views = '1';
                        }
                    }
                } else {
                    $post_views = '1';
                }
            }
            //echo $post_views.";";
            /** the pick post **/
            if (!empty($lc_pickcats_array) && $lc_pickcats_array[0] != '0' || !empty($lc_comments_count) && $lc_comments_count != '0' || !empty($lc_views_count) && ${$lc_views_count} != '0') {
                $pick = 0;
                if ($pick == '0') {
                    if (!empty($lc_pickcats_array) && $lc_pickcats_array[0] != '0') {
                        $cat_ID = array();
                        foreach (get_the_category($post->ID) as $category) {
                            array_push($cat_ID, $category->cat_ID);
                            if (array_intersect($cat_ID, $lc_pickcats_array)) {
                                $pick = '1';
                            }
                        }
                    }
                }
                if ($pick == '0') {
                    if (!empty($lc_comments_count) && $lc_comments_count != '0') {
                        if (empty($comment_count)) {
                            $comment_count = $my_post['comment_count'];
                        }
                        //get post_comment_count
                        if ($comment_count - $lc_comments_count >= '1') {
                            $pick = '1';
                        }
                    }
                }
                if ($pick == '0') {
                    if (!empty($lc_views_count) && function_exists('the_views') && $lc_views_count != '0') {
                        if ($post_views - $lc_views_count >= '1') {
                            $pick = '1';
                        }
                    }
                }
            }
            //echo $pick.";  ";
            $xml_middle = '<item>' . "\n";
            //$xml_middle .= '<link>'."$lc_blog_url".'/?p='."$post_ID".'</link>'."\n";
            $xml_middle .= '<link>' . $permalink . '</link>' . "\n";
            $xml_middle .= '<title>' . "{$post_title}" . '</title>' . "\n";
            $xml_middle .= '<pubDate>' . "{$post_date}" . '</pubDate>' . "\n";
            if ($lc_comments == '1') {
                $xml_middle .= '<bbs:lastDate>' . $comment_date . '</bbs:lastDate>' . "\n";
                $xml_middle .= '<bbs:reply>' . $comment_count . '</bbs:reply>' . "\n";
            }
            if (function_exists('the_views') && $lc_post_views == '1') {
                $xml_middle .= '<bbs:hit>' . $post_views . '</bbs:hit>' . "\n";
            }
            if ($lc_post_length == '1') {
                $xml_middle .= '<bbs:mainLen>' . $post_content_str . '</bbs:mainLen>' . "\n";
            }
            if ($lc_post_cat == '1') {
                $xml_middle .= '<bbs:boardid>' . $my_cat . '</bbs:boardid>' . "\n";
            }
            if (!empty($lc_pickcats_array) && $lc_pickcats_array[0] != '0' || !empty($lc_comments_count) && $lc_comments_count != '0' || !empty($lc_views_count) && ${$lc_views_count} != '0') {
                $xml_middle .= '<bbs:pick>' . $pick . '</bbs:pick>' . "\n";
            }
            $xml_middle .= '</item>' . "\n";
            $xml_middle_done .= $xml_middle;
            /** html_contents **/
            $comment_count = $my_post['comment_count'];
            if ($comment_count || $comment_count == 0) {
                $html_comment = str_replace("%html_comment%", $comment_count, __('Comments %html_comment%', 'baidu_sitemap'));
            }
            if ($post_views) {
                $html_views = str_replace("%html_views%", $post_views, __('&nbsp;&nbsp;&nbsp;Views %html_views%', 'baidu_sitemap'));
            } else {
                $html_views = '';
            }
            $html_content = '<li><a href="' . $permalink . '">' . $post_title . '</a>&nbsp;&nbsp;(' . $html_comment . '' . $html_views . ')</li>';
            $html_contents .= $html_content . "\n";
        }
    }
    /** XML_end **/
    $xml_end = '</document>';
    /** XML_ALL **/
    $baidu_xml = $xml_begin . $xml_middle_done . $xml_end;
    /** save XML file as sitemap_baidu.xml **/
    $GetHomePath = GetHomePath();
    $filename = $GetHomePath . 'sitemap_baidu.xml';
    if (IsFileWritable($GetHomePath) || IsFileWritable($filename)) {
        file_put_contents("{$filename}", "{$baidu_xml}");
        /** Messages  **/
        baidu_sitemap_topbarmessage(__('Congratulate, Build the XML file success', 'baidu_sitemap'));
    } else {
        /** Messages  **/
        baidu_sitemap_topbarmessage(__('Directory is not writable. please chmod your directory to 777.', 'baidu_sitemap'));
    }
    /** html sitemap Page **/
    if ($lc_sitemap_html = '1') {
        $blog_title = __('SiteMap', 'baidu_sitemap');
        $blog_name = get_bloginfo('name');
        $blog_keywords = $blog_title . ',' . $blog_name;
        $lc_generator = 'Baidu SiteMap Generator';
        $lc_author = 'Liucheng.Name';
        $lc_copyright = 'Liucheng.Name';
        $blog_home = get_bloginfo('url');
        $sitemap_url = get_bloginfo('url') . '/sitemap.html';
        $recentpost = __('RecentPost', 'baidu_sitemap');
        $footnote = __('HomePage', 'baidu_sitemap');
        $updated_time = "{$today_year}-{$today_month}-{$today_day} {$hour}:{$minute}:{$second}";
        if ($html_contents) {
            $path_html = GetPluginPath() . 'sitemap.html';
            $html = file_get_contents("{$path_html}");
            $html = str_replace("%blog_title%", $blog_title, $html);
            $html = str_replace("%blog_name%", $blog_name, $html);
            $html = str_replace("%blog_home%", $blog_home, $html);
            $html = str_replace("%blog_keywords%", $blog_keywords, $html);
            $html = str_replace("%lc_generator%", $lc_generator, $html);
            $html = str_replace("%lc_author%", $lc_author, $html);
            $html = str_replace("%lc_copyright%", $lc_copyright, $html);
            $html = str_replace("%sitemap_url%", $sitemap_url, $html);
            $html = str_replace("%footnote%", $footnote, $html);
            $html = str_replace("%RecentPost%", $recentpost, $html);
            $html = str_replace("%updated_time%", $updated_time, $html);
            $html = str_replace("%contents%", $html_contents, $html);
            $filename_html = $GetHomePath . 'sitemap.html';
            if (IsFileWritable($GetHomePath) || IsFileWritable($filename_html)) {
                file_put_contents("{$filename_html}", "{$html}");
                /** Messages  **/
                //baidu_sitemap_topbarmessage(__('Congratulate, Build the XML file success','baidu_sitemap'));
            }
        }
        //echo $html;
    }
    if (function_exists('wp_clear_scheduled_hook')) {
        wp_clear_scheduled_hook('do_this_auto');
    }
    if (function_exists('wp_clear_scheduled_hook')) {
        wp_clear_scheduled_hook('do_baidu_sitemap_2');
    }
    baidu_sitemap_is_auto();
}
 /**
  * List of product reviews.
  *
  * ## OPTIONS
  *
  * <id>
  * : Product ID.
  *
  * [--field=<field>]
  * : Instead of returning the whole review fields, returns the value of a single fields.
  *
  * [--fields=<fields>]
  * : Get a specific subset of the review's fields.
  *
  * [--format=<format>]
  * : Accepted values: table, json, csv. Default: table.
  *
  * ## EXAMPLES
  *
  *     wp wc product reviews 123
  *
  *     wp wc product reviews 123 --fields=id,rating,reviewer_email
  *
  * @since 2.5.0
  */
 public function reviews($args, $assoc_args)
 {
     try {
         $id = $args[0];
         $product = wc_get_product($id);
         if (!$product) {
             throw new WC_CLI_Exception('woocommerce_cli_invalid_product', sprintf(__('Invalid product "%s"', 'woocommerce'), $id));
         }
         $comments = get_approved_comments($id);
         $reviews = array();
         foreach ($comments as $comment) {
             $reviews[] = array('id' => intval($comment->comment_ID), 'created_at' => $this->format_datetime($comment->comment_date_gmt), 'review' => $comment->comment_content, 'rating' => get_comment_meta($comment->comment_ID, 'rating', true), 'reviewer_name' => $comment->comment_author, 'reviewer_email' => $comment->comment_author_email, 'verified' => (bool) get_comment_meta($comment->comment_ID, 'verified', true));
         }
         if (empty($assoc_args['fields'])) {
             $assoc_args['fields'] = $this->get_review_fields();
         }
         $formatter = $this->get_formatter($assoc_args);
         $formatter->display_items($reviews);
     } catch (WC_CLI_Exception $e) {
         WP_CLI::error($e->getMessage());
     }
 }
 /**
  * Build and return a comma-separated list of comment IDs for comments attached to a post.
  *
  * @since   0.8.0
  *
  * @param   int|object  $post  The post ID or object.
  * @return  string             The string of comment IDs or empty.
  */
 public function get_comment_ids_for_post($post)
 {
     // Handle $post being an ID or a post object.
     if (is_object($post)) {
         $post_id = $post->ID;
     } elseif (is_int($post)) {
         $post_id = $post;
     } else {
         return '';
     }
     $comments = get_approved_comments($post_id);
     // Return empty string if the post has no comments.
     if (empty($comments)) {
         return '';
     }
     $comments_array = array();
     foreach ($comments as $comment) {
         $comments_array[] = $comment->comment_ID;
     }
     sort($comments_array);
     // Return a comma-separated string of comment IDs.
     return implode(',', $comments_array);
 }
"><abbr title="Really Simple Syndication">RSS</abbr> feed for comments on this post.</a></p>
		<?php 
    if ('open' == $post->ping_status) {
        ?>
			<p>The <abbr title="Universal Resource Locator">URL</abbr> to TrackBack this entry is: <em><?php 
        trackback_url();
        ?>
</em></p>
		<?php 
    }
    ?>
		<?php 
    // this line is WordPress' motor, do not delete it.
    $commenter = wp_get_current_commenter();
    extract($commenter);
    $comments = get_approved_comments($id);
    $post = get_post($id);
    if (!empty($post->post_password) && $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) {
        // and it doesn't match the cookie
        echo get_the_password_form();
    } else {
        ?>
				<?php 
        if ($comments) {
            ?>
					<ol id="commentlist">
						<?php 
            foreach ($comments as $comment) {
                ?>
							<li id="comment-<?php 
                comment_ID();
if ( $comments ) {
	foreach ( $comments as $comment ) {
		//echo $comment->comment_approved;
	 
		 echo get_avatar( 'comment->comment_author_email', 50 ); 
	//echo get_avatar(get_the_author_meta('user_email'), $size = '96', $default = '<path_to_url>' ); 	
		echo '<p>' . $comment->comment_author .'</p>'; echo 'says';
		echo '<p>' . $comment->comment_content . '</p>';
	 
		
	}
} else {
	echo 'No comments found.';
}*/
$postID = get_the_ID();
$comment_array = get_approved_comments($postID);
foreach ($comment_array as $comment) {
    echo get_avatar('comment->comment_author_email', 50);
    //echo get_avatar(get_the_author_meta('user_email'), $size = '96', $default = '<path_to_url>' );
    echo '<p>' . $comment->comment_author . '</p>';
    echo 'says';
    echo '<p>' . $comment->comment_content . '</p>';
}
?>
           </div>
            <div id="fourth">
		
                <p><?php 
comment_form($args, $post_id);
?>
</p>
 /**
  * Get the reviews for a product
  *
  * @since 2.1
  * @param int $id the product ID to get reviews for
  * @param string $fields fields to include in response
  * @return array
  */
 public function get_product_reviews($id, $fields = null)
 {
     $id = $this->validate_request($id, 'product', 'read');
     if (is_wp_error($id)) {
         return $id;
     }
     $comments = get_approved_comments($id);
     $reviews = array();
     foreach ($comments as $comment) {
         $reviews[] = array('id' => intval($comment->comment_ID), 'created_at' => $this->server->format_datetime($comment->comment_date_gmt), 'review' => $comment->comment_content, 'rating' => get_comment_meta($comment->comment_ID, 'rating', true), 'reviewer_name' => $comment->comment_author, 'reviewer_email' => $comment->comment_author_email, 'verified' => wc_review_is_from_verified_owner($comment->comment_ID));
     }
     return array('product_reviews' => apply_filters('woocommerce_api_product_reviews_response', $reviews, $id, $fields, $comments, $this->server));
 }
Example #30
0
function vegpledge_get_all_pledges()
{
    $pledges = array();
    $pledge_labels = vegpledge_pledge_ticker_labels();
    $pledge_comments = get_approved_comments(12);
    foreach ($pledge_comments as $pledge_comment) {
        foreach (get_comment_meta($pledge_comment->comment_ID, 'vegpledge') as $pledge) {
            $pledges[] = $pledge_comment->comment_author . ' pledged to ' . $pledge_labels[$pledge];
        }
    }
    shuffle($pledges);
    return $pledges;
}