コード例 #1
0
/**
 * Rating manager save comment like and dislike.
 *
 * @since 1.0.0
 * @package GeoDirectory_Review_Rating_Manager
 *
 * @param string $ajaxcommentid string contains Comment ID and like or dislike option.
 */
function geodir_reviewrating_save_like_unlike($ajaxcommentid)
{
    global $wpdb;
    if ($ajaxcommentid != '') {
        $ids = explode('-', $ajaxcommentid);
        $comment_id = $ids[1];
        $like_unlike = $ids[0];
        $ip_address = $_SERVER["REMOTE_ADDR"];
        $has_liked = $wpdb->get_var($wpdb->prepare("SELECT count(like_id) FROM " . GEODIR_COMMENTS_REVIEWS_TABLE . " WHERE comment_id=%d AND ip=%s", array($comment_id, $ip_address)));
        if ($like_unlike == 'like') {
            if ($has_liked == 0) {
                $wpdb->query($wpdb->prepare("UPDATE " . GEODIR_REVIEWRATING_POSTREVIEW_TABLE . " SET wasthis_review=wasthis_review+1 WHERE comment_id=%d", array($comment_id)));
                $wpdb->query($wpdb->prepare("INSERT INTO " . GEODIR_COMMENTS_REVIEWS_TABLE . " (comment_id, ip, like_unlike) VALUES (%d, %s, '1')", array($comment_id, $ip_address)));
            }
        } else {
            if ($has_liked > 0) {
                $wpdb->query($wpdb->prepare("UPDATE " . GEODIR_REVIEWRATING_POSTREVIEW_TABLE . " SET wasthis_review=wasthis_review-1 WHERE comment_id=%d", array($comment_id)));
                $wpdb->query($wpdb->prepare("DELETE FROM " . GEODIR_COMMENTS_REVIEWS_TABLE . " WHERE comment_id=%d AND ip=%s", array($comment_id, $ip_address)));
            }
        }
    }
    geodir_reviewrating_comments_like_unlike($comment_id);
    exit;
}
コード例 #2
0
/**
 * Adds rating manager fields to the comment text.
 *
 * @since 1.0.0
 * @package GeoDirectory_Review_Rating_Manager
 *
 * @global string $geodir_post_type The post type.
 *
 * @param string $content Comment text.
 * @param string|object $comment The comment object.
 * @return string Modified comment text.
 */
function geodir_reviewrating_wrap_comment_text($content, $comment = '')
{
    global $geodir_post_type;
    $all_postypes = geodir_get_posttypes();
    if (!in_array($geodir_post_type, $all_postypes)) {
        return $content;
    }
    $like_unlike = '';
    if (!empty($comment) && !is_admin() && !$comment->comment_parent) {
        if (get_option('geodir_reviewrating_enable_rating')) {
            $comment_ratings = geodir_reviewrating_get_comment_rating_by_id($comment->comment_ID);
            $comment_rating_overall = isset($comment_ratings->overall_rating) ? $comment_ratings->overall_rating : '';
            $overall_html = geodir_reviewrating_draw_overall_rating($comment_rating_overall);
            $ratings = @unserialize($comment_ratings->ratings);
        }
        if (!is_admin()) {
            $ratings_html = geodir_reviewrating_draw_ratings($ratings);
            $comment_images = geodir_reviewrating_get_comment_images($comment->comment_ID);
        }
        $images_show_hide = '';
        $comment_images_display = '';
        if (get_option('geodir_reviewrating_enable_images')) {
            $total_images = 0;
            if (isset($comment_images->images) && $comment_images->images != '') {
                $total_images = explode(',', $comment_images->images);
            }
            // open lightbox on click
            $div_click = (int) get_option('geodir_disable_gb_modal') != 1 ? 'div.place-gallery' : 'div.overall-more-rating';
            $onclick = !empty($comment_images) && count($total_images) > 0 ? 'onclick="javascript:jQuery(this).closest(\'.gdreview_section\').find(\'' . $div_click . ' a:first\').trigger(\'click\');"' : '';
            $images_show_hide = '<span class="showcommentimages" comment_id="' . $comment->comment_ID . '" ' . $onclick . ' ><i class="fa fa-camera"></i> <a href="javascript:void(0);">';
            if (empty($comment_images) || count($total_images) == 0) {
                $images_show_hide .= __('No Photo', GEODIRREVIEWRATING_TEXTDOMAIN);
            } elseif (count($total_images) == 1) {
                $images_show_hide .= sprintf(__('%d Photo', GEODIRREVIEWRATING_TEXTDOMAIN), 1);
            } else {
                $images_show_hide .= sprintf(__('%d Photos', GEODIRREVIEWRATING_TEXTDOMAIN), (int) count($total_images));
            }
            $images_show_hide .= '</a></span>';
            $comment_images_display = $images_show_hide;
        }
        if (get_option('geodir_reviewrating_enable_rating')) {
            $overallrating_html = '<div class="comment_overall"><span>' . $overall_html . '</span></div>';
            $rating_html = $ratings_html;
        }
        if (get_option('geodir_reviewrating_enable_review') && !is_admin()) {
            $like_unlike = geodir_reviewrating_comments_like_unlike($comment->comment_ID, false);
        }
        ob_start();
        ?>
			<div class="gdreview_section">
                <div class="clearfix">
                    <?php 
        echo $overallrating_html;
        ?>
                    <div  style="float:left;"><?php 
        echo $comment_images_display;
        ?>
</div>
                    <?php 
        echo $like_unlike;
        ?>
                    <div class="overall-more-rating"><a href="javascript:void(0)"><?php 
        _e('more', GEODIRREVIEWRATING_TEXTDOMAIN);
        ?>
</a></div>
                </div>
                <div class="comment_more_ratings clearfix">
					<?php 
        echo $rating_html;
        ?>
                    <?php 
        if (isset($comment_images->html)) {
            echo $comment_images->html;
        }
        ?>
                </div>
          	</div>
            <div class="commenttext geodir-reviewrating-commenttext"><?php 
        echo $content;
        ?>
</div>
         
		<?php 
        $content = ob_get_clean();
        return $content;
    } else {
        return $content;
    }
}