コード例 #1
0
ファイル: rtmedia-functions.php プロジェクト: rtCamp/rtMedia
/**
 * Show media like count
 *
 * @global      RTMedia     $rtmedia
 */
function show_rtmedia_like_counts()
{
    global $rtmedia;
    $options = $rtmedia->options;
    $count = get_rtmedia_like();
    if (!(isset($options['general_enableLikes']) && 0 === intval($options['general_enableLikes']))) {
        $class = '';
        if (!intval($count)) {
            $class = 'hide';
        }
        ?>
		<div class='rtmedia-like-info <?php 
        echo $class;
        ?>
'>
			<i class="rtmicon-thumbs-up rtmicon-fw"></i>
			<span class="rtmedia-like-counter-wrap">
				<?php 
        if (class_exists('RTMediaLike') && function_exists('rtmedia_who_like_html')) {
            $rtmedialike = new RTMediaLike();
            echo rtmedia_who_like_html($count, $rtmedialike->is_liked(rtmedia_id()));
        }
        ?>
			</span>
			<?php 
        ?>
		</div>
		<?php 
    }
}
コード例 #2
0
ファイル: RTMediaLike.php プロジェクト: rtCamp/rtMedia
 function process()
 {
     $actions = $this->model->get(array('id' => $this->action_query->id));
     $like_nonce = filter_input(INPUT_POST, 'like_nonce', FILTER_SANITIZE_STRING);
     if (!wp_verify_nonce($like_nonce, 'rtm_media_like_nonce' . $this->media->id)) {
         die;
     }
     $rtmediainteraction = new RTMediaInteractionModel();
     $user_id = $this->interactor;
     $media_id = $this->action_query->id;
     $action = $this->action;
     $check_action = $rtmediainteraction->check($user_id, $media_id, $action);
     if ($check_action) {
         $results = $rtmediainteraction->get_row($user_id, $media_id, $action);
         $row = $results[0];
         $curr_value = $row->value;
         if (1 === intval($curr_value)) {
             $value = '0';
             $this->increase = false;
         } else {
             $value = '1';
             $this->increase = true;
         }
         $update_data = array('value' => $value);
         $where_columns = array('user_id' => $user_id, 'media_id' => $media_id, 'action' => $action);
         $update = $rtmediainteraction->update($update_data, $where_columns);
     } else {
         $value = '1';
         $columns = array('user_id' => $user_id, 'media_id' => $media_id, 'action' => $action, 'value' => $value);
         $insert_id = $rtmediainteraction->insert($columns);
         $this->increase = true;
     }
     $actionwa = $this->action . 's';
     $return = array();
     $actions = intval($actions[0]->{$actionwa});
     if (true === $this->increase) {
         $actions++;
         $return['next'] = apply_filters('rtmedia_' . $this->action . '_label_text', $this->undo_label);
     } else {
         $actions--;
         $return['next'] = apply_filters('rtmedia_' . $this->action . '_label_text', $this->label);
     }
     $like_html = '<span class="rtmedia-like-counter"></span>';
     if ($actions > 0 && function_exists('rtmedia_who_like_html')) {
         $like_html = rtmedia_who_like_html($actions, $this->increase);
     }
     /* label for "person/people like this" in media popup" */
     if (1 === $actions) {
         $return['person_text'] = apply_filters('rtmedia_' . $this->action . '_person_label_text', $like_html);
     } else {
         $return['person_text'] = apply_filters('rtmedia_' . $this->action . '_person_label_text', $like_html);
     }
     if ($actions < 0) {
         $actions = 0;
     }
     $return['count'] = $actions;
     $this->model->update(array('likes' => $actions), array('id' => $this->action_query->id));
     global $rtmedia_points_media_id;
     $rtmedia_points_media_id = $this->action_query->id;
     do_action('rtmedia_after_like_media', $this);
     $is_json = filter_input(INPUT_POST, 'json', FILTER_SANITIZE_STRING);
     if (!empty($is_json) && 'true' === $is_json) {
         wp_send_json($return);
     } else {
         $url = rtm_get_server_var('HTTP_REFERER', 'FILTER_SANITIZE_URL');
         wp_safe_redirect(esc_url_raw($url));
         die;
     }
     return $actions;
 }