/** * Format string and media url for notification * * @param array $params array ('action', 'post_id', 'initiator_id', 'total_items', 'format' ) * * @return string/array format notification as $params['format'] request */ function format_like_notifications($params) { $action = $params['action']; $post_id = intval($params['post_id']); if ($this->component_action . $post_id === $action) { $initiator_id = $params['initiator_id']; $total_items = $params['total_items']; $format = $params['format']; $rtmedia_id = rtmedia_id($post_id); $liked_list = $this->fetch_media_like_stats($rtmedia_id); $liked_by = bp_core_get_username($liked_list[0]->user_id); $like_count = get_rtmedia_like($post_id); $link = esc_url(get_rtmedia_permalink($rtmedia_id)); $media_type = rtmedia_type($rtmedia_id); $text = null; if (0 === intval($like_count)) { $this->delete_notification_by_item_id($initiator_id, $post_id); } elseif (1 === intval($like_count)) { $text = $liked_by . ' ' . __('liked your', 'buddypress-media') . ' ' . $media_type; } elseif (2 === intval($like_count)) { $text = $liked_by . ' ' . __('and one more friend liked your', 'buddypress-media') . ' ' . $media_type; } else { $count = $like_count - 1; $text = $liked_by . ' ' . __('and', 'buddypress-media') . ' ' . $count . ' ' . __('other friends liked your', 'buddypress-media') . ' ' . $media_type; } $return = apply_filters('rtmedia_before_like_notification', array('link' => $link, 'text' => $text), (int) $total_items); if ('string' === $format) { return '<a href="' . esc_url($return['link']) . '">' . esc_html($return['text']) . '</a>'; } else { return $return; } } }
/** * Format string and media url for notification * * @param array $params array ('action', 'post_id', 'initiator_id', 'total_items', 'format' ) * @return string/array format notification as $params['format'] request */ function format_like_notifications($params) { $action = $params['action']; $post_id = $params['post_id']; if ($this->component_action . $post_id == $action) { $initiator_id = $params['initiator_id']; $total_items = $params['total_items']; $format = $params['format']; $liked_list = $this->fetch_media_like_stats(rtmedia_id($post_id)); $liked_by = bp_core_get_username($liked_list[0]->user_id); $like_count = get_rtmedia_like($post_id); $link = get_rtmedia_permalink(rtmedia_id($post_id)); $media_type = rtmedia_type(rtmedia_id($post_id)); if ($like_count == 0) { $this->delete_notification_by_item_id($initiator_id, $post_id); } elseif ($like_count == 1) { $text = $liked_by . ' ' . __('liked your', 'rtmedia') . ' ' . $media_type; } elseif ($like_count == 2) { $text = $liked_by . ' ' . __('and one more friend liked your', 'rtmedia') . ' ' . $media_type; } else { $count = $like_count - 1; $text = $liked_by . ' ' . __('and', 'rtmedia') . ' ' . $count . ' ' . __('other friends liked your', 'rtmedia') . ' ' . $media_type; } if ($format == 'string') { $return = apply_filters('rtmedia_before_like_notification', '<a href="' . $link . '">' . $text . '</a>', (int) $total_items); } else { $return = apply_filters('rtmedia_before_like_notification', array('link' => $link, 'text' => $text), (int) $total_items); } return $return; } }
function show_rtmedia_like_counts() { global $rtmedia; $options = $rtmedia->options; $count = get_rtmedia_like(); if (!(isset($options['general_enableLikes']) && $options['general_enableLikes'] == 0)) { ?> <div class='rtmedia-like-info<?php if ($count == 0) { echo " hide"; } ?> '><i class="rtmicon-thumbs-up rtmicon-fw"></i> <span class="rtmedia-like-counter-wrap"><span class="rtmedia-like-counter"><?php echo $count; ?> </span> <?php _e('people like this', 'rtmedia'); ?> </span> </div> <?php } }
/** * Like/Unlike by media_id or activity_id * @global int $this->ec_server_error * @global type $this->msg_server_error * @global int $this->ec_invalid_media_id * @global type $this->msg_invalid_media_id */ function rtmedia_api_process_like_media_request() { $this->rtmediajsonapifunction->rtmedia_api_verfiy_token(); $this->rtmediajsonapifunction->rtmedia_api_media_activity_id_missing(); //Like errors $ec_already_liked = 900001; $msg_already_liked = __('unliked media', 'rtmedia'); $ec_liked_media = 900002; $msg_liked_media = __('liked media', 'rtmedia'); extract($_POST); if (class_exists('RTMediaInteractionModel')) { $rtmediainteraction = new RTMediaInteractionModel(); if (class_exists('RTMediaLike')) { $rtmedialike = new RTMediaLike(); } $action = 'like'; // Like or Unlike if (!rtmedia_media_id($media_id)) { echo $this->rtmedia_api_response_object('FALSE', $this->ec_invalid_media_id, $this->msg_invalid_media_id); exit; } $like_count_old = get_rtmedia_like(rtmedia_media_id($media_id)); $check_action = $rtmediainteraction->check($this->user_id, $media_id, $action); if ($check_action) { $results = $rtmediainteraction->get_row($this->user_id, $media_id, $action); $row = $results[0]; $curr_value = $row->value; if ($curr_value == "1") { $value = "0"; $increase = false; } else { $value = "1"; $increase = true; } $update_data = array('value' => $value); $where_columns = array('user_id' => $this->user_id, 'media_id' => $media_id, 'action' => $action); $update = $rtmediainteraction->update($update_data, $where_columns); } else { $value = "1"; $columns = array('user_id' => $this->user_id, 'media_id' => $media_id, 'action' => $action, 'value' => $value); $insert_id = $rtmediainteraction->insert($columns); $increase = true; } if ($increase) { $like_count_old++; } elseif (!$increase) { $like_count_old--; } if ($like_count_old < 0) { $like_count_old = 0; } $data = array('like_count' => $like_count_old); if (!empty($insert_id)) { $rtmedialike->model->update(array('likes' => $like_count_old), array('id' => $media_id)); echo $this->rtmedia_api_response_object('TRUE', $ec_liked_media, $msg_liked_media, $data); exit; } elseif (!empty($update)) { $rtmedialike->model->update(array('likes' => $like_count_old), array('id' => $media_id)); if ($value == 1) { echo $this->rtmedia_api_response_object('TRUE', $ec_liked_media, $msg_liked_media, $data); exit; } elseif ($value == 0) { echo $this->rtmedia_api_response_object('TRUE', $ec_already_liked, $msg_already_liked, $data); exit; } } else { echo $this->rtmedia_api_response_object('FALSE', $this->ec_server_error, $this->msg_server_error); exit; } } }
/** * 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 } }
/** * Like/Unlike by media_id or activity_id * @global int $this ->ec_server_error * @global type $this ->msg_server_error * @global int $this ->ec_invalid_media_id * @global type $this ->msg_invalid_media_id */ function rtmedia_api_process_like_media_request() { $this->rtmediajsonapifunction->rtmedia_api_verfiy_token(); $this->rtmediajsonapifunction->rtmedia_api_media_activity_id_missing(); //Like errors $ec_already_liked = 900001; $msg_already_liked = esc_html__('unliked media', 'buddypress-media'); $ec_liked_media = 900002; $msg_liked_media = esc_html__('liked media', 'buddypress-media'); $media_id = filter_input(INPUT_POST, 'media_id', FILTER_SANITIZE_NUMBER_INT); if (class_exists('RTMediaInteractionModel')) { $rtmediainteraction = new RTMediaInteractionModel(); if (class_exists('RTMediaLike')) { $rtmedialike = new RTMediaLike(); } $action = 'like'; // Like or Unlike if (!rtmedia_media_id($media_id)) { wp_send_json($this->rtmedia_api_response_object('FALSE', $this->ec_invalid_media_id, $this->msg_invalid_media_id)); } $like_count_old = get_rtmedia_like(rtmedia_media_id($media_id)); $check_action = $rtmediainteraction->check($this->user_id, $media_id, $action); if ($check_action) { $results = $rtmediainteraction->get_row($this->user_id, $media_id, $action); $row = $results[0]; $curr_value = $row->value; if (1 === intval($curr_value)) { $value = '0'; $increase = false; } else { $value = '1'; $increase = true; } $update_data = array('value' => $value); $where_columns = array('user_id' => $this->user_id, 'media_id' => $media_id, 'action' => $action); $update = $rtmediainteraction->update($update_data, $where_columns); } else { $value = '1'; $columns = array('user_id' => $this->user_id, 'media_id' => $media_id, 'action' => $action, 'value' => $value); $insert_id = $rtmediainteraction->insert($columns); $increase = true; } if ($increase) { $like_count_old++; } elseif (!$increase) { $like_count_old--; } if ($like_count_old < 0) { $like_count_old = 0; } $data = array('like_count' => $like_count_old); if (!empty($insert_id) && isset($rtmedialike)) { $rtmedialike->model->update(array('likes' => $like_count_old), array('id' => $media_id)); wp_send_json($this->rtmedia_api_response_object('TRUE', $ec_liked_media, $msg_liked_media, $data)); } elseif (!empty($update) && isset($rtmedialike)) { $rtmedialike->model->update(array('likes' => $like_count_old), array('id' => $media_id)); if (1 === intval($value)) { wp_send_json($this->rtmedia_api_response_object('TRUE', $ec_liked_media, $msg_liked_media, $data)); } elseif (0 === intval($value)) { wp_send_json($this->rtmedia_api_response_object('TRUE', $ec_already_liked, $msg_already_liked, $data)); } } else { wp_send_json($this->rtmedia_api_response_object('FALSE', $this->ec_server_error, $this->msg_server_error)); } } }