private function internalCallApi($page, $argsOrType = array(), $argsIfType = array(), $postid = null) { try { return $this->m_fb->api($page, $argsOrType, $argsIfType); } catch (FacebookApiException $e) { if ($e->getType() == "OAuthException") { $this->disconnect(); } wso_log_msg(sprintf(__('An error appeared when publishing <a href="%s">this post</a> on Facebook (Reason : %s)', 'wordsocial'), get_bloginfo('wpurl') . "/wp-admin/post.php?post=" . $postid . "&action=edit", $e)); } return 0; }
public function publish($postid, $comment = "") { $post = get_post($postid); $wsoOpts = get_option(WSO_OPTIONS); $shortenLink = $this->getShortenLink($postid); $maxLn = 140; $tweet = stripslashes($wsoOpts[$this->m_options['format']]); $tweetTitleLn = strstr($tweet, '%title') === false ? 0 : strlen("%title"); $tweetLinkLn = strstr($tweet, '%link') === false ? 0 : strlen("%link"); $tweetExcerptLn = strstr($tweet, '%excerpt') === false ? 0 : strlen("%excerpt"); $tweetCommentLn = strstr($tweet, '%comment') === false || empty($comment) ? 0 : strlen("%comment"); $tweetCategoriesLn = strstr($tweet, '%categories') === false ? 0 : strlen("%categories"); $tweetTagsLn = strstr($tweet, '%tags') === false ? 0 : strlen("%tags"); $tweetLn = strlen($tweet) - $tweetLinkLn - $tweetTitleLn - $tweetCategoriesLn - $tweetTagsLn - $tweetExcerptLn - $tweetCommentLn; // no enough space for the link -> Force the format if (strlen($shortenLink) > $maxLn - $tweetLn) { $tweet = "%title %link"; $tweetTitleLn = strlen("%title"); $tweetLinkLn = strlen("%link"); } if ($tweetLinkLn > 0) { $tweet = str_replace("%link", $shortenLink, $tweet); $tweetLn = strlen($tweet) - $tweetTitleLn - $tweetCategoriesLn - $tweetTagsLn - $tweetExcerptLn - $tweetCommentLn; } if ($tweetTitleLn > 0) { $postTitle = $this->qTrans($post->post_title); $postTitle = strlen($postTitle) > $maxLn - $tweetLn ? substr($postTitle, 0, $maxLn - $tweetLn) : $postTitle; $tweet = str_replace("%title", $postTitle, $tweet); $tweetLn = strlen($tweet) - $tweetCategoriesLn - $tweetTagsLn - $tweetExcerptLn - $tweetCommentLn; } if ($tweetCategoriesLn > 0) { $categories = get_the_category($postid); $catHashtags = ''; foreach ($categories as $category) { $catHashtags .= '#' . str_replace(' ', '', ucwords($category->cat_name)); $catHashtags .= ' '; } $catHashtags = trim($catHashtags); while (strlen($catHashtags) > $maxLn - $tweetLn) { $catHashtags = substr($catHashtags, 0, strrpos($catHashtags, " ")); } $tweet = str_replace("%categories", $catHashtags, $tweet); $tweetLn = strlen($tweet) - $tweetTagsLn - $tweetExcerptLn - $tweetCommentLn; } if ($tweetTagsLn > 0) { $tags = get_the_tags($postid); $tagsHashtags = ''; foreach ($tags as $tag) { $tagsHashtags .= '#' . str_replace(' ', '', ucwords($tag->name)); $tagsHashtags .= ' '; } $tagsHashtags = trim($tagsHashtags); while (strlen($tagsHashtags) > $maxLn - $tweetLn) { $tagsHashtags = substr($tagsHashtags, 0, strrpos($tagsHashtags, " ")); } $tweet = str_replace("%tags", $tagsHashtags, $tweet); $tweetLn = strlen($tweet) - $tweetExcerptLn - $tweetCommentLn; } if ($tweetExcerptLn > 0) { $content = $post->post_excerpt; if (empty($content)) { $content = $post->post_content; } $postExcerpt = $this->qTrans($content); $postExcerpt = strlen($postExcerpt) > $maxLn - $tweetLn ? substr($postExcerpt, 0, $maxLn - $tweetLn) : $postExcerpt; $tweet = str_replace("%excerpt", $postExcerpt, $tweet); $tweetLn = strlen($tweet) - $tweetCommentLn; } if ($tweetCommentLn > 0) { $comment = stripslashes($comment); $postComment = strlen($comment) > $maxLn - $tweetLn ? substr($comment, 0, $maxLn - $tweetLn) : $comment; $tweet = str_replace("%comment", $postComment, $tweet); } else { $tweet = str_replace("%comment", '', $tweet); } $response = $this->m_OAuth->post('statuses/update', array('status' => $tweet)); if (isset($response->error)) { wso_log_msg(sprintf(__('Error publishing on Twitter:') . ' <a href="%s">post id %d</a> [' . __('Reason:') . ' ' . $response->error . ']', get_bloginfo('wpurl') . "/wp-admin/post.php?post=" . $postid . "&action=edit", $postid)); } }
public function disconnect() { $wsoOpts = get_option(WSO_OPTIONS); $response = $this->m_linkedIn->revoke(); if ($response['success'] === TRUE) { unset($wsoOpts[$this->m_options['access_token']]); unset($wsoOpts[$this->m_options['access_token_secret']]); unset($wsoOpts[$this->m_options['options']]); update_option(WSO_OPTIONS, $wsoOpts); wp_redirect(get_bloginfo('wpurl') . "/wp-admin/options-general.php?page=wordsocial"); } else { wso_log_msg(__("LinkedIn : Error revoking user's token", 'wordsocial')); } }