/** * Checks for a retweet via twitter API data and user perception. * * @static * @param stdClass $comment * @return bool */ public static function is_retweet($comment = null, $tweet = null) { $is_retweet = false; if (!is_null($comment)) { if (isset($comment->social_raw_data) and !empty($comment->social_raw_data->retweeted_status)) { $is_retweet = true; } if (social_substr($comment->comment_content, 0, 4) == 'RT @') { $is_retweet = true; } } else { if (!is_null($tweet)) { if (!empty($tweet->retweeted_status)) { $is_retweet = true; } if (social_substr($tweet->text, 0, 4) == 'RT @') { $is_retweet = true; } } } return $is_retweet; }
/** * Formats a comment before it's broadcasted. * * @param WP_Comment $comment * @param array $format * @return string */ public function format_comment_content($comment, $format) { // Filter the format $format = apply_filters('social_comment_broadcast_format', $format, $comment, $this); $_format = $format; $available = $this->max_broadcast_length(); $used_tokens = array(); // Gather used tokens and subtract remaining characters from available length foreach (Social::comment_broadcast_tokens() as $token => $description) { $replaced = 0; $_format = str_replace($token, '', $_format, $replaced); if ($replaced) { $used_tokens[$token] = ''; } } $available = $available - social_strlen($_format); // Prep token replacement content foreach ($used_tokens as $token => $content) { switch ($token) { case '{url}': $url = social_get_shortlink($comment->comment_post_ID); if (empty($url)) { $url = home_url('?p=' . $comment->comment_post_ID); } $url .= '#comment-' . $comment->comment_ID; $url = apply_filters('social_comment_broadcast_permalink', $url, $comment, $this); $used_tokens[$token] = esc_url($url); break; case '{content}': $used_tokens[$token] = strip_tags($comment->comment_content); $used_tokens[$token] = str_replace(' ', '', $used_tokens[$token]); break; } } // if {url} is used, pre-allocate its length if (isset($used_tokens['{url}'])) { $available = $available - social_strlen($used_tokens['{url}']); } $used_tokens['{content}'] = apply_filters('social_format_comment_content', $used_tokens['{content}'], $comment, $format, $this); // Truncate content to size limit if (social_strlen($used_tokens['{content}']) > $available) { $used_tokens['{content}'] = social_substr($used_tokens['{content}'], 0, $available - 3) . '...'; } foreach ($used_tokens as $token => $replacement) { if (strpos($format, $token) !== false) { $format = str_replace($token, $replacement, $format); } } $format = apply_filters('social_comment_broadcast_content_formatted', $format, $comment, $this); return $format; }