function kopa_click_like_button() { check_ajax_referer('kopa_click_like_button', 'ajax_nonce'); if (!empty($_POST['post_id'])) { $result = array('status' => 'disable', 'total' => 0); $post_id = (int) $_POST['post_id']; $status = $_POST['status']; $include_text = $_POST['include_text']; $public_key = KOPA_OPT_PREFIX . 'likes'; $single_key = KOPA_OPT_PREFIX . 'like_by_' . KopaUtil::get_client_IP(); $total = KopaUtil::get_likes($post_id); $is_liked = KopaUtil::is_liked($post_id); if ('enable' == $status && !$is_liked) { $total++; update_post_meta($post_id, $single_key, true); update_post_meta($post_id, $public_key, abs($total)); $result['class'] = 'kopa-button-likes-disable'; } else { $total--; delete_post_meta($post_id, $single_key); update_post_meta($post_id, $public_key, abs($total)); $result['class'] = 'kopa-button-likes-enable'; } if ($include_text) { if ($total < 2) { $total .= __(' Like', kopa_get_domain()); } else { $total .= __(' Likes', kopa_get_domain()); } } $result['total'] = $total; echo json_encode($result); } exit; }
/** * @package Kopa * @subpackage Core * @author thethangtran <*****@*****.**> * @since 1.0.0 */ public static function kopa_get_like_button($post_id, $include_text = false) { $class = ''; if (self::is_liked($post_id)) { $class = 'kopa-button-likes-disable'; } else { $class = 'kopa-button-likes-enable'; } $onclick = sprintf('onclick="KopaFrontend.click_likes_button(event, jQuery(this), %s, \'%s\')"', $post_id, $include_text); $out = sprintf('<span class="%s" %s>%s<span>%s</span></span>', $class, $onclick, KopaIcon::getIconLike(), KopaUtil::get_likes($post_id, $include_text)); return apply_filters('kopa_get_like_button', $out, $post_id); }
public function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); echo $before_widget; if (!empty($title)) { echo $before_title . $title . $after_title; } $instance['posts_per_page'] = 4; $query = $this->build_query($instance); $posts = new WP_Query($query); if ($posts->have_posts()) { ?> <div class="widget-content container clearfix"> <div class="owl-slider-col-left pull-left"> <?php $is_first = true; $loop_index = 0; while ($posts->have_posts()) { $posts->the_post(); if (has_post_thumbnail()) { $classes = array('owl-slider-navigation-post-title'); if ($is_first) { $classes[] = 'active'; $classes[] = 'first'; $is_first = false; } ?> <p class="<?php echo implode(' ', $classes); ?> " data-index="<?php echo $loop_index; ?> "> <?php echo get_the_title(); ?> </p> <?php $loop_index++; } } ?> </div> <div class="owl-slider-col-center pull-left"> <div class="owl-carousel" data-transition="<?php echo $instance['transition_type']; ?> "> <?php $is_first = true; global $post; while ($posts->have_posts()) { $posts->the_post(); $post_id = get_the_ID(); $post_title = get_the_title(); $post_url = get_permalink(); $post_format = get_post_format(); if (has_post_thumbnail()) { $classes = array('owl-slider-single-slide'); if ($is_first) { $classes[] = 'active'; $classes[] = 'first'; $classes[] = 'synced'; $is_first = false; } $image_croped = KopaImage::get_post_image_src($post_id, 'size_11'); ?> <div class="<?php echo implode(' ', $classes); ?> "> <?php if ('video' == $post_format) { $video = KopaUtil::get_video($post->post_content, array('youtube', 'vimeo')); if ($video) { $url = ''; if ('youtube' == $video['type']) { $url = 'http://www.youtube.com/watch?v=' . $video['id']; } else { if ('vimeo' == $video['type']) { $url = 'https://vimeo.com/' . $video['id']; } } printf('<a class="kss-icon kss-icon-play" href="%s"><span class="fa fa-play"></span></a>', $url); } } ?> <img src="<?php echo $image_croped; ?> " alt="<?php echo $post_title; ?> "> <a href="<?php echo $post_url; ?> " title="<?php echo $post_title; ?> "><?php echo $post_title; ?> </a> </div> <?php } } ?> </div> </div> <div class="owl-slider-col-right pull-left"> <div class="owl-carousel"> <?php $is_first = true; while ($posts->have_posts()) { $posts->the_post(); $post_id = get_the_ID(); $post_title = get_the_title(); $post_url = get_permalink(); $post_format = get_post_format(); if (has_post_thumbnail()) { $classes = array('owl-slider-single-slide-detail'); if ($is_first) { $classes[] = 'first'; $classes[] = 'synced'; $is_first = false; } ?> <div class="<?php echo implode(' ', $classes); ?> "> <span class="kopa-icon-post-format"><?php echo KopaIcon::getIconPostFormat($post_format, 'span'); ?> </span> <?php if ('true' != $instance['is_hide_created_date']) { ?> <span class="kopa-date"><?php echo get_the_date('M, j'); ?> <br/><?php echo get_the_date('Y'); ?> </span> <?php } ?> <?php if ('true' != $instance['is_hide_views'] || 'true' != $instance['is_hide_comments'] || 'true' != $instance['is_hide_views']) { ?> <ul class="kopa-metadata"> <?php if ('true' != $instance['is_hide_comments']) { ?> <li class="metadata-first"><i class="fa fa-comment"></i><span><?php echo KopaUtil::get_comments($post_id, true); ?> </span></li> <?php } ?> <?php if ('true' != $instance['is_hide_views']) { ?> <li><?php echo KopaIcon::getIconView(); ?> <span><?php echo KopaUtil::get_views($post_id, false); ?> </span></li> <?php } ?> <?php if ('true' != $instance['is_hide_likes']) { ?> <li class="metadata-last"><?php echo KopaIcon::getIconLike(); ?> <span><?php echo KopaUtil::get_likes($post_id, false); ?> </span></li> <?php } ?> </ul> <?php } ?> </div> <?php } } ?> </div> </div> </div> <?php } wp_reset_postdata(); echo $after_widget; }