WordPress.org

Ready to get started?Download WordPress

Forums

Tweetily - Tweet Your Posts Automatically!
Multibyte support (2 posts)

  1. karasunouta
    Member
    Posted 4 months ago #

    Dear author,

    I want this plugin to support multibyte languages like Japanese, Chinese, and so on.
    I think it's easy. A little bit of change on top-core.php after L.402.
    Set $lenFunc/$subFunc and use them as strlen/substr function like this:

    //Shrink a tweet and accompanying URL down to 140 chars.
    function set_tweet_length($message, $url, $twitter_hashtags="", $hashtag_length=0) {
    
    	$lenFunc = function_exists('mb_strlen') ? 'mb_strlen' : 'strlen';
    	$subFunc = function_exists('mb_substr') ? 'mb_substr' : 'substr';
        $tags = $twitter_hashtags;
        $message_length = $lenFunc($message);
        $url_length = $lenFunc($url);
        //$cur_length = $lenFunc($tags);
        if ($hashtag_length == 0)
            $hashtag_length = $lenFunc($tags);
    
        if ($twitter_hashtags != "") {
            if ($lenFunc($tags) > $hashtag_length) {
                $tags = $subFunc($tags, 0, $hashtag_length);
                $tags = $subFunc($tags, 0, strrpos($tags, ' '));
            }
            $hashtag_length = $lenFunc($tags);
        }
    
        if ($message_length + $url_length + $hashtag_length > 140) {
    
            $shorten_message_to = 140 - $url_length - $hashtag_length;
            $shorten_message_to = $shorten_message_to - 4;
    //$message = $message." ";
            if ($lenFunc($message) > $shorten_message_to) {
                $message = $subFunc($message, 0, $shorten_message_to);
                $message = $subFunc($message, 0, strrpos($message, ' '));
            }
            $message = $message . "...";
        }
        return $message . " " . $url . " " . $tags;
    }

    This is important for mutlibyte language users like me, as this problem can't be fixed with wp filters.
    Thank you for your consideration (and patience with my bad English).

    https://wordpress.org/plugins/tweetily-tweet-wordpress-posts-automatically/

  2. karasunouta
    Member
    Posted 4 months ago #

    Modified a little:
    strrpos -> $posFunc

    //Shrink a tweet and accompanying URL down to 140 chars.
    function set_tweet_length($message, $url, $twitter_hashtags="", $hashtag_length=0) {
    
        $lenFunc = function_exists('mb_strlen') ? 'mb_strlen' : 'strlen';
        $posFunc = function_exists('mb_strrpos') ? 'mb_strrpos' : 'strrpos';
        $subFunc = function_exists('mb_substr') ? 'mb_substr' : 'substr';
        $tags = $twitter_hashtags;
        $message_length = $lenFunc($message);
        $url_length = $lenFunc($url);
        //$cur_length = $lenFunc($tags);
        if ($hashtag_length == 0)
            $hashtag_length = $lenFunc($tags);
    
        if ($twitter_hashtags != "") {
            if ($lenFunc($tags) > $hashtag_length) {
                $tags = $subFunc($tags, 0, $hashtag_length);
                $tags = $subFunc($tags, 0, $posFunc($tags, ' '));
            }
            $hashtag_length = $lenFunc($tags);
        }
    
        if ($message_length + $url_length + $hashtag_length > 140) {
    
            $shorten_message_to = 140 - $url_length - $hashtag_length;
            $shorten_message_to = $shorten_message_to - 4;
    //$message = $message." ";
            if ($lenFunc($message) > $shorten_message_to) {
                $message = $subFunc($message, 0, $shorten_message_to);
                $message = $subFunc($message, 0, $posFunc($message, ' '));
            }
            $message = $message . "...";
        }
        return $message . " " . $url . " " . $tags;
    }

Reply

You must log in to post.

About this Plugin

About this Topic