Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

attempt to address mbstr issues

  • Loading branch information...
commit 7b1184eb04d86f36d8dbd214f8577ddb9cfa746b 1 parent cc3bed8
@alexkingorg alexkingorg authored jondavidjohn committed
View
4 lib/social/controller/broadcast.php
@@ -75,7 +75,7 @@ public function action_options() {
}
else {
$account_content[$key][$account_id[0]] = $account_content[$key][$account_id[0]];
- if (strlen($account_content[$key][$account_id[0]]) > $service->max_broadcast_length()) {
+ if (social_strlen($account_content[$key][$account_id[0]]) > $service->max_broadcast_length()) {
$errors[$key][$account_id[0]] = sprintf(__('Content must not be longer than %s characters.', 'social'), $service->max_broadcast_length());
}
else {
@@ -107,7 +107,7 @@ public function action_options() {
}
else {
$account_content[$key][$page_id] = $account_content[$key][$page_id];
- if (strlen($account_content[$key][$page_id]) > $service->max_broadcast_length()) {
+ if (social_strlen($account_content[$key][$page_id]) > $service->max_broadcast_length()) {
$errors[$key][$page_id] = sprintf(__('Content must not be longer than %s characters.', 'social'), $service->max_broadcast_length());
}
else {
View
16 lib/social/service.php
@@ -388,7 +388,7 @@ public function format_content($post, $format) {
foreach (Social::broadcast_tokens() as $token => $description) {
$_format = str_replace($token, '', $_format);
}
- $available = $available - strlen($_format);
+ $available = $available - social_strlen($_format);
$_format = explode(' ', $format);
foreach (Social::broadcast_tokens() as $token => $description) {
@@ -420,13 +420,13 @@ public function format_content($post, $format) {
break;
}
- if (strlen($content) > $available) {
+ if (social_strlen($content) > $available) {
if (in_array($token, array('{date}', '{author}'))
) {
$content = '';
}
else {
- $content = substr($content, 0, ($available - 3)).'...';
+ $content = social_substr($content, 0, ($available - 3)).'...';
}
}
@@ -436,7 +436,7 @@ public function format_content($post, $format) {
foreach ($_format as $haystack) {
if (strpos($haystack, $token) !== false and $available > 0) {
$haystack = str_replace($token, $content, $haystack);
- $available = $available - strlen($haystack);
+ $available = $available - social_strlen($haystack);
$format = str_replace($token, $content, $format);
break;
}
@@ -472,7 +472,7 @@ public function format_comment_content($comment, $format) {
$used_tokens[$token] = '';
}
}
- $available = $available - strlen($_format);
+ $available = $available - social_strlen($_format);
// Prep token replacement content
foreach ($used_tokens as $token => $content) {
@@ -496,14 +496,14 @@ public function format_comment_content($comment, $format) {
// if {url} is used, pre-allocate its length
if (isset($used_tokens['{url}'])) {
- $available = $available - strlen($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 (strlen($used_tokens['{content}']) > $available) {
- $used_tokens['{content}'] = substr($used_tokens['{content}'], 0, ($available - 3)).'...';
+ if (social_strlen($used_tokens['{content}']) > $available) {
+ $used_tokens['{content}'] = social_substr($used_tokens['{content}'], 0, ($available - 3)).'...';
}
foreach ($used_tokens as $token => $replacement) {
View
4 social-twitter.php
@@ -278,7 +278,7 @@ public static function is_retweet($comment = null, $tweet = null) {
if (isset($comment->social_raw_data) and !empty($comment->social_raw_data->retweeted_status)) {
$is_retweet = true;
}
- if (substr($comment->comment_content, 0, 4) == 'RT @') {
+ if (social_substr($comment->comment_content, 0, 4) == 'RT @') {
$is_retweet = true;
}
}
@@ -286,7 +286,7 @@ public static function is_retweet($comment = null, $tweet = null) {
if (!empty($tweet->retweeted_status)) {
$is_retweet = true;
}
- if (substr($tweet->text, 0, 4) == 'RT @') {
+ if (social_substr($tweet->text, 0, 4) == 'RT @') {
$is_retweet = true;
}
}
View
38 social.php
@@ -2178,6 +2178,44 @@ function addslashes_deep($value) {
}
}
+function social_strlen($str) {
+ if (function_exists('mb_strlen')) {
+ return mb_strlen($str);
+ }
+ else {
+ return strlen($str);
+ }
+}
+
+function social_substr($str, $start = null, $end = null) {
+ if (function_exists('mb_substr')) {
+ switch (func_num_args()) {
+ case 1:
+ return mb_substr($str);
+ break;
+ case 2:
+ return mb_substr($str, $start);
+ break;
+ case 3:
+ return mb_substr($str, $start, $end);
+ break;
+ }
+ }
+ else {
+ switch (func_num_args()) {
+ case 1:
+ return substr($str);
+ break;
+ case 2:
+ return substr($str, $start);
+ break;
+ case 3:
+ return substr($str, $start, $end);
+ break;
+ }
+ }
+}
+
function social_wpdb_escape($str) {
global $wpdb;
return $wpdb->escape($str);
Please sign in to comment.
Something went wrong with that request. Please try again.