@Override
    protected CommentList doInBackground(Void... args) {
      if (!hasActivity()) return null;

      Blog blog = WordPress.getCurrentBlog();
      if (blog == null) {
        isError = true;
        return null;
      }

      // the first time this is called, make sure comments deleted on server are removed
      // from the local database
      if (!mHasCheckedDeletedComments && !isLoadingMore) {
        mHasCheckedDeletedComments = true;
        ApiHelper.removeDeletedComments(blog);
      }

      Map<String, Object> hPost = new HashMap<String, Object>();
      if (isLoadingMore) {
        int numExisting = getCommentAdapter().getCount();
        hPost.put("offset", numExisting);
        hPost.put("number", COMMENTS_PER_PAGE);
      } else {
        hPost.put("number", COMMENTS_PER_PAGE);
      }

      Object[] params = {blog.getRemoteBlogId(), blog.getUsername(), blog.getPassword(), hPost};
      try {
        return ApiHelper.refreshComments(getActivity(), blog, params);
      } catch (Exception e) {
        isError = true;
        return null;
      }
    }
 private String getRsdUrl(String baseUrl) throws SSLHandshakeException {
   String rsdUrl;
   rsdUrl = ApiHelper.getRSDMetaTagHrefRegEx(baseUrl);
   if (rsdUrl == null) {
     rsdUrl = ApiHelper.getRSDMetaTagHref(baseUrl);
   }
   return rsdUrl;
 }
  // Attempts to retrieve the xmlrpc url for a self-hosted site, in this order:
  // 1: Try to retrieve it by finding the ?rsd url in the site's header
  // 2: Take whatever URL the user entered to see if that returns a correct response
  // 3: Finally, just guess as to what the xmlrpc url should be
  private String getSelfHostedXmlrpcUrl(String url) {
    String xmlrpcUrl;

    // Convert IDN names to punycode if necessary
    url = UrlUtils.convertUrlToPunycodeIfNeeded(url);

    // Add http to the beginning of the URL if needed
    url = UrlUtils.addUrlSchemeIfNeeded(url, false);

    if (!URLUtil.isValidUrl(url)) {
      mErrorMsgId = org.wordpress.android.R.string.invalid_url_message;
      return null;
    }

    // Attempt to get the XMLRPC URL via RSD
    String rsdUrl;
    try {
      rsdUrl = UrlUtils.addUrlSchemeIfNeeded(getRsdUrl(url), false);
    } catch (SSLHandshakeException e) {
      if (!UrlUtils.getDomainFromUrl(url).endsWith("wordpress.com")) {
        mErroneousSslCertificate = true;
      }
      AppLog.w(T.NUX, "SSLHandshakeException failed. Erroneous SSL certificate detected.");
      return null;
    }

    try {
      if (rsdUrl != null) {
        xmlrpcUrl = UrlUtils.addUrlSchemeIfNeeded(ApiHelper.getXMLRPCUrl(rsdUrl), false);
        if (xmlrpcUrl == null) {
          xmlrpcUrl = UrlUtils.addUrlSchemeIfNeeded(rsdUrl.replace("?rsd", ""), false);
        }
      } else {
        xmlrpcUrl = UrlUtils.addUrlSchemeIfNeeded(getXmlrpcByUserEnteredPath(url), false);
      }
    } catch (SSLHandshakeException e) {
      if (!UrlUtils.getDomainFromUrl(url).endsWith("wordpress.com")) {
        mErroneousSslCertificate = true;
      }
      AppLog.w(T.NUX, "SSLHandshakeException failed. Erroneous SSL certificate detected.");
      return null;
    }

    return xmlrpcUrl;
  }
    @Override
    protected Boolean doInBackground(Post... posts) {
      mErrorUnavailableVideoPress = false;
      mPost = posts[0];

      mPostUploadNotifier = new PostUploadNotifier(mPost);
      String postTitle =
          TextUtils.isEmpty(mPost.getTitle()) ? getString(R.string.untitled) : mPost.getTitle();
      String uploadingPostTitle = String.format(getString(R.string.posting_post), postTitle);
      String uploadingPostMessage =
          String.format(
              getString(R.string.sending_content),
              mPost.isPage()
                  ? getString(R.string.page).toLowerCase()
                  : getString(R.string.post).toLowerCase());
      mPostUploadNotifier.updateNotificationMessage(uploadingPostTitle, uploadingPostMessage);

      mBlog = WordPress.wpDB.instantiateBlogByLocalId(mPost.getLocalTableBlogId());
      if (mBlog == null) {
        mErrorMessage = mContext.getString(R.string.blog_not_found);
        return false;
      }

      // Create the XML-RPC client
      mClient =
          XMLRPCFactory.instantiate(mBlog.getUri(), mBlog.getHttpuser(), mBlog.getHttppassword());

      if (TextUtils.isEmpty(mPost.getPostStatus())) {
        mPost.setPostStatus(PostStatus.toString(PostStatus.PUBLISHED));
      }

      String descriptionContent = processPostMedia(mPost.getDescription());

      String moreContent = "";
      if (!TextUtils.isEmpty(mPost.getMoreText())) {
        moreContent = processPostMedia(mPost.getMoreText());
      }

      mPostUploadNotifier.updateNotificationMessage(uploadingPostTitle, uploadingPostMessage);

      // If media file upload failed, let's stop here and prompt the user
      if (mIsMediaError) {
        return false;
      }

      JSONArray categoriesJsonArray = mPost.getJSONCategories();
      String[] postCategories = null;
      if (categoriesJsonArray != null) {
        if (categoriesJsonArray.length() > 0) {
          mHasCategory = true;
        }

        postCategories = new String[categoriesJsonArray.length()];
        for (int i = 0; i < categoriesJsonArray.length(); i++) {
          try {
            postCategories[i] = TextUtils.htmlEncode(categoriesJsonArray.getString(i));
          } catch (JSONException e) {
            AppLog.e(T.POSTS, e);
          }
        }
      }

      Map<String, Object> contentStruct = new HashMap<String, Object>();

      if (!mPost.isPage() && mPost.isLocalDraft()) {
        // add the tagline
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);

        if (prefs.getBoolean(getString(R.string.pref_key_post_sig_enabled), false)) {
          String tagline = prefs.getString(getString(R.string.pref_key_post_sig), "");
          if (!TextUtils.isEmpty(tagline)) {
            String tag = "\n\n<span class=\"post_sig\">" + tagline + "</span>\n\n";
            if (TextUtils.isEmpty(moreContent)) descriptionContent += tag;
            else moreContent += tag;
          }
        }
      }

      // Post format
      if (!mPost.isPage()) {
        if (!TextUtils.isEmpty(mPost.getPostFormat())) {
          contentStruct.put("wp_post_format", mPost.getPostFormat());
        }
      }

      contentStruct.put("post_type", (mPost.isPage()) ? "page" : "post");
      contentStruct.put("title", mPost.getTitle());
      long pubDate = mPost.getDate_created_gmt();
      if (pubDate != 0) {
        Date date_created_gmt = new Date(pubDate);
        contentStruct.put("date_created_gmt", date_created_gmt);
        Date dateCreated = new Date(pubDate + (date_created_gmt.getTimezoneOffset() * 60000));
        contentStruct.put("dateCreated", dateCreated);
      }

      if (!TextUtils.isEmpty(moreContent)) {
        descriptionContent = descriptionContent.trim() + "<!--more-->" + moreContent;
        mPost.setMoreText("");
      }

      // get rid of the p and br tags that the editor adds.
      if (mPost.isLocalDraft()) {
        descriptionContent =
            descriptionContent.replace("<p>", "").replace("</p>", "\n").replace("<br>", "");
      }

      // gets rid of the weird character android inserts after images
      descriptionContent = descriptionContent.replaceAll("\uFFFC", "");

      contentStruct.put("description", descriptionContent);
      if (!mPost.isPage()) {
        contentStruct.put("mt_keywords", mPost.getKeywords());

        if (postCategories != null && postCategories.length > 0) {
          contentStruct.put("categories", postCategories);
        }
      }

      contentStruct.put("mt_excerpt", mPost.getPostExcerpt());
      contentStruct.put((mPost.isPage()) ? "page_status" : "post_status", mPost.getPostStatus());

      // Geolocation
      if (mPost.supportsLocation()) {
        JSONObject remoteGeoLatitude = mPost.getCustomField("geo_latitude");
        JSONObject remoteGeoLongitude = mPost.getCustomField("geo_longitude");
        JSONObject remoteGeoPublic = mPost.getCustomField("geo_public");

        Map<Object, Object> hLatitude = new HashMap<Object, Object>();
        Map<Object, Object> hLongitude = new HashMap<Object, Object>();
        Map<Object, Object> hPublic = new HashMap<Object, Object>();

        try {
          if (remoteGeoLatitude != null) {
            hLatitude.put("id", remoteGeoLatitude.getInt("id"));
          }

          if (remoteGeoLongitude != null) {
            hLongitude.put("id", remoteGeoLongitude.getInt("id"));
          }

          if (remoteGeoPublic != null) {
            hPublic.put("id", remoteGeoPublic.getInt("id"));
          }

          if (mPost.hasLocation()) {
            PostLocation location = mPost.getLocation();
            if (!hLatitude.containsKey("id")) {
              hLatitude.put("key", "geo_latitude");
            }

            if (!hLongitude.containsKey("id")) {
              hLongitude.put("key", "geo_longitude");
            }

            if (!hPublic.containsKey("id")) {
              hPublic.put("key", "geo_public");
            }

            hLatitude.put("value", location.getLatitude());
            hLongitude.put("value", location.getLongitude());
            hPublic.put("value", 1);
          }
        } catch (JSONException e) {
          AppLog.e(T.EDITOR, e);
        }

        if (!hLatitude.isEmpty() && !hLongitude.isEmpty() && !hPublic.isEmpty()) {
          Object[] geo = {hLatitude, hLongitude, hPublic};
          contentStruct.put("custom_fields", geo);
        }
      }

      // featured image
      if (featuredImageID != -1) {
        contentStruct.put("wp_post_thumbnail", featuredImageID);
      }

      if (!TextUtils.isEmpty(mPost.getQuickPostType())) {
        mClient.addQuickPostHeader(mPost.getQuickPostType());
      }

      contentStruct.put("wp_password", mPost.getPassword());

      Object[] params;
      if (mPost.isLocalDraft())
        params =
            new Object[] {
              mBlog.getRemoteBlogId(),
              mBlog.getUsername(),
              mBlog.getPassword(),
              contentStruct,
              false
            };
      else
        params =
            new Object[] {
              mPost.getRemotePostId(),
              mBlog.getUsername(),
              mBlog.getPassword(),
              contentStruct,
              false
            };

      try {
        EventBus.getDefault().post(new PostUploadStarted(mPost.getLocalTableBlogId()));

        if (mPost.isLocalDraft()) {
          Object object = mClient.call("metaWeblog.newPost", params);
          if (object instanceof String) {
            mPost.setRemotePostId((String) object);
          }
        } else {
          mClient.call("metaWeblog.editPost", params);
        }

        // Track any Analytics before modifying the post
        trackUploadAnalytics();

        mPost.setLocalDraft(false);
        mPost.setLocalChange(false);
        WordPress.wpDB.updatePost(mPost);

        // request the new/updated post from the server to ensure local copy matches server
        ApiHelper.updateSinglePost(
            mBlog.getLocalTableBlogId(), mPost.getRemotePostId(), mPost.isPage());

        return true;
      } catch (final XMLRPCException e) {
        setUploadPostErrorMessage(e);
      } catch (IOException e) {
        setUploadPostErrorMessage(e);
      } catch (XmlPullParserException e) {
        setUploadPostErrorMessage(e);
      }

      return false;
    }