Skip to content

Commit

Permalink
potential fix for multi-byte issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkingorg committed Oct 25, 2012
1 parent f50bc8a commit d14edec
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
31 changes: 29 additions & 2 deletions classes/aktt.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ static function profile_link($username) {
} }


static function profile_prefix($username, $prefix = '@') { static function profile_prefix($username, $prefix = '@') {
if (substr($username, 0, 1) != '#') { if (AKTT::substr($username, 0, 1) != '#') {
$username = '@'.$username; $username = '@'.$username;
} }
return $username; return $username;
Expand All @@ -1069,7 +1069,7 @@ static function hashtag_link($hashtag) {
} }


static function hashtag_prefix($hashtag, $prefix = '#') { static function hashtag_prefix($hashtag, $prefix = '#') {
if (substr($hashtag, 0, 1) != '#') { if (AKTT::substr($hashtag, 0, 1) != '#') {
$hashtag = '#'.$hashtag; $hashtag = '#'.$hashtag;
} }
return $hashtag; return $hashtag;
Expand Down Expand Up @@ -1132,6 +1132,33 @@ static function gmt_to_wp_time($gmt_time) {
} }
} }


static function substr_replace($str, $replace, $start, $length) {
if (function_exists('mb_str_replace')) {
return mb_substr_replace($str, $replace, $start, $length);
}
else {
return substr_replace($str, $replace, $start, $length);
}
}

static function strlen($str) {
if (function_exists('mb_strlen')) {
return mb_strlen($str);
}
else {
return strlen($str);
}
}

static function substr($str, $start, $length) {
if (function_exists('mb_substr')) {
return mb_substr($str, $start, $length);
}
else {
return substr($str, $start, $length);
}
}

} }




20 changes: 10 additions & 10 deletions classes/aktt_tweet.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public function id() {
*/ */
public function title() { public function title() {
if (isset($this->data)) { if (isset($this->data)) {
$title = trim(substr($this->data->text, 0, 50)); $title = trim(AKTT::substr($this->data->text, 0, 50));
if (strlen($this->data->text) > 50) { if (AKTT::strlen($this->data->text) > 50) {
$title = $title.'...'; $title = $title.'...';
} }
} }
Expand Down Expand Up @@ -282,7 +282,7 @@ function get_post($post_type = null) {
* @return bool * @return bool
*/ */
function is_reply() { function is_reply() {
return (bool) (substr($this->content(), 0, 1) == '@' || !empty($this->data->in_reply_to_screen_name)); return (bool) (AKTT::substr($this->content(), 0, 1) == '@' || !empty($this->data->in_reply_to_screen_name));
} }




Expand All @@ -292,7 +292,7 @@ function is_reply() {
* @return bool * @return bool
*/ */
function is_retweet() { function is_retweet() {
return (bool) (substr($this->content(), 0, 2) == 'RT' || !empty($this->data->retweeted_status)); return (bool) (AKTT::substr($this->content(), 0, 2) == 'RT' || !empty($this->data->retweeted_status));
} }




Expand Down Expand Up @@ -353,18 +353,18 @@ function link_entities($defer_to_anywhere = true) {
// $log = array(); // $log = array();
// $log[] = 'diff: '.$diff; // $log[] = 'diff: '.$diff;
// $log[] = 'entity start: '.$entity['start']; // $log[] = 'entity start: '.$entity['start'];
// $log[] = 'entity start chars: '.substr($this->content(), $entity['start'], 3); // $log[] = 'entity start chars: '.AKTT::substr($this->content(), $entity['start'], 3);
// $log[] = 'diff start: '.$start; // $log[] = 'diff start: '.$start;
// $log[] = 'diff start chars: '.substr($str, $start, 3); // $log[] = 'diff start chars: '.AKTT::substr($str, $start, 3);
// $log[] = 'entity end: '.$entity['end']; // $log[] = 'entity end: '.$entity['end'];
// $log[] = 'diff end: '.$end; // $log[] = 'diff end: '.$end;
// $log[] = 'find len: '.strlen($entity['find']); // $log[] = 'find len: '.AKTT::strlen($entity['find']);
// $log[] = 'find: '.htmlspecialchars($entity['find']); // $log[] = 'find: '.htmlspecialchars($entity['find']);
// $log[] = 'replace len: '.strlen($entity['replace']); // $log[] = 'replace len: '.AKTT::strlen($entity['replace']);
// $log[] = 'replace: '.htmlspecialchars($entity['replace']); // $log[] = 'replace: '.htmlspecialchars($entity['replace']);
// echo '<p>'.implode('<br>', $log).'</p>'; // echo '<p>'.implode('<br>', $log).'</p>';
$str = substr_replace($str, $entity['replace'], $start, ($end - $start)); $str = AKTT::substr_replace($str, $entity['replace'], $start, ($end - $start));
$diff += strlen($entity['replace']) - ($end - $start); $diff += AKTT::strlen($entity['replace']) - ($end - $start);
} }
return $str; return $str;
} }
Expand Down

0 comments on commit d14edec

Please sign in to comment.