function lp_update_shortlink()
 {
     check_ajax_referer('lp_update_shortlink');
     $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : null;
     $update_id = isset($_REQUEST['update_id']) ? intval($_REQUEST['update_id']) : null;
     $cache_key = 'lp_shortlink_aaaa' . LP_PLUGIN_VERSION . '_' . $update_id;
     $shortlink = LivePress_WP_Utils::get_from_post($post_id, $cache_key, true);
     $status_code = 200;
     if (!$shortlink) {
         global $post;
         $post = get_post($post_id);
         $post_parent_url = get_permalink($post);
         if (0 === preg_match('/\\/\\?/', $post_parent_url)) {
             $post_parent_url .= '?';
         } else {
             $post_parent_url .= '&';
         }
         $canonical_url = $post_parent_url . 'lpup=' . $update_id . '#livepress-update-' . $update_id;
         //$bitly_api = '7ea952a9826d091fbda8a4ca220ba634efe61e31'; // TODO: Allow to set up from web page
         $bitly_api = 'a68d0da03159457bff5f6b287d6cdecb88b108dd';
         // datacompboy
         $get_shortlink = 'https://api-ssl.bitly.com/v3/shorten?access_token=' . $bitly_api . '&domain=bit.ly&longUrl=' . urlencode($canonical_url);
         $url = $get_shortlink;
         if (function_exists('vip_safe_wp_remote_get')) {
             $res = vip_safe_wp_remote_get($url, '', 5, 10, 20, array('reject_unsafe_urls' => false));
         } else {
             $res = wp_remote_get($url, array('reject_unsafe_urls' => false));
         }
         $response = json_decode($res['body'], true);
         $status_code = $response['status_code'];
         if (is_wp_error($res) || 200 !== $status_code) {
             $shortlink = $canonical_url;
         } else {
             if (!$res || !isset($response['data']) || !isset($response['data']['url'])) {
                 $shortlink = $canonical_url;
                 $status_code = 500;
             } else {
                 $shortlink = $response['data']['url'];
                 LivePress_WP_Utils::save_on_post($post_id, $cache_key, $shortlink);
                 $options = get_option(LivePress_Administration::$options_name);
                 $livepress_com = new LivePress_Communication($options['api_key']);
                 $livepress_com->send_to_livepress_broadcast($post_id, array('shortlink' => array($update_id => $shortlink)));
             }
         }
     }
     wp_send_json_success(array('shortlink' => $shortlink, 'code' => $status_code));
 }
 /**
  * Get current post feed link.
  *
  * @return array|string
  */
 public function get_current_post_feed_link()
 {
     global $post;
     return LivePress_WP_Utils::get_from_post($post->ID, 'feed_link');
 }
 /**
  * Send to the livepress webservice a new message with the comment updates
  */
 public function send_to_livepress_new_comment($comment_id, $comment_status = '')
 {
     if (is_int($comment_id)) {
         $comment = get_comment($comment_id);
     } else {
         $comment = $comment_id;
         $comment_id = $comment->comment_ID;
     }
     if (!$comment_status) {
         $comment_status = wp_get_comment_status($comment_id);
     }
     $post = get_post($comment->comment_post_ID);
     $params = array('content' => $comment->comment_content, 'comment_id' => $comment_id, 'comment_url' => get_comment_link($comment), 'comment_gmt' => $comment->comment_date_gmt . 'Z', 'post_id' => $comment->comment_post_ID, 'post_title' => $post->post_title, 'post_link' => get_permalink($post->ID), 'author' => $comment->comment_author, 'author_url' => $comment->comment_author_url, 'avatar_url' => get_avatar($comment->comment_author_email, 30));
     if ($comment_status != 'approved') {
         try {
             $params = array_merge($params, array('status' => $comment_status, 'author_email' => $comment->comment_author_email));
             $this->lp_com->send_to_livepress_new_created_comment($params);
         } catch (LivePress_Communication_Exception $e) {
             $e->log('new comment');
         }
     } else {
         $old_uuid = LivePress_WP_Utils::get_from_post($comment->comment_post_ID, 'comment_update', true);
         $new_uuid = $this->lp_com->new_uuid();
         LivePress_WP_Utils::save_on_post($comment->comment_post_ID, 'comment_update', $new_uuid);
         // Used to fake if the user is logged or not
         global $user_ID;
         $global_user_ID = $user_ID;
         $user_ID = null;
         if (current_user_can('edit_post', $post->ID)) {
             wp_set_current_user(null);
         }
         $comment_template_non_logged = $this->get_comment_list_templated($comment);
         $added_comment_template_non_logged = $this->get_comment_templated($comment, $post);
         $updated_counter_only_template = $this->get_comments_counter_templated($comment_id, $post);
         global $wp_query;
         $wp_query->rewind_comments();
         $user_ID = $post->post_author;
         if (!current_user_can('edit_post', $post->ID)) {
             wp_set_current_user($post->post_author);
         }
         $comment_template = $this->get_comment_list_templated($comment);
         $added_comment_template = $this->get_comment_templated($comment, $post);
         $updated_counter_only_template_logged = $this->get_comments_counter_templated($comment_id, $post);
         try {
             $params = array_merge($params, array('post_author' => get_the_author_meta('login', $post->post_author), 'old_template' => $comment_template_non_logged['old'], 'new_template' => $comment_template_non_logged['new'], 'comment_parent' => $comment->comment_parent, 'comment_html' => $added_comment_template_non_logged, '_ajax_nonce' => $this->options['ajax_comment_nonce'], 'previous_uuid' => $old_uuid, 'uuid' => $new_uuid, 'old_template_logged' => $comment_template['old'], 'new_template_logged' => $comment_template['new'], 'comments_counter_only' => $updated_counter_only_template, 'comments_counter_only_logged' => $updated_counter_only_template_logged, 'comment_html_logged' => $added_comment_template));
             $this->lp_com->send_to_livepress_approved_comment($params);
         } catch (LivePress_Communication_Exception $e) {
             $e->log('approved comment');
         }
         $user_ID = $global_user_ID;
         // Restore changed global $user_ID
     }
 }