コード例 #1
0
    @Override
    protected List<Map<String, Object>> doInBackground(Void... notUsed) {
      String xmlrpcUrl = null;
      if (mSelfHostedUrl != null && mSelfHostedUrl.length() != 0) {
        xmlrpcUrl = getSelfHostedXmlrpcUrl(mSelfHostedUrl);
      }

      if (xmlrpcUrl == null) {
        if (!mHttpAuthRequired && mErrorMsgId == 0) {
          mErrorMsgId = org.wordpress.android.R.string.no_site_error;
        }
        return null;
      }

      // Validate the URL found before calling the client. Prevent a crash that can occur
      // during the setup of self-hosted sites.
      URI xmlrpcUri;
      xmlrpcUri = URI.create(xmlrpcUrl);
      XMLRPCClientInterface client =
          XMLRPCFactory.instantiate(xmlrpcUri, mHttpUsername, mHttpPassword);
      Object[] params = {mUsername, mPassword};
      try {
        Object[] userBlogs = (Object[]) client.call("wp.getUsersBlogs", params);
        if (userBlogs == null) {
          // Could happen if the returned server response is truncated
          mErrorMsgId = org.wordpress.android.R.string.xmlrpc_error;
          mClientResponse = client.getResponse();
          return null;
        }
        Arrays.sort(userBlogs, BlogUtils.BlogNameComparator);
        List<Map<String, Object>> userBlogList = new ArrayList<Map<String, Object>>();
        for (Object blog : userBlogs) {
          try {
            userBlogList.add((Map<String, Object>) blog);
          } catch (ClassCastException e) {
            AppLog.e(T.NUX, "invalid data received from XMLRPC call wp.getUsersBlogs");
          }
        }
        return userBlogList;
      } catch (XmlPullParserException parserException) {
        mErrorMsgId = org.wordpress.android.R.string.xmlrpc_error;
        AppLog.e(T.NUX, "invalid data received from XMLRPC call wp.getUsersBlogs", parserException);
      } catch (XMLRPCFault xmlRpcFault) {
        handleXmlRpcFault(xmlRpcFault);
      } catch (XMLRPCException xmlRpcException) {
        AppLog.e(
            T.NUX, "XMLRPCException received from XMLRPC call wp.getUsersBlogs", xmlRpcException);
        mErrorMsgId = org.wordpress.android.R.string.no_site_error;
      } catch (SSLHandshakeException e) {
        if (xmlrpcUri.getHost() != null && xmlrpcUri.getHost().endsWith("wordpress.com")) {
          mErroneousSslCertificate = true;
        }
        AppLog.w(T.NUX, "SSLHandshakeException failed. Erroneous SSL certificate detected.");
      } catch (IOException e) {
        AppLog.e(T.NUX, "Exception received from XMLRPC call wp.getUsersBlogs", e);
        mErrorMsgId = org.wordpress.android.R.string.no_site_error;
      }
      mClientResponse = client.getResponse();
      return null;
    }
コード例 #2
0
    private Object uploadFileHelper(Object[] params, final File tempFile) {
      // Create listener for tracking upload progress in the notification
      if (mClient instanceof XMLRPCClient) {
        XMLRPCClient xmlrpcClient = (XMLRPCClient) mClient;
        xmlrpcClient.setOnBytesUploadedListener(
            new XMLRPCClient.OnBytesUploadedListener() {
              @Override
              public void onBytesUploaded(long uploadedBytes) {
                if (tempFile.length() == 0) {
                  return;
                }
                float percentage = (uploadedBytes * 100) / tempFile.length();
                mPostUploadNotifier.updateNotificationProgress(percentage);
              }
            });
      }

      try {
        return mClient.call(ApiHelper.Methods.UPLOAD_FILE, params, tempFile);
      } catch (XMLRPCException e) {
        AppLog.e(T.API, e);
        mErrorMessage =
            mContext.getResources().getString(R.string.error_media_upload) + ": " + e.getMessage();
        return null;
      } catch (IOException e) {
        AppLog.e(T.API, e);
        mErrorMessage =
            mContext.getResources().getString(R.string.error_media_upload) + ": " + e.getMessage();
        return null;
      } catch (XmlPullParserException e) {
        AppLog.e(T.API, e);
        mErrorMessage =
            mContext.getResources().getString(R.string.error_media_upload) + ": " + e.getMessage();
        return null;
      } finally {
        // remove the temporary upload file now that we're done with it
        if (tempFile != null && tempFile.exists()) {
          tempFile.delete();
        }
      }
    }
コード例 #3
0
 private Object uploadFileHelper(XMLRPCClientInterface client, Object[] params, File tempFile) {
   try {
     return client.call("wp.uploadFile", params, tempFile);
   } catch (XMLRPCException e) {
     AppLog.e(T.API, e);
     mErrorMessage =
         context.getResources().getString(R.string.error_media_upload) + ": " + e.getMessage();
     return null;
   } catch (IOException e) {
     AppLog.e(T.API, e);
     mErrorMessage =
         context.getResources().getString(R.string.error_media_upload) + ": " + e.getMessage();
     return null;
   } catch (XmlPullParserException e) {
     AppLog.e(T.API, e);
     mErrorMessage =
         context.getResources().getString(R.string.error_media_upload) + ": " + e.getMessage();
     return null;
   } finally {
     // remove the temporary upload file now that we're done with it
     if (tempFile != null && tempFile.exists()) tempFile.delete();
   }
 }
コード例 #4
0
  private String getXmlrpcByUserEnteredPath(String baseUrl) {
    String xmlRpcUrl;
    if (!UrlUtils.isValidUrlAndHostNotNull(baseUrl)) {
      AppLog.e(T.NUX, "invalid URL: " + baseUrl);
      mErrorMsgId = org.wordpress.android.R.string.invalid_url_message;
      return null;
    }
    URI uri = URI.create(baseUrl);
    XMLRPCClientInterface client = XMLRPCFactory.instantiate(uri, mHttpUsername, mHttpPassword);
    try {
      client.call("system.listMethods");
      xmlRpcUrl = baseUrl;
      return xmlRpcUrl;
    } catch (XMLRPCException e) {
      AppLog.i(T.NUX, "system.listMethods failed on: " + baseUrl);
      if (isHTTPAuthErrorMessage(e)) {
        return null;
      }
    } catch (SSLHandshakeException e) {
      if (!UrlUtils.getDomainFromUrl(baseUrl).endsWith("wordpress.com")) {
        mErroneousSslCertificate = true;
      }
      AppLog.w(T.NUX, "SSLHandshakeException failed. Erroneous SSL certificate detected.");
      return null;
    } catch (SSLPeerUnverifiedException e) {
      if (!UrlUtils.getDomainFromUrl(baseUrl).endsWith("wordpress.com")) {
        mErroneousSslCertificate = true;
      }
      AppLog.w(T.NUX, "SSLPeerUnverifiedException failed. Erroneous SSL certificate detected.");
      return null;
    } catch (IOException e) {
      AppLog.i(T.NUX, "system.listMethods failed on: " + baseUrl);
      if (isHTTPAuthErrorMessage(e)) {
        return null;
      }
    } catch (XmlPullParserException e) {
      AppLog.i(T.NUX, "system.listMethods failed on: " + baseUrl);
      if (isHTTPAuthErrorMessage(e)) {
        return null;
      }
    } catch (IllegalArgumentException e) {
      // TODO: Hopefully a temporary log - remove it if we find a pattern of failing URLs
      CrashlyticsUtils.setString(ExtraKey.ENTERED_URL, baseUrl);
      CrashlyticsUtils.logException(e, ExceptionType.SPECIFIC, T.NUX);
      mErrorMsgId = org.wordpress.android.R.string.invalid_url_message;
      return null;
    }

    // Guess the xmlrpc path
    String guessURL = baseUrl;
    if (guessURL.substring(guessURL.length() - 1, guessURL.length()).equals("/")) {
      guessURL = guessURL.substring(0, guessURL.length() - 1);
    }
    guessURL += "/xmlrpc.php";
    uri = URI.create(guessURL);
    client = XMLRPCFactory.instantiate(uri, mHttpUsername, mHttpPassword);
    try {
      client.call("system.listMethods");
      xmlRpcUrl = guessURL;
      return xmlRpcUrl;
    } catch (XMLRPCException e) {
      AnalyticsTracker.track(Stat.LOGIN_FAILED_TO_GUESS_XMLRPC);
      AppLog.e(T.NUX, "system.listMethods failed on: " + guessURL, e);
    } catch (SSLHandshakeException e) {
      if (!UrlUtils.getDomainFromUrl(baseUrl).endsWith("wordpress.com")) {
        mErroneousSslCertificate = true;
      }
      AppLog.w(T.NUX, "SSLHandshakeException failed. Erroneous SSL certificate detected.");
      return null;
    } catch (SSLPeerUnverifiedException e) {
      if (!UrlUtils.getDomainFromUrl(baseUrl).endsWith("wordpress.com")) {
        mErroneousSslCertificate = true;
      }
      AppLog.w(T.NUX, "SSLPeerUnverifiedException failed. Erroneous SSL certificate detected.");
      return null;
    } catch (IOException e) {
      AnalyticsTracker.track(Stat.LOGIN_FAILED_TO_GUESS_XMLRPC);
      AppLog.e(T.NUX, "system.listMethods failed on: " + guessURL, e);
    } catch (XmlPullParserException e) {
      AnalyticsTracker.track(Stat.LOGIN_FAILED_TO_GUESS_XMLRPC);
      AppLog.e(T.NUX, "system.listMethods failed on: " + guessURL, e);
    }

    return null;
  }
コード例 #5
0
    @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;
    }
コード例 #6
0
    @Override
    protected Boolean doInBackground(Post... posts) {
      mErrorUnavailableVideoPress = false;
      post = posts[0];

      // add the uploader to the notification bar
      nm = (NotificationManager) SystemServiceFactory.get(context, Context.NOTIFICATION_SERVICE);

      String postOrPage =
          (String)
              (post.isPage()
                  ? context.getResources().getText(R.string.page_id)
                  : context.getResources().getText(R.string.post_id));
      String message = context.getResources().getText(R.string.uploading) + " " + postOrPage;
      n = new Notification(R.drawable.notification_icon, message, System.currentTimeMillis());

      Intent notificationIntent =
          new Intent(context, post.isPage() ? PagesActivity.class : PostsActivity.class);
      notificationIntent.addFlags(
          Intent.FLAG_ACTIVITY_CLEAR_TOP
              | Intent.FLAG_ACTIVITY_NEW_TASK
              | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
      notificationIntent.setAction(Intent.ACTION_MAIN);
      notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
      notificationIntent.setData(
          (Uri.parse("custom://wordpressNotificationIntent" + post.getLocalTableBlogId())));
      notificationIntent.putExtra(PostsActivity.EXTRA_VIEW_PAGES, post.isPage());
      PendingIntent pendingIntent =
          PendingIntent.getActivity(context, 0, notificationIntent, Intent.FLAG_ACTIVITY_CLEAR_TOP);

      n.setLatestEventInfo(context, message, message, pendingIntent);

      notificationID = (new Random()).nextInt() + post.getLocalTableBlogId();
      nm.notify(notificationID, n); // needs a unique id

      Blog blog = WordPress.wpDB.instantiateBlogByLocalId(post.getLocalTableBlogId());
      if (blog == null) {
        mErrorMessage = context.getString(R.string.blog_not_found);
        return false;
      }

      if (TextUtils.isEmpty(post.getPostStatus())) {
        post.setPostStatus("publish");
      }
      Boolean publishThis = false;

      String descriptionContent = "", moreContent = "";
      int moreCount = 1;
      if (!TextUtils.isEmpty(post.getMoreText())) moreCount++;
      String imgTags = "<img[^>]+android-uri\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>";
      Pattern pattern = Pattern.compile(imgTags);

      for (int x = 0; x < moreCount; x++) {

        if (x == 0) descriptionContent = post.getDescription();
        else moreContent = post.getMoreText();

        Matcher matcher;

        if (x == 0) {
          matcher = pattern.matcher(descriptionContent);
        } else {
          matcher = pattern.matcher(moreContent);
        }

        List<String> imageTags = new ArrayList<String>();
        while (matcher.find()) {
          imageTags.add(matcher.group());
        }

        for (String tag : imageTags) {

          Pattern p = Pattern.compile("android-uri=\"([^\"]+)\"");
          Matcher m = p.matcher(tag);
          if (m.find()) {
            String imgPath = m.group(1);
            if (!imgPath.equals("")) {
              MediaFile mf = WordPress.wpDB.getMediaFile(imgPath, post);

              if (mf != null) {
                String imgHTML = uploadMediaFile(mf, blog);
                if (imgHTML != null) {
                  if (x == 0) {
                    descriptionContent = descriptionContent.replace(tag, imgHTML);
                  } else {
                    moreContent = moreContent.replace(tag, imgHTML);
                  }
                } else {
                  if (x == 0) descriptionContent = descriptionContent.replace(tag, "");
                  else moreContent = moreContent.replace(tag, "");
                  mIsMediaError = true;
                }
              }
            }
          }
        }
      }

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

      JSONArray categoriesJsonArray = post.getJSONCategories();
      String[] postCategories = null;
      if (categoriesJsonArray != null) {
        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 (!post.isPage() && post.isLocalDraft()) {
        // add the tagline
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

        if (prefs.getBoolean("wp_pref_signature_enabled", false)) {
          String tagline = prefs.getString("wp_pref_post_signature", "");
          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 (!post.isPage()) {
        if (!TextUtils.isEmpty(post.getPostFormat())) {
          contentStruct.put("wp_post_format", post.getPostFormat());
        }
      }

      contentStruct.put("post_type", (post.isPage()) ? "page" : "post");
      contentStruct.put("title", post.getTitle());
      long pubDate = post.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 (!moreContent.equals("")) {
        descriptionContent = descriptionContent.trim() + "<!--more-->" + moreContent;
        post.setMoreText("");
      }

      // get rid of the p and br tags that the editor adds.
      if (post.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 (!post.isPage()) {
        contentStruct.put("mt_keywords", post.getKeywords());

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

      contentStruct.put("mt_excerpt", post.getPostExcerpt());

      contentStruct.put((post.isPage()) ? "page_status" : "post_status", post.getPostStatus());
      if (!post.isPage()) {
        if (post.getLatitude() > 0) {
          Map<Object, Object> hLatitude = new HashMap<Object, Object>();
          hLatitude.put("key", "geo_latitude");
          hLatitude.put("value", post.getLatitude());

          Map<Object, Object> hLongitude = new HashMap<Object, Object>();
          hLongitude.put("key", "geo_longitude");
          hLongitude.put("value", post.getLongitude());

          Map<Object, Object> hPublic = new HashMap<Object, Object>();
          hPublic.put("key", "geo_public");
          hPublic.put("value", 1);

          Object[] geo = {hLatitude, hLongitude, hPublic};

          contentStruct.put("custom_fields", geo);
        }
      }

      // featured image
      if (featuredImageID != -1) {
        contentStruct.put("wp_post_thumbnail", featuredImageID);
      }
      XMLRPCClientInterface client =
          XMLRPCFactory.instantiate(blog.getUri(), blog.getHttpuser(), blog.getHttppassword());
      if (!TextUtils.isEmpty(post.getQuickPostType())) {
        client.addQuickPostHeader(post.getQuickPostType());
      }
      n.setLatestEventInfo(context, message, message, n.contentIntent);
      nm.notify(notificationID, n);

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

      Object[] params;
      if (post.isLocalDraft() && !post.isUploaded())
        params =
            new Object[] {
              blog.getRemoteBlogId(),
              blog.getUsername(),
              blog.getPassword(),
              contentStruct,
              publishThis
            };
      else
        params =
            new Object[] {
              post.getRemotePostId(),
              blog.getUsername(),
              blog.getPassword(),
              contentStruct,
              publishThis
            };

      try {
        if (post.isLocalDraft() && !post.isUploaded()) {
          Object newPostId = client.call("metaWeblog.newPost", params);
          if (newPostId instanceof String) {
            post.setRemotePostId((String) newPostId);
          }
        } else {
          client.call("metaWeblog.editPost", params);
        }

        post.setUploaded(true);
        post.setLocalChange(false);
        WordPress.wpDB.updatePost(post);
        return true;
      } catch (final XMLRPCException e) {
        setUploadPostErrorMessage(e);
      } catch (IOException e) {
        setUploadPostErrorMessage(e);
      } catch (XmlPullParserException e) {
        setUploadPostErrorMessage(e);
      }

      return false;
    }