function cjtheme_insert_answer() { global $wpdb; $errors = null; parse_str($_POST['postdata'], $postdata); $user_info = cjtheme_user_info($postdata['user_id']); $time = current_time('mysql'); $comment_data = array('comment_post_ID' => $postdata['post_id'], 'comment_author' => $user_info['user_login'], 'comment_author_email' => $user_info['user_email'], 'comment_author_url' => '', 'comment_content' => esc_textarea($postdata['comment']), 'user_id' => $user_info['ID'], 'comment_date' => $time, 'comment_approved' => 1); $comment_id = wp_insert_comment($comment_data); if (strlen($postdata['comment']) >= 140) { gamf_add_points($user_info['ID'], 1, 'comment-140', 'You answered a question with more than 140 characters.'); } $post_info = cjtheme_post_info($postdata['post_id']); $nmessage = '<a href="' . site_url($user_info['user_login']) . '">' . $user_info['display_name'] . '</a> answered your <a href="' . get_permalink($post_info['ID']) . '">question</a>.'; $nmessage .= '<br>' . cjtheme_trim_text($post_info['post_content'], 160, '...'); cjtheme_notification_add($post_info['post_author'], $nmessage); $return['success'] = get_permalink($post_info['ID']) . '#answer-' . $comment_id; echo json_encode($return); die; }
function cjtheme_update_bp_acmeta_thanks() { global $wpdb; $table_bp_acmeta = $wpdb->prefix . 'cjtheme_likes_thanks'; $check_existing = $wpdb->get_row("SELECT * FROM {$table_bp_acmeta} WHERE user_id = '{$_POST['user_id']}' AND comment_id = '{$_POST['comment_id']}'"); if (is_null($check_existing)) { $acmeta_data = array('comment_id' => $_POST['comment_id'], 'user_id' => $_POST['user_id'], 'thanks' => 1); cjtheme_insert($table_bp_acmeta, $acmeta_data); $comment_thanks = cjtheme_activity_comment_thanks($_POST['comment_id']); $comment_thanks = !is_null($comment_thanks) ? ' ' . $comment_thanks : ''; $comment = get_comment($_POST['comment_id']); if ($comment->user_id != $_POST['user_id']) { gamf_add_points(cjtheme_user_info($comment->user_id, 'ID'), '3', 'thank-answer', 'You received a thanks on your answer.'); } echo ' ' . $comment_thanks; } elseif ($check_existing->thanks == 0) { $acmeta_data = array('comment_id' => $_POST['comment_id'], 'user_id' => $_POST['user_id'], 'thanks' => 1); cjtheme_update($table_bp_acmeta, $acmeta_data, 'id', $check_existing->id); $comment_thanks = cjtheme_activity_comment_thanks($_POST['comment_id']); $comment_thanks = !is_null($comment_thanks) ? ' ' . $comment_thanks : ''; $comment = get_comment($_POST['comment_id']); if ($comment->user_id != $_POST['user_id']) { gamf_add_points(cjtheme_user_info($comment->user_id, 'ID'), '3', 'thank-answer', 'You received a thanks on your answer.'); $nmessage = '<a href="' . site_url(cjtheme_user_info($_POST['user_id'], 'user_login')) . '">' . cjtheme_user_info($_POST['user_id'], 'display_name') . '</a> said thanks for your <a href="' . get_permalink($comment->comment_post_ID) . '#answer-' . $comment->comment_ID . '">answer</a>.'; cjtheme_notification_add(cjtheme_user_info($comment->user_id, 'ID'), $nmessage); } echo ' ' . $comment_thanks; } else { $acmeta_data = array('comment_id' => $_POST['comment_id'], 'user_id' => $_POST['user_id'], 'thanks' => 0); cjtheme_update($table_bp_acmeta, $acmeta_data, 'id', $check_existing->id); $comment_thanks = cjtheme_activity_comment_thanks($_POST['comment_id']); $comment_thanks = !is_null($comment_thanks) ? ' ' . $comment_thanks : ''; $comment = get_comment($_POST['comment_id']); if ($comment->user_id != $_POST['user_id']) { gamf_add_points(cjtheme_user_info($comment->user_id, 'ID'), '-3', 'unthank-answer', 'You received a Thanks on your answer.'); $nmessage = '<a href="' . site_url(cjtheme_user_info($_POST['user_id'], 'user_login')) . '">' . cjtheme_user_info($_POST['user_id'], 'display_name') . '</a> unthanked your <a href="' . get_permalink($comment->comment_post_ID) . '#answer-' . $comment->comment_ID . '">answer</a>.'; cjtheme_notification_add(cjtheme_user_info($comment->user_id, 'ID'), $nmessage); } echo '' . $comment_thanks; } die; }