Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building a Twitter Composer Modal with URL Rewriting

I've built my own Twitter app in PHP with the front end using Twitter Bootstrap as the framework.

I want to build a composer window, so that my app can post a tweet (or a reply). It would need to integrate with bit.ly (and potentially other URL shorteners). Rather than reinvent the wheel, is there something I can use that preferably uses jQuery?

Ideally it would...

  1. Have a character counter that counts down from 140 and gives a negative number when you go over 140 chars. Ideally it would refuse to send if there are more than 140 chars.
  2. Rewrite URLS on the fly (Ajax) using bit.ly or other URL shorteners and reduce the character account accordingly once shortened. The importance of using bit.ly would be to use custom URL shorteners
  3. Style screen names and hashtags on the fly.

I've searched GitHub and can't seem to find anything. I've also checked out twitter-text-js from Twitter, but although it helps with some of what I want to do, the documentation is nonsensical and overly complex and it doesn't integrate with bitly.

There are plenty of social media apps that have the functionality I am looking for, but there doesn't seem to be any example code that is open source and uses PHP/jQuery.

Thanks.

like image 952
iagdotme Avatar asked Nov 05 '13 11:11

iagdotme


Video Answer


1 Answers

https://github.com/twitter/twitter-text-js is Twitter's JavaScript library for handling text counters, detection of URLs/usernames/hashtags, etc. You may find it extremely useful.

edit: twttr.txt.isInvalidTweet and twttr.txt.getTweetLength are likely what you want.

A note: URL shortening doesn't change the length of a tweet. All URLs take up a consistent number of characters in a Twitter post, because Twitter passes all URLs through their t.co shortener. In fact, http://bit.ly doesn't take up 13 characters, it takes up 22 for this reason.

like image 159
ceejayoz Avatar answered Oct 29 '22 04:10

ceejayoz