post_type == 'question'){ $name = 'question_'.$postid; }elseif($post->post_type == 'answer'){ $name = 'question_'.$post->post_parent; } ap_push_to_browser($name, array( 'action' => 'upvote', 'post_id' => $postid, 'net_vote' => $counts['net_vote'], 'type' => $post->post_type, )); } public function vote_down($postid, $counts) { $post = get_post($postid); if($post->post_type == 'question'){ $name = 'question_'.$postid; }elseif($post->post_type == 'answer'){ $name = 'question_'.$post->post_parent; } ap_push_to_browser($name, array( 'action' => 'downvote', 'post_id' => $postid, 'net_vote' => $counts['net_vote'], 'type' => $post->post_type, )); } public function undo_vote_up($postid, $counts) { $post = get_post($postid); if($post->post_type == 'question'){ $name = 'question_'.$postid; }elseif($post->post_type == 'answer'){ $name = 'question_'.$post->post_parent; } ap_push_to_browser($name, array( 'action' => 'voteup_undo', 'post_id' => $postid, 'net_vote' => $counts['net_vote'], 'type' => $post->post_type, )); } public function undo_vote_down($postid, $counts) { $post = get_post($postid); if($post->post_type == 'question'){ $name = 'question_'.$postid; }elseif($post->post_type == 'answer'){ $name = 'question_'.$post->post_parent; } ap_push_to_browser($name, array( 'action' => 'votedown_undo', 'post_id' => $postid, 'net_vote' => $counts['net_vote'], 'type' => $post->post_type, )); } public function new_comment($comment, $post_type){ $post = get_post($comment->comment_post_ID); if($post->post_type == 'question'){ $name = 'question_'.$post->ID; }elseif($post->post_type == 'answer'){ $name = 'question_'.$post->post_parent; } ob_start(); ap_comment($comment); $html = ob_get_clean(); ap_push_to_browser($name, array( 'action' => 'comment', 'message' => __('New comment loaded', 'ap'), 'comment_id' => $comment->comment_ID, 'post_id' => $comment->comment_post_ID, 'type' => $post->post_type, 'html' => $html, )); } } function ap_push_to_browser($name, $parameters){ require_once('libSSE/libsse.php'); //$parameters['time'] = current_time('timestamp'); $data = new SSEData('file',array('path'=>ANSPRESS_ADDON_DIR.DS.'realtime'.DS.'data')); $exist = $data->get($name); $time = current_time('timestamp'); if(!empty($exist)){ $old_data = new stdClass(); $old_data = json_decode($data->get($name)); $old_data->$time = $parameters; $data->set($name, json_encode($old_data)); }else{ $old_data = new stdClass(); $old_data->$time = $parameters; $data->set($name, json_encode($old_data)); } } AP_Realtime_Addon::get_instance();