Permalink
Browse files

Removed extra filters from format_content(). Updated README.

  • Loading branch information...
1 parent 54a6b3d commit b8ee02c409d90c19744cffd2ef58bc33aba20d0b Andrew Ellis committed Sep 2, 2011
Showing with 119 additions and 0 deletions.
  1. +18 −0 lib/social/interface/service.php
  2. +77 −0 lib/social/service.php
  3. +9 −0 lib/social/service/facebook.php
  4. +9 −0 lib/social/service/twitter.php
  5. +6 −0 readme.txt
@@ -38,6 +38,24 @@ function authorize_url();
*/
function accounts(array $accounts = null);
+ /**
+ * Formats the provided content to the defined tokens.
+ *
+ * @abstract
+ * @param object $post
+ * @param string $format
+ * @return string
+ */
+ function format_content($post, $format);
+
+ /**
+ * The max length a post can be when broadcasted.
+ *
+ * @abstract
+ * @return int
+ */
+ function max_broadcast_length();
+
/**
* Broadcasts the message to the specified account. Returns the broadcasted ID.
*
View
@@ -187,4 +187,81 @@ public function accounts(array $accounts = null) {
return $this;
}
+ /**
+ * Formats the broadcast content.
+ *
+ * @param object $post
+ * @param string $format
+ * @return string
+ */
+ public function format_content($post, $format) {
+ // Filter the format
+ $format = apply_filters('social_broadcast_format', $format, $post, $this->_key);
+
+ $_format = $format;
+ $available = $this->max_broadcast_length();
+ foreach (Social::broadcast_tokens() as $token => $description) {
+ $_format = str_replace($token, '', $_format);
+ }
+ $available = $available - strlen($_format);
+
+ $_format = explode(' ', $format);
+ foreach (Social::broadcast_tokens() as $token => $description) {
+ $content = '';
+ switch ($token) {
+ case '{url}':
+ $url = wp_get_shortlink($post->ID);
+ if (empty($url)) {
+ $url = site_url('?p='.$post->ID);
+ }
+ $url = apply_filters('social_broadcast_permalink', $url, $post, $this->_key);
+ $content = esc_url($url);
+ break;
+ case '{title}':
+ $content = $post->post_title;
+ break;
+ case '{content}':
+ $content = strip_tags($post->post_content);
+ $content = str_replace(array("\n", "\r", PHP_EOL), '', $content);
+ $content = str_replace(' ', ' ', $content);
+ break;
+ case '{author}':
+ $user = get_userdata($post->post_author);
+ $content = $user->display_name;
+ break;
+ case '{date}':
+ $content = get_date_from_gmt($post->post_date_gmt);
+ break;
+ }
+
+ if (strlen($content) > $available) {
+ if (in_array($token, array('{date}', '{author}'))) {
+ $content = '';
+ }
+ else {
+ $content = substr($content, 0, ($available-3)).'...';
+ }
+ }
+
+ // Filter the content
+ $content = apply_filters('social_format_content', $content, $post, $format, $this->_key);
+
+ foreach ($_format as $haystack) {
+ if (strpos($haystack, $token) !== false) {
+ if ($available > 0) {
+ $haystack = str_replace($token, $content, $haystack);
+ $available = $available - strlen($haystack);
+ $format = str_replace($token, $content, $format);
+ break;
+ }
+ }
+ }
+ }
+
+ // Filter the content
+ $format = apply_filters('social_broadcast_content_formatted', $format, $post, $this->_key);
+
+ return $format;
+ }
+
} // End Social_Service
@@ -12,6 +12,15 @@
*/
protected $_key = 'facebook';
+ /**
+ * The max length a post can be when broadcasted.
+ *
+ * @return int
+ */
+ public function max_broadcast_length() {
+ return 400;
+ }
+
/**
* Broadcasts the message to the specified account. Returns the broadcasted ID.
*
@@ -15,6 +15,15 @@
*/
protected $_key = 'twitter';
+ /**
+ * The max length a post can be when broadcasted.
+ *
+ * @return int
+ */
+ public function max_broadcast_length() {
+ return 140;
+ }
+
/**
* Broadcasts the message to the specified account. Returns the broadcasted ID.
*
View
@@ -168,6 +168,12 @@ No, the proxy acts just like any Twitter or Facebook application. We've simply p
== Changelog ==
+= 1.0.2 =
+* Filter: social_broadcast_format now contains a third parameter, $service_key.
+* Filter: social_broadcast_permalink now contains a third parameter, $service_key.
+* Filter: social_format_content now contains a fourth parameter, $service_key.
+* Filter: social_broadcast_content_formatted now contains a third parameter, $service_key.
+
= 1.0.1 =
* Automatic CRON jobs now run correctly.
* Facebook replies to broadcasted posts are now aggregated.

0 comments on commit b8ee02c

Please sign in to comment.